From 62ba1032657a0bf3878a5fe77018633adab8767d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 21 Jan 2023 00:49:37 +0100 Subject: NyaaSi: exclude episode number from track name, add extension --- src/plugins/NyaaSi.cpp | 2 +- src/plugins/utils/EpisodeNameParser.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/NyaaSi.cpp b/src/plugins/NyaaSi.cpp index d0bc616..38e3c21 100644 --- a/src/plugins/NyaaSi.cpp +++ b/src/plugins/NyaaSi.cpp @@ -30,7 +30,7 @@ namespace QuickMedia { return TrackResult::ERR; } - const std::string track_name = combine_strings({ episode_parts->group, episode_parts->anime, episode_parts->episode, episode_parts->season, episode_parts->resolution }, ' '); + const std::string track_name = combine_strings({ episode_parts->group, episode_parts->anime, episode_parts->season, episode_parts->resolution, episode_parts->file_ext }, ' '); std::string url = "https://nyaa.si/?page=rss&q=" + url_param_encode(track_name) + "&c=0_0&f=0"; if(!episode_parts->group.empty()) diff --git a/src/plugins/utils/EpisodeNameParser.cpp b/src/plugins/utils/EpisodeNameParser.cpp index a381cca..e314953 100644 --- a/src/plugins/utils/EpisodeNameParser.cpp +++ b/src/plugins/utils/EpisodeNameParser.cpp @@ -90,6 +90,10 @@ namespace QuickMedia { episode_name.remove_prefix(i + 1); return episode; } + + static bool ends_with(std::string_view str, std::string_view substr) { + return str.size() >= substr.size() && str.substr(str.size() - substr.size()) == substr; + } std::optional episode_name_extract_parts(std::string_view episode_name) { EpisodeNameParts name_parts; @@ -122,6 +126,27 @@ namespace QuickMedia { else if(episode_name.find("3840x2160") != std::string_view::npos) name_parts.resolution = "3840x2160"; + if(ends_with(episode_name, ".mkv")) + name_parts.file_ext = ".mkv"; + else if(ends_with(episode_name, ".mp4")) + name_parts.file_ext = ".mp4"; + else if(ends_with(episode_name, ".avi")) + name_parts.file_ext = ".avi"; + else if(ends_with(episode_name, ".webm")) + name_parts.file_ext = ".webm"; + else if(ends_with(episode_name, ".wmv")) + name_parts.file_ext = ".wmv"; + else if(ends_with(episode_name, ".mp3")) + name_parts.file_ext = ".mp3"; + else if(ends_with(episode_name, ".flac")) + name_parts.file_ext = ".flac"; + else if(ends_with(episode_name, ".opus")) + name_parts.file_ext = ".opus"; + else if(ends_with(episode_name, ".wav")) + name_parts.file_ext = ".wav"; + else if(ends_with(episode_name, ".ogg")) + name_parts.file_ext = ".ogg"; + return name_parts; } } \ No newline at end of file -- cgit v1.2.3