pub struct Media {
pub id: i64,
pub library_id: i64,
pub name: String,
pub description: Option<String>,
pub rating: Option<f64>,
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.
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<f64>
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 get_id_by_name(
tx: &mut Transaction<'_>,
name: &str
) -> Result<Option<i64>, DatabaseError>
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.