pub struct Media {
pub id: i64,
pub library_id: i64,
pub name: String,
pub description: Option<String>,
pub rating: Option<i64>,
pub year: Option<i64>,
pub added: Option<String>,
pub poster_path: Option<String>,
pub backdrop_path: Option<String>,
pub media_type: MediaType,
}
Expand description
Media struct that represents a media object, usually a movie, tv show or a episode of a tv show. This struct is returned by several methods and can be serialized to json.
Fields
id: i64
unique id automatically assigned by postgres.
library_id: i64
id of the library that this media objects belongs to.
name: String
name of this media object. Usually the title of a movie, episode or tv show.
description: Option<String>
description of this media object. Usually overview of a movie etc.
rating: Option<i64>
rating provided by any API that is encoded as a signed integer. Usually TMDB rating.
year: Option<i64>
Year in which this movie/tv show/episode was released/aired.
added: Option<String>
Date when this media object was created and inserted into the database. Used by several routes to return sorted lists of medias, based on when they were scanned and inserted into the db.
poster_path: Option<String>
Path to the media poster.
backdrop_path: Option<String>
Path to the backdrop for this media object.
media_type: MediaType
Media type encoded as a string. Either movie/tv/episode or none.
Implementations
sourceimpl Media
impl Media
sourcepub async fn get_all(
conn: &mut Transaction<'_>,
library_id: i64
) -> Result<Vec<Self>, DatabaseError>
pub async fn get_all(
conn: &mut Transaction<'_>,
library_id: i64
) -> Result<Vec<Self>, DatabaseError>
Method returns all Media objects associated with a Library. Its exactly the same as
Library::get
except it takes in a Library object instead of a id.
Library::get
is a intermediary to this function, as it calls this
function.
Arguments
conn
- mutable reference to a sqlx transaction.library_id
- aLibrary
id.
sourcepub async fn get(
conn: &mut Transaction<'_>,
id: i64
) -> Result<Self, DatabaseError>
pub async fn get(
conn: &mut Transaction<'_>,
id: i64
) -> Result<Self, DatabaseError>
Method returns a media object based on its id
Arguments
conn
- mutable reference to a sqlx transaction.req_id
- id of a media that we’d like to match against.
sourcepub async fn get_by_name_and_lib(
conn: &mut Transaction<'_>,
library_id: i64,
name: &str
) -> Result<Self, DatabaseError>
pub async fn get_by_name_and_lib(
conn: &mut Transaction<'_>,
library_id: i64,
name: &str
) -> Result<Self, DatabaseError>
Method to get a entry in a library based on name and library
Arguments
conn
- mutable reference to a sqlx transaction.library_id
- a library id.name
- string slice reference containing the name we would like to filter by.
pub async fn get_of_mediafile(
conn: &mut Transaction<'_>,
mediafile_id: i64
) -> Result<Self, DatabaseError>
sourcepub async fn get_top_rated(
conn: &mut Transaction<'_>,
limit: i64
) -> Result<Vec<i64>, DatabaseError>
pub async fn get_top_rated(
conn: &mut Transaction<'_>,
limit: i64
) -> Result<Vec<i64>, DatabaseError>
Method returns the top rated medias
sourcepub async fn get_recently_added(
conn: &mut Transaction<'_>,
limit: i64
) -> Result<Vec<i64>, DatabaseError>
pub async fn get_recently_added(
conn: &mut Transaction<'_>,
limit: i64
) -> Result<Vec<i64>, DatabaseError>
Method returns the recently added medias
pub async fn get_random_with(
conn: &mut Transaction<'_>,
limit: i64
) -> Result<Vec<Self>, DatabaseError>
pub async fn get_search(
conn: &mut Transaction<'_>,
query: &str,
limit: i64
) -> Result<Vec<Self>, DatabaseError>
pub async fn get_of_genre(
conn: &mut Transaction<'_>,
genre_id: i64
) -> Result<Vec<Self>, DatabaseError>
pub async fn get_of_year(
conn: &mut Transaction<'_>,
year: i64
) -> Result<Vec<Self>, DatabaseError>
pub async fn get_first_duration(&self, conn: &mut Transaction<'_>) -> i64
pub async fn media_mediatype(
conn: &mut Transaction<'_>,
id: i64
) -> Result<MediaType, DatabaseError>
pub async fn decouple_mediafiles(
conn: &mut Transaction<'_>,
id: i64
) -> Result<Vec<i64>, DatabaseError>
sourcepub async fn delete(
conn: &mut Transaction<'_>,
id: i64
) -> Result<usize, DatabaseError>
pub async fn delete(
conn: &mut Transaction<'_>,
id: i64
) -> Result<usize, DatabaseError>
Method deletes a media object based on its id.
Arguments
conn
- mutable reference to a sqlx transaction.id
- id of a media object we want to delete
sourcepub async fn delete_by_lib_id(
conn: &mut Transaction<'_>,
library_id: i64
) -> Result<usize, DatabaseError>
pub async fn delete_by_lib_id(
conn: &mut Transaction<'_>,
library_id: i64
) -> Result<usize, DatabaseError>
This function exists because for some reason CASCADE DELETE
doesnt work with a sqlite
backend. Thus we must manually delete entries when deleting a library.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Media
impl<'de> Deserialize<'de> for Media
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Media
impl Send for Media
impl Sync for Media
impl Unpin for Media
impl UnwindSafe for Media
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more