public void When_sampleData_is_extracted_from_file_but_file_does_not_exist_Then_throws_FileNotFoundException() { var fakeFileHelper = new Mock<IFileHelper>(); var fakedFileInfoHelper = new Mock<IFileInfoHelper>(); fakedFileInfoHelper.SetupProperty(x => x.Exists, false); var hashHelper = new OpenSubtitlesHash(fakeFileHelper.Object, fakedFileInfoHelper.Object); Assert.Throws<FileNotFoundException>(() => hashHelper.ExtractSampleData("c:\\dummy.avi")); }
public void When_bytes_of_data_are_hashed_using_opensubtitles_algorithm_Then_returns_expected_hash() { var inputData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; var expectedHash = "18161412100e0c1a"; var fakeFileHelper = new Mock<IFileHelper>(); var fakeFileInfoHelper = new Mock<IFileInfoHelper>(); fakeFileInfoHelper.SetupProperty(x => x.Exists, true); var hashHelper = new OpenSubtitlesHash(fakeFileHelper.Object, fakeFileInfoHelper.Object); var sampleData = new SampleData(inputData.Length, inputData); var hash = hashHelper.ComputeHash(sampleData); StringAssert.AreEqualIgnoringCase(expectedHash, hash); }
public void When_sampleData_is_extracted_from_file_Then_returns_expected_sampleData() { var inputData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var expectedData = new SampleData(inputData.Length, new byte[] { 1, 2, 7, 8 }); var fakeFileHelper = new Mock<IFileHelper>(); fakeFileHelper.Setup(x => x.Open(It.IsAny<string>(), It.IsAny<FileMode>())).Returns(new MemoryStream(inputData)); var fakeFileInfoHelper = new Mock<IFileInfoHelper>(); fakeFileInfoHelper.SetupProperty(x => x.Exists, true); var hashHelper = new OpenSubtitlesHash(fakeFileHelper.Object, fakeFileInfoHelper.Object) { DataChunckLength = 2 }; var result = hashHelper.ExtractSampleData("c:\\dummy.avi"); Assert.AreEqual(expectedData, result); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken) { var result = new List <RemoteSearchResult>(); if (searchInfo == null || string.IsNullOrEmpty(Plugin.Instance.Configuration.MetadataAPIToken)) { return(result); } var curID = searchInfo.Name.GetAttributeValue("theporndbid"); if (string.IsNullOrEmpty(curID)) { searchInfo.ProviderIds.TryGetValue(this.Name, out curID); } if (!string.IsNullOrEmpty(curID)) { var sceneData = new MetadataResult <Movie>() { HasMetadata = false, Item = new Movie(), People = new List <PersonInfo>(), }; var sceneImages = new List <RemoteImageInfo>(); try { sceneData = await MetadataAPI.SceneUpdate(curID, cancellationToken).ConfigureAwait(false); } catch (Exception e) { Logger.Error($"Update error: \"{e}\""); } try { sceneImages = (List <RemoteImageInfo>) await MetadataAPI.SceneImages(curID, cancellationToken).ConfigureAwait(false); } catch (Exception e) { Logger.Error($"GetImages error: \"{e}\""); } if (sceneData.HasMetadata) { result.Add(new RemoteSearchResult { ProviderIds = { { Plugin.Instance.Name, curID } }, Name = sceneData.Item.Name, ImageUrl = sceneImages?.Where(o => o.Type == ImageType.Primary).FirstOrDefault()?.Url, PremiereDate = sceneData.Item.PremiereDate, }); return(result); } } if (string.IsNullOrEmpty(searchInfo.Name)) { return(result); } string searchTitle = searchInfo.Name, oshash = string.Empty; #if __EMBY__ #else if (!string.IsNullOrEmpty(searchInfo.Path) && Plugin.Instance.Configuration.UseFilePath) { searchTitle = searchInfo.Path; } if (!string.IsNullOrEmpty(searchInfo.Path) && Plugin.Instance.Configuration.UseOSHash) { oshash = OpenSubtitlesHash.ComputeHash(searchInfo.Path); } #endif try { result = await MetadataAPI.SceneSearch(searchTitle, oshash, cancellationToken).ConfigureAwait(false); } catch (Exception e) { Logger.Error($"Search error: \"{e}\""); } if (result.Any()) { foreach (var scene in result) { if (scene.PremiereDate.HasValue) { scene.ProductionYear = scene.PremiereDate.Value.Year; } } } return(result); }