From e9764820c012e9cfe5c823ea87c1277f54878b4a Mon Sep 17 00:00:00 2001 From: Qstick Date: Tue, 20 Dec 2022 16:24:34 -0600 Subject: [PATCH] Fixed: (SecretCinema) Title not being decoded Fixes #1238 --- .../Indexers/SecretCinema/recentfeed.json | 144 ++++++++++++++++++ .../OrpheusTests/OrpheusFixture.cs | 2 +- .../SecretCinemaTests/SecretCinemaFixture.cs | 68 +++++++++ .../Indexers/Definitions/SecretCinema.cs | 17 +-- 4 files changed, 219 insertions(+), 12 deletions(-) create mode 100644 src/NzbDrone.Core.Test/Files/Indexers/SecretCinema/recentfeed.json create mode 100644 src/NzbDrone.Core.Test/IndexerTests/SecretCinemaTests/SecretCinemaFixture.cs diff --git a/src/NzbDrone.Core.Test/Files/Indexers/SecretCinema/recentfeed.json b/src/NzbDrone.Core.Test/Files/Indexers/SecretCinema/recentfeed.json new file mode 100644 index 000000000..268d37913 --- /dev/null +++ b/src/NzbDrone.Core.Test/Files/Indexers/SecretCinema/recentfeed.json @@ -0,0 +1,144 @@ +{ + "status": "success", + "response": { + "currentPage": 1, + "pages": 1, + "results": [ + { + "groupId": 2497, + "groupName": "Singin' in the Rain", + "artist": "Gene Kelly & Stanley Donen", + "cover": "https:\/\/www.themoviedb.org\/t\/p\/original\/g2AaJDC2vSRcqHSDH29642xmQd.jpg", + "tags": [ "comedy", "musical", "romance" ], + "bookmarked": false, + "vanityHouse": false, + "groupYear": 1952, + "releaseType": null, + "groupTime": "1671129449", + "maxSize": 57473058680, + "totalSnatched": 25, + "totalSeeders": 9, + "totalLeechers": 0, + "torrents": [ + { + "torrentId": 3599, + "editionId": 1, + "artists": [ + { + "id": 126, + "name": "Gene Kelly", + "aliasid": 127 + }, + { + "id": 125, + "name": "Stanley Donen", + "aliasid": 126 + } + ], + "remastered": false, + "remasterYear": 0, + "remasterCatalogueNumber": "", + "remasterTitle": "", + "media": "1080p", + "encoding": "", + "format": "", + "hasLog": false, + "logScore": 0, + "hasCue": false, + "scene": false, + "vanityHouse": false, + "fileCount": 1, + "time": "2017-09-10 11:47:27", + "size": 24724893991, + "snatches": 14, + "seeders": 1, + "leechers": 0, + "isFreeleech": true, + "isNeutralLeech": false, + "isPersonalFreeleech": false, + "canUseToken": false, + "hasSnatched": false + }, + { + "torrentId": 45068, + "editionId": 2, + "artists": [ + { + "id": 126, + "name": "Gene Kelly", + "aliasid": 127 + }, + { + "id": 125, + "name": "Stanley Donen", + "aliasid": 126 + } + ], + "remastered": false, + "remasterYear": 0, + "remasterCatalogueNumber": "", + "remasterTitle": "", + "media": "2160p", + "encoding": "", + "format": "", + "hasLog": false, + "logScore": 0, + "hasCue": false, + "scene": false, + "vanityHouse": false, + "fileCount": 1, + "time": "2022-12-15 19:37:29", + "size": 57473058680, + "snatches": 6, + "seeders": 8, + "leechers": 0, + "isFreeleech": true, + "isNeutralLeech": false, + "isPersonalFreeleech": false, + "canUseToken": false, + "hasSnatched": false + }, + { + "torrentId": 2726, + "editionId": 3, + "artists": [ + { + "id": 126, + "name": "Gene Kelly", + "aliasid": 127 + }, + { + "id": 125, + "name": "Stanley Donen", + "aliasid": 126 + } + ], + "remastered": false, + "remasterYear": 0, + "remasterCatalogueNumber": "", + "remasterTitle": "", + "media": "DVD-R", + "encoding": "", + "format": "", + "hasLog": false, + "logScore": 0, + "hasCue": false, + "scene": false, + "vanityHouse": false, + "fileCount": 37, + "time": "2017-08-26 14:58:58", + "size": 10350032896, + "snatches": 5, + "seeders": 0, + "leechers": 0, + "isFreeleech": true, + "isNeutralLeech": false, + "isPersonalFreeleech": false, + "canUseToken": false, + "hasSnatched": false + } + ] + } + ] + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/IndexerTests/OrpheusTests/OrpheusFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/OrpheusTests/OrpheusFixture.cs index 5c007cec0..03f012795 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/OrpheusTests/OrpheusFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/OrpheusTests/OrpheusFixture.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.IndexerTests.OrpheusTests } [Test] - public async Task should_parse_recent_feed_from_GazelleGames() + public async Task should_parse_recent_feed_from_Orpheus() { var recentFeed = ReadAllText(@"Files/Indexers/Orpheus/recentfeed.json"); diff --git a/src/NzbDrone.Core.Test/IndexerTests/SecretCinemaTests/SecretCinemaFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/SecretCinemaTests/SecretCinemaFixture.cs new file mode 100644 index 000000000..5da0a9864 --- /dev/null +++ b/src/NzbDrone.Core.Test/IndexerTests/SecretCinemaTests/SecretCinemaFixture.cs @@ -0,0 +1,68 @@ +using System; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Common.Http; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.Indexers.Definitions; +using NzbDrone.Core.Indexers.Gazelle; +using NzbDrone.Core.IndexerSearch.Definitions; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.IndexerTests.SecretCinemaTests +{ + [TestFixture] + public class SecretCinemaFixture : CoreTest + { + [SetUp] + public void Setup() + { + Subject.Definition = new IndexerDefinition() + { + Name = "SecretCinema", + Settings = new GazelleSettings() { Username = "somekey", Password = "somekey" } + }; + } + + [Test] + public async Task should_parse_recent_feed_from_SecretCinema() + { + var recentFeed = ReadAllText(@"Files/Indexers/SecretCinema/recentfeed.json"); + + Mocker.GetMock() + .Setup(o => o.ExecuteProxiedAsync(It.Is(v => v.Method == HttpMethod.Get), Subject.Definition)) + .Returns((r, d) => Task.FromResult(new HttpResponse(r, new HttpHeader { { "Content-Type", "application/json" } }, new CookieCollection(), recentFeed))); + + var releases = (await Subject.Fetch(new BasicSearchCriteria { Categories = new int[] { 2000 } })).Releases; + + releases.Should().HaveCount(3); + releases.First().Should().BeOfType(); + + var torrentInfo = releases.First() as GazelleInfo; + + torrentInfo.Title.Should().Be("Singin' in the Rain (1952) 2160p"); + torrentInfo.DownloadProtocol.Should().Be(DownloadProtocol.Torrent); + torrentInfo.DownloadUrl.Should().Be("https://secret-cinema.pw/torrents.php?action=download&useToken=0&id=45068"); + torrentInfo.InfoUrl.Should().Be("https://secret-cinema.pw/torrents.php?id=2497&torrentid=45068"); + torrentInfo.CommentUrl.Should().BeNullOrEmpty(); + torrentInfo.Indexer.Should().Be(Subject.Definition.Name); + torrentInfo.PublishDate.Should().Be(DateTime.Parse("2022-12-15 19:37:29")); + torrentInfo.Size.Should().Be(57473058680); + torrentInfo.InfoHash.Should().Be(null); + torrentInfo.MagnetUrl.Should().Be(null); + torrentInfo.Peers.Should().Be(8); + torrentInfo.Seeders.Should().Be(8); + torrentInfo.ImdbId.Should().Be(0); + torrentInfo.TmdbId.Should().Be(0); + torrentInfo.TvdbId.Should().Be(0); + torrentInfo.Languages.Should().HaveCount(0); + torrentInfo.Subs.Should().HaveCount(0); + torrentInfo.DownloadVolumeFactor.Should().Be(0); + torrentInfo.UploadVolumeFactor.Should().Be(1); + } + } +} diff --git a/src/NzbDrone.Core/Indexers/Definitions/SecretCinema.cs b/src/NzbDrone.Core/Indexers/Definitions/SecretCinema.cs index 75381c628..b39826d02 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/SecretCinema.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/SecretCinema.cs @@ -2,24 +2,16 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net; -using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; -using FluentValidation; -using FluentValidation.Results; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; -using NzbDrone.Common.Serializer; -using NzbDrone.Core.Annotations; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Indexers.Gazelle; -using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { @@ -113,7 +105,6 @@ namespace NzbDrone.Core.Indexers.Definitions // in SC movies, artist=director and GroupName=title var artist = WebUtility.HtmlDecode(result.Artist); - var album = WebUtility.HtmlDecode(result.GroupName); var title = WebUtility.HtmlDecode(result.GroupName); var release = new GazelleInfo() @@ -131,6 +122,8 @@ namespace NzbDrone.Core.Indexers.Definitions Peers = int.Parse(torrent.Leechers) + int.Parse(torrent.Seeders), PublishDate = torrent.Time.ToUniversalTime(), Scene = torrent.Scene, + DownloadVolumeFactor = torrent.IsFreeLeech || torrent.IsNeutralLeech || torrent.IsPersonalFreeLeech ? 0 : 1, + UploadVolumeFactor = torrent.IsNeutralLeech ? 0 : 1 }; var category = torrent.Category; @@ -147,7 +140,7 @@ namespace NzbDrone.Core.Indexers.Definitions { // Remove director from title // SC API returns no more useful information than this - release.Title = $"{result.GroupName} ({result.GroupYear}) {torrent.Media}"; + release.Title = $"{title} ({result.GroupYear}) {torrent.Media}"; // Replace media formats with standards release.Title = Regex.Replace(release.Title, "BDMV", "COMPLETE BLURAY", RegexOptions.IgnoreCase); @@ -156,7 +149,7 @@ namespace NzbDrone.Core.Indexers.Definitions else { // SC API currently doesn't return anything but title. - release.Title = $"{result.Artist} - {result.GroupName} ({result.GroupYear}) [{torrent.Format} {torrent.Encoding}] [{torrent.Media}]"; + release.Title = $"{artist} - {title} ({result.GroupYear}) [{torrent.Format} {torrent.Encoding}] [{torrent.Media}]"; } if (torrent.HasCue) @@ -184,6 +177,8 @@ namespace NzbDrone.Core.Indexers.Definitions Files = result.FileCount, Grabs = result.Snatches, PublishDate = DateTimeOffset.FromUnixTimeSeconds(ParseUtil.CoerceLong(result.GroupTime)).UtcDateTime, + DownloadVolumeFactor = result.IsFreeLeech || result.IsNeutralLeech || result.IsPersonalFreeLeech ? 0 : 1, + UploadVolumeFactor = result.IsNeutralLeech ? 0 : 1 }; var category = result.Category;