Skip to content

Commit

Permalink
Update for jellyfin 10.9 (#104)
Browse files Browse the repository at this point in the history
* Update project and code to work with 10.9

* Format code

* Update dotnet version in workflow

* Sort usings and format code

* Update manifest

* Fix tests
Before AM/PM, there is a narrow no-break space instead of a normal one
GetVideoInfoPathTest still fails on linux (due to hardcoded backslashes)
RemoteProviderCachedResultsTest still fails

* Fix GetVideoInfoPathTest
  • Loading branch information
nalsai authored May 20, 2024
1 parent 6b3abfc commit 9a76b15
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- '**.csproj'

env:
DOTNET_VERSION: '6.0.300' # The .NET SDK version to use
DOTNET_VERSION: '8.0.104' # The .NET SDK version to use

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.8.0-beta2" />
<PackageReference Include="Jellyfin.Data" Version="10.8.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="6.0.0" />
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
<PackageReference Include="Jellyfin.Data" Version="10.*" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="NYoutubeDL" Version="0.11.2" />
Expand Down
23 changes: 7 additions & 16 deletions Jellyfin.Plugin.YoutubeMetadata.Providers.Tests/ProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
using System.Collections.Generic;
using System.Text.Json;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using MediaBrowser.Controller.Entities.Movies;
using System.Net.Http;
using Jellyfin.Data.Enums;

namespace Jellyfin.Plugin.YoutubeMetadata.Tests
{


public class YTDLEpisodeProviderTest
{
private readonly Moq.Mock<MediaBrowser.Model.IO.IFileSystem> _jf_fs;
Expand Down Expand Up @@ -66,7 +64,7 @@ public void RemoteProviderCachedResultsTest()
_fs.AddFile(@"\cache\youtubemetadata\AAAAAAAAAAA\ytvideo.info.json", new MockFileData(JsonSerializer.Serialize(json)));
_epInfo.Path = "/Something [AAAAAAAAAAA].mkv";

//var provider = new YTDLEpisodeProvider(_jf_fs.Object, new Mock<Microsoft.Extensions.Logging.ILogger<YTDLEpisodeProvider>>().Object, _config.Object, _fs);
//var provider = new YTDLEpisodeProvider(_jf_fs.Object, new Mock<IHttpClientFactory>().Object, new Mock<Microsoft.Extensions.Logging.ILogger<YTDLEpisodeProvider>>().Object, _config.Object, _fs);
var metadata = _provider.GetMetadata(_epInfo, _token);
metadata.Wait();
Assert.Equal(json.title, metadata.Result.Item.Name);
Expand Down Expand Up @@ -150,7 +148,7 @@ public void YTDLJsonToMovieTest()
},
People = new List<PersonInfo> {new PersonInfo {
Name = "ankenyr",
Type = PersonType.Director,
Type = PersonKind.Director,
ProviderIds = new Dictionary<string, string> { { "YoutubeMetadata", "abc123" } } }
}
}
Expand Down Expand Up @@ -180,12 +178,13 @@ public void YTDLJsonToMovieTest()
},
People = new List<PersonInfo> {new PersonInfo {
Name = "ankenyr",
Type = PersonType.Director,
Type = PersonKind.Director,
ProviderIds = new Dictionary<string, string> { { "YoutubeMetadata", "abc123" } } }
}
}
}
};

[Theory]
[MemberData(nameof(MusicJsonTests))]
public void YTDLJsonToMusicVideo(YTDLData json, MetadataResult<MusicVideo> expected)
Expand Down Expand Up @@ -219,27 +218,19 @@ public void YTDLJsonToMusicVideo(YTDLData json, MetadataResult<MusicVideo> expec
},
People = new List<PersonInfo> {new PersonInfo {
Name = "ankenyr",
Type = PersonType.Director,
Type = PersonKind.Director,
ProviderIds = new Dictionary<string, string> { { "YoutubeMetadata", "abc123" } } }
}
}
}
};

[Theory]
[MemberData(nameof(MovieJsonTests))]
public void YTDLJsonToMovie(YTDLData json, MetadataResult<Movie> expected)
{
var result = JsonSerializer.Serialize(YTDLEpisodeProvider.YTDLJsonToMovie(json, "id123"));
Assert.Equal(JsonSerializer.Serialize(expected), result);
}


}







}
35 changes: 16 additions & 19 deletions Jellyfin.Plugin.YoutubeMetadata.Providers.Tests/UtilsTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using Xunit;
using Jellyfin.Plugin.YoutubeMetadata;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using Newtonsoft.Json;
using MediaBrowser.Controller;
using Moq;
using System.Collections.Generic;
using System.IO.Abstractions.TestingHelpers;
using System.Threading;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Entities.Movies;
using System;
using System.IO;
using Jellyfin.Data.Enums;
using Jellyfin.Plugin.YoutubeMetadata;

namespace Jellyfin.Plugin.YoutubeMetadata.Tests
{
Expand All @@ -23,38 +22,37 @@ public class UtilsTest
public void GetYTIDTest(string fn, string expected)
{
Assert.Equal(expected, Utils.GetYTID(fn));


}

[Fact]
public void CreatePersonTest()
{
var result = Utils.CreatePerson("3Blue1Brown", "UCYO_jab_esuFRV4b17AJtAw");
var expected = new PersonInfo { Name = "3Blue1Brown", Type = PersonType.Director, ProviderIds = new Dictionary<string, string> { { "YoutubeMetadata", "UCYO_jab_esuFRV4b17AJtAw" } } };

var expected = new PersonInfo { Name = "3Blue1Brown", Type = PersonKind.Director, ProviderIds = new Dictionary<string, string> { { "YoutubeMetadata", "UCYO_jab_esuFRV4b17AJtAw" } } };

Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(result));
}

[Fact]
public void GetVideoInfoPathTest()
{
var mockAppPath = Mock.Of<IServerApplicationPaths>(a =>
a.CachePath == @"\foo\bar");

var mockAppPath = Mock.Of<IServerApplicationPaths>(a => a.CachePath == Path.Combine("foo", "bar").ToString());

var result = Utils.GetVideoInfoPath(mockAppPath, "id123");
Assert.Equal(@"\foo\bar\youtubemetadata\id123\ytvideo.info.json", result);
Assert.Equal(Path.Combine("foo", "bar", "youtubemetadata", "id123", "ytvideo.info.json").ToString(), result);
}

[Fact]
public void YTDLJsonToMovieTest()
{
var data = new YTDLData {
var data = new YTDLData
{
title = "Foo",
description = "Some cool movie!",
upload_date = "20220131",
uploader = "SomeGuyIKnow",
channel_id = "ABCDEFGHIJKLMNOPQRSTUVWX" };
channel_id = "ABCDEFGHIJKLMNOPQRSTUVWX"
};
var result = Utils.YTDLJsonToMovie(data);
var person = new PersonInfo
{
Expand All @@ -78,7 +76,7 @@ public void YTDLJsonToMovieTest()
Assert.Equal("Foo", result.Item.Name);
Assert.Equal("Some cool movie!", result.Item.Overview);
Assert.Equal(2022, result.Item.ProductionYear);
Assert.Equal("1/31/2022 12:00:00 AM", result.Item.PremiereDate.ToString());
Assert.Equal("1/31/2022 12:00:00AM", result.Item.PremiereDate.ToString());
Assert.Equal("SomeGuyIKnow", result.People[0].Name);
Assert.Equal("ABCDEFGHIJKLMNOPQRSTUVWX", result.People[0].ProviderIds["YoutubeMetadata"]);
}
Expand All @@ -105,7 +103,7 @@ public void YTDLJsonToMusicTest()
Assert.Equal("Foo", result.Item.Name);
Assert.Equal("Some cool movie!", result.Item.Overview);
Assert.Equal(2022, result.Item.ProductionYear);
Assert.Equal("1/31/2022 12:00:00 AM", result.Item.PremiereDate.ToString());
Assert.Equal("1/31/2022 12:00:00AM", result.Item.PremiereDate.ToString());
Assert.Equal("SomeGuyIKnow", result.People[0].Name);
Assert.Equal("ABCDEFGHIJKLMNOPQRSTUVWX", result.People[0].ProviderIds["YoutubeMetadata"]);
}
Expand Down Expand Up @@ -133,7 +131,7 @@ public void YTDLJsonToMusicWithTrackTest()
Assert.Equal("Bar", result.Item.Name);
Assert.Equal("Some cool movie!", result.Item.Overview);
Assert.Equal(2022, result.Item.ProductionYear);
Assert.Equal("1/31/2022 12:00:00 AM", result.Item.PremiereDate.ToString());
Assert.Equal("1/31/2022 12:00:00AM", result.Item.PremiereDate.ToString());
Assert.Equal("SomeGuyIKnow", result.People[0].Name);
Assert.Equal("ABCDEFGHIJKLMNOPQRSTUVWX", result.People[0].ProviderIds["YoutubeMetadata"]);
}
Expand All @@ -160,7 +158,7 @@ public void YTDLJsonToEpisodeTest()
Assert.Equal("Foo", result.Item.Name);
Assert.Equal("Some cool movie!", result.Item.Overview);
Assert.Equal(2022, result.Item.ProductionYear);
Assert.Equal("1/31/2022 12:00:00 AM", result.Item.PremiereDate.ToString());
Assert.Equal("1/31/2022 12:00:00AM", result.Item.PremiereDate.ToString());
Assert.Equal("SomeGuyIKnow", result.People[0].Name);
Assert.Equal("ABCDEFGHIJKLMNOPQRSTUVWX", result.People[0].ProviderIds["YoutubeMetadata"]);
Assert.Equal("20220131-Foo", result.Item.ForcedSortName);
Expand All @@ -187,5 +185,4 @@ public void YTDLJsonToSeriesTest()
Assert.Equal("ABCDEFGHIJKLMNOPQRSTUVWX", result.Item.ProviderIds["YoutubeMetadata"]);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Jellyfin.Plugin.YoutubeMetadata</RootNamespace>
<AssemblyVersion>1.0.3.8</AssemblyVersion>
<FileVersion>1.0.3.8</FileVersion>
<Version>1.0.3.9</Version>
<AssemblyVersion>1.0.4.0</AssemblyVersion>
<FileVersion>1.0.4.0</FileVersion>
<Version>1.0.4.0</Version>
</PropertyGroup>
<ItemGroup>
<None Remove="Configuration\configPage.html" />
Expand All @@ -14,11 +14,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.8.0-beta2" />
<PackageReference Include="Jellyfin.Data" Version="10.8.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="NYoutubeDLP" Version="0.12.1" />
<PackageReference Include="System.IO.Abstractions" Version="14.0.13" />
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
<PackageReference Include="Jellyfin.Data" Version="10.9.*" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="NYoutubeDLP" Version="0.12.1" />
<PackageReference Include="System.IO.Abstractions" Version="14.0.13" />
</ItemGroup>
</Project>
</Project>
8 changes: 6 additions & 2 deletions Jellyfin.Plugin.YoutubeMetadata/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.DependencyInjection;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Plugins;

namespace Jellyfin.Plugin.YoutubeMetadata
{
Expand All @@ -19,6 +21,7 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages

public override Guid Id => Guid.Parse(Constants.PluginGuid);
IHttpClientFactory _httpClientFactory;

public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IHttpClientFactory httpClientFactory) : base(applicationPaths, xmlSerializer)
{
Instance = this;
Expand All @@ -34,6 +37,7 @@ public HttpClient GetHttpClient()

return httpClient;
}

public IEnumerable<PluginPageInfo> GetPages()
{
return new[]
Expand All @@ -53,9 +57,9 @@ public IEnumerable<PluginPageInfo> GetPages()
public class PluginServiceRegistrator : IPluginServiceRegistrator
{
/// <inheritdoc />
public void RegisterServices(IServiceCollection serviceCollection)
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
{
serviceCollection.AddScoped<System.IO.Abstractions.IFileSystem, FileSystem>();
}
}
}
}
Loading

0 comments on commit 9a76b15

Please sign in to comment.