/* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin */ use crate::{CreditCategory, IdentifierType, PictureSlot}; use std::{fmt::Display, ops::Deref, str::FromStr}; #[derive(PartialEq)] pub struct SortAnyway(pub T); impl Eq for SortAnyway { fn assert_receiver_is_total_eq(&self) {} } #[allow(clippy::non_canonical_partial_ord_impl)] impl PartialOrd for SortAnyway { fn partial_cmp(&self, other: &Self) -> Option { self.0.partial_cmp(&other.0) } } impl Ord for SortAnyway { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.partial_cmp(other).unwrap() } } impl Deref for SortAnyway { type Target = T; fn deref(&self) -> &Self::Target { &self.0 } } impl Display for CreditCategory { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { CreditCategory::Cast => "cast", CreditCategory::Writing => "writing", CreditCategory::Directing => "directing", CreditCategory::Art => "art", CreditCategory::Sound => "sound", CreditCategory::Camera => "camera", CreditCategory::Lighting => "lighting", CreditCategory::Crew => "crew", CreditCategory::Editing => "editing", CreditCategory::Production => "production", CreditCategory::Vfx => "vfx", CreditCategory::CostumeMakeup => "costume_makeup", CreditCategory::CreatedBy => "created_by", CreditCategory::Performance => "performance", CreditCategory::Instrument => "instrument", CreditCategory::Vocal => "vocal", CreditCategory::Arranger => "arranger", CreditCategory::Producer => "producer", CreditCategory::Engineer => "engineer", }) } } impl FromStr for CreditCategory { type Err = (); fn from_str(s: &str) -> Result { Ok(match s { "cast" => CreditCategory::Cast, "writing" => CreditCategory::Writing, "directing" => CreditCategory::Directing, "art" => CreditCategory::Art, "sound" => CreditCategory::Sound, "camera" => CreditCategory::Camera, "lighting" => CreditCategory::Lighting, "crew" => CreditCategory::Crew, "editing" => CreditCategory::Editing, "production" => CreditCategory::Production, "vfx" => CreditCategory::Vfx, "costume_makeup" => CreditCategory::CostumeMakeup, "created_by" => CreditCategory::CreatedBy, "performance" => CreditCategory::Performance, "instrument" => CreditCategory::Instrument, "vocal" => CreditCategory::Vocal, "arranger" => CreditCategory::Arranger, "producer" => CreditCategory::Producer, "engineer" => CreditCategory::Engineer, _ => return Err(()), }) } } impl Display for IdentifierType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { IdentifierType::MusicbrainzRecording => "musicbrainz_recording", IdentifierType::MusicbrainzArtist => "musicbrainz_artist", IdentifierType::MusicbrainzRelease => "musicbrainz_release", IdentifierType::MusicbrainzReleaseGroup => "musicbrainz_release_group", IdentifierType::Isrc => "isrc", IdentifierType::TraktEpisode => "trakt_episode", IdentifierType::TraktMovie => "trakt_movie", IdentifierType::TraktSeason => "trakt_season", IdentifierType::TraktShow => "trakt_show", IdentifierType::Imdb => "imdb", IdentifierType::TmdbMovie => "tmdb_movie", IdentifierType::TmdbSeries => "tmdb_tv", IdentifierType::Tvdb => "tvdb", IdentifierType::Omdb => "omdb", IdentifierType::YoutubeVideo => "youtube_video", IdentifierType::YoutubeChannel => "youtube_channel", IdentifierType::YoutubeChannelHandle => "youtube_channel_handle", IdentifierType::Barcode => "barcode", IdentifierType::AcoustIdTrack => "acoustid_track", IdentifierType::Bandcamp => "bandcamp", IdentifierType::VgmdbArtist => "vgmdb_artist", }) } } impl FromStr for IdentifierType { type Err = (); fn from_str(s: &str) -> Result { Ok(match s { "musicbrainz_recording" => IdentifierType::MusicbrainzRecording, "musicbrainz_artist" => IdentifierType::MusicbrainzArtist, "musicbrainz_release" => IdentifierType::MusicbrainzRelease, "musicbrainz_release_group" => IdentifierType::MusicbrainzReleaseGroup, "isrc" => IdentifierType::Isrc, "trakt_episode" => IdentifierType::TraktEpisode, "trakt_movie" => IdentifierType::TraktMovie, "trakt_season" => IdentifierType::TraktSeason, "trakt_show" => IdentifierType::TraktShow, "imdb" => IdentifierType::Imdb, "tmdb_movie" => IdentifierType::TmdbMovie, "tmdb_tv" => IdentifierType::TmdbSeries, "tvdb" => IdentifierType::Tvdb, "omdb" => IdentifierType::Omdb, "youtube_video" => IdentifierType::YoutubeVideo, "youtube_channel" => IdentifierType::YoutubeChannel, "youtube_channel_handle" => IdentifierType::YoutubeChannelHandle, "barcode" => IdentifierType::Barcode, "acoustid_track" => IdentifierType::AcoustIdTrack, "vgmdb_artist" => IdentifierType::VgmdbArtist, _ => return Err(()), }) } } impl Display for PictureSlot { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { PictureSlot::Backdrop => "backdrop", PictureSlot::Cover => "cover", }) } } impl FromStr for PictureSlot { type Err = (); fn from_str(s: &str) -> Result { Ok(match s { "backdrop" => PictureSlot::Backdrop, "cover" => PictureSlot::Cover, _ => return Err(()), }) } }