Skip to content

Commit aee3a36

Browse files
authored
Merge pull request #16 from ArabCoders/dev
Code cleanup
2 parents a8f550f + 887ea28 commit aee3a36

19 files changed

Lines changed: 60 additions & 216 deletions

Jellyfin.Plugin.YTINFOReader.Providers.Tests/Jellyfin.Plugin.YTINFOReader.Tests.csproj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<TargetFramework>net6.0</TargetFramework>
54
<Nullable>enable</Nullable>
65
<IsPackable>false</IsPackable>
76
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
87
</PropertyGroup>
9-
8+
<ItemGroup>
9+
<ProjectReference Include="..\Jellyfin.Plugin.YTINFOReader\Jellyfin.Plugin.YTINFOReader.csproj" />
10+
</ItemGroup>
1011
<ItemGroup>
1112
<PackageReference Include="Jellyfin.Controller" Version="10.8.0-beta2" />
1213
<PackageReference Include="Jellyfin.Data" Version="10.8.0" />
@@ -24,9 +25,4 @@
2425
<PrivateAssets>all</PrivateAssets>
2526
</PackageReference>
2627
</ItemGroup>
27-
28-
<ItemGroup>
29-
<ProjectReference Include="..\Jellyfin.Plugin.YTINFOReader\Jellyfin.Plugin.YTINFOReader.csproj" />
30-
</ItemGroup>
31-
3228
</Project>

Jellyfin.Plugin.YTINFOReader.Providers.Tests/UtilsTests.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public class UtilsTest
2121
[InlineData("ChannelName - 20190113 - this is a test title [youtube-dQw4w9WgXcQ].mkv", "dQw4w9WgXcQ")]
2222
public void GetYouTubeChannelOrVideoIds(string fn, string expected)
2323
{
24-
25-
2624
var result = "";
2725
if (Utils.RX_V.IsMatch(fn))
2826
{
@@ -32,7 +30,6 @@ public void GetYouTubeChannelOrVideoIds(string fn, string expected)
3230

3331
Assert.Equal(expected, result);
3432
}
35-
3633
[Theory]
3734
[InlineData("Foo", "")]
3835
[InlineData("ChannelName Videos [UCuAXFkgsw1L7xaCfnd5JJOw].info.json", "UCuAXFkgsw1L7xaCfnd5JJOw")]
@@ -41,16 +38,13 @@ public void GetYouTubeChannelOrVideoIds(string fn, string expected)
4138
public void GetYouTubeChannelIds(string fn, string expected)
4239
{
4340
var result = "";
44-
4541
if (Utils.RX_C.IsMatch(fn))
4642
{
4743
MatchCollection match = Utils.RX_C.Matches(fn);
4844
result = match[0].Groups["id"].ToString();
4945
}
50-
5146
Assert.Equal(expected, result);
5247
}
53-
5448
[Theory]
5549
[InlineData("Foo", "")]
5650
[InlineData("Cool playlist [PLirUFnHsz2_v-j-wQfot7uYSeoRgFv0K0].info.json", "PLirUFnHsz2_v-j-wQfot7uYSeoRgFv0K0")]
@@ -65,10 +59,8 @@ public void GetYouTubePlaylistIds(string fn, string expected)
6559
MatchCollection match = Utils.RX_P.Matches(fn);
6660
result = match[0].Groups["id"].ToString();
6761
}
68-
6962
Assert.Equal(expected, result);
7063
}
71-
7264
[Fact]
7365
public void CreatePersonTest()
7466
{
@@ -79,24 +71,19 @@ public void CreatePersonTest()
7971
Type = PersonType.Director,
8072
ProviderIds = new Dictionary<string, string> { { Constants.PLUGIN_NAME, "UCuAXFkgsw1L7xaCfnd5JJOw" } }
8173
};
82-
8374
Assert.Equal(JsonSerializer.Serialize(expected), JsonSerializer.Serialize(result));
8475
}
85-
8676
[Fact]
8777
public void GetVideoInfoPathTest()
8878
{
8979
var mockAppPath = Mock.Of<IServerApplicationPaths>(a => a.CachePath == Path.Combine("foo", "bar").ToString());
90-
9180
var result = Utils.GetVideoInfoPath(mockAppPath, "id123");
9281
Assert.Equal(Path.Combine("foo", "bar", Constants.PLUGIN_NAME, "id123", "ytvideo.info.json").ToString(), result);
9382
}
94-
9583
[Fact]
9684
public void YTDLJsonToMovieTest()
9785
{
9886
var result = Utils.YTDLJsonToMovie(GetYouTubeVideoData());
99-
10087
Assert.True(result.HasMetadata);
10188
Assert.Equal("Never Gonna Give You Up", result.Item.Name);
10289
Assert.Equal("The official video for “Never Gonna Give You Up” by Rick Astley", result.Item.Overview);
@@ -125,7 +112,6 @@ public void YTDLJsonToMusicTest()
125112
public void YTDLJsonToEpisodeTest()
126113
{
127114
var result = Utils.YTDLJsonToEpisode(GetYouTubeVideoData());
128-
129115
Assert.True(result.HasMetadata);
130116
Assert.Equal("Never Gonna Give You Up", result.Item.Name);
131117
Assert.Equal("The official video for “Never Gonna Give You Up” by Rick Astley", result.Item.Overview);

Jellyfin.Plugin.YTINFOReader/Configuration/PluginConfiguration.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

Jellyfin.Plugin.YTINFOReader/Configuration/configPage.html

Lines changed: 0 additions & 20 deletions
This file was deleted.

Jellyfin.Plugin.YTINFOReader/ExternalId.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ namespace Jellyfin.Plugin.YTINFOReader
1111
public class VideoExternalId : IExternalId
1212
{
1313
public bool Supports(IHasProviderIds item) => item is Movie || item is Episode || item is MusicVideo;
14-
1514
public string ProviderName => Constants.PLUGIN_NAME;
16-
1715
public string Key => Constants.PLUGIN_NAME;
18-
1916
public ExternalIdMediaType? Type => null;
20-
2117
public string UrlFormatString => Constants.VIDEO_URL;
2218
}
2319

@@ -36,11 +32,8 @@ public bool Supports(IHasProviderIds item)
3632
}
3733

3834
public string ProviderName => Constants.PLUGIN_NAME;
39-
4035
public string Key => Constants.PLUGIN_NAME;
41-
4236
public ExternalIdMediaType? Type => ExternalIdMediaType.Series;
43-
4437
public string UrlFormatString => Constants.CHANNEL_URL;
4538
}
4639

@@ -59,11 +52,8 @@ public bool Supports(IHasProviderIds item)
5952
}
6053

6154
public string ProviderName => Constants.PLUGIN_NAME;
62-
6355
public string Key => Constants.PLUGIN_NAME;
64-
6556
public ExternalIdMediaType? Type => ExternalIdMediaType.Series;
66-
6757
public string UrlFormatString => Constants.PLAYLIST_URL;
6858
}
6959

@@ -80,13 +70,9 @@ public bool Supports(IHasProviderIds item)
8070

8171
return item is Season && isPlaylist;
8272
}
83-
8473
public string ProviderName => Constants.PLUGIN_NAME;
85-
8674
public string Key => Constants.PLUGIN_NAME;
87-
8875
public ExternalIdMediaType? Type => ExternalIdMediaType.Season;
89-
9076
public string UrlFormatString => Constants.PLAYLIST_URL;
9177
}
9278

Jellyfin.Plugin.YTINFOReader/Helpers/Constants.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ public class Constants
88
public const string CHANNEL_RX = @"(?<=\[)(?:youtube-)?(?<id>(UC|HC)[a-zA-Z0-9\-_]{22})(?=\])";
99
public const string VIDEO_URL = "https://www.youtube.com/watch?v={0}";
1010
public const string VIDEO_RX = @"(?<=\[)(?:youtube-)?(?<id>[a-zA-Z0-9\-_]{11})(?=\])";
11-
1211
public const string PLAYLIST_RX = @"\[(?:youtube\-)?(?<id>PL[^\[\]]{32}|PL[^\[\]]{16}|(UU|FL|LP|RD)[^\[\]]{22})\]";
13-
1412
public const string PLAYLIST_URL = "https://www.youtube.com/playlist?list={0}";
1513
}
1614
}

Jellyfin.Plugin.YTINFOReader/Helpers/ThumbnailInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace Jellyfin.Plugin.YTINFOReader.Helpers
77
/// </summary>
88
public class ThumbnailInfo
99
{
10-
public string url { get; set; }
11-
public int width { get; set; }
12-
public int height { get; set; }
13-
public string resolution { get; set; }
14-
public string id { get; set; }
10+
public string Url { get; set; }
11+
public int Width { get; set; }
12+
public int Height { get; set; }
13+
public string Resolution { get; set; }
14+
public string Id { get; set; }
1515
}
1616
}

Jellyfin.Plugin.YTINFOReader/Helpers/Utils.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ public class Utils
2626
PropertyNameCaseInsensitive = true,
2727
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString
2828
};
29-
3029
#nullable enable
3130
public static ILogger? Logger { get; set; }
3231
#nullable disable
33-
3432
public static bool IsFresh(FileSystemMetadata fileInfo)
3533
{
3634
if (fileInfo.Exists && DateTime.UtcNow.Subtract(fileInfo.LastWriteTimeUtc).Days <= 10)
@@ -39,7 +37,6 @@ public static bool IsFresh(FileSystemMetadata fileInfo)
3937
}
4038
return false;
4139
}
42-
4340
/// <summary>
4441
/// Returns boolean if the given content is youtube.
4542
/// </summary>
@@ -49,7 +46,6 @@ public static bool IsYouTubeContent(string name)
4946
{
5047
return RX_C.IsMatch(name) || RX_P.IsMatch(name) || RX_V.IsMatch(name);
5148
}
52-
5349
/// <summary>
5450
/// Returns the Youtube ID from the file path. Matches last 11 character field inside square brackets.
5551
/// </summary>
@@ -77,7 +73,6 @@ public static string GetYTID(string name)
7773

7874
return "";
7975
}
80-
8176
/// <summary>
8277
/// Creates a person object of type director for the provided name.
8378
/// </summary>
@@ -93,7 +88,6 @@ public static PersonInfo CreatePerson(string name, string channel_id)
9388
ProviderIds = new Dictionary<string, string> { { Constants.PLUGIN_NAME, channel_id } },
9489
};
9590
}
96-
9791
/// <summary>
9892
/// Returns path to where metadata json file should be.
9993
/// </summary>
@@ -105,7 +99,6 @@ public static string GetVideoInfoPath(IServerApplicationPaths appPaths, string y
10599
var dataPath = Path.Combine(appPaths.CachePath, Constants.PLUGIN_NAME, youtubeID);
106100
return Path.Combine(dataPath, "ytvideo.info.json");
107101
}
108-
109102
/// <summary>
110103
/// Reads JSON data from file.
111104
/// </summary>
@@ -123,7 +116,6 @@ public static YTDLData ReadYTDLInfo(string fpath, FileSystemMetadata path, Cance
123116
data.File_path = path;
124117
return data;
125118
}
126-
127119
/// <summary>
128120
/// Provides a Movie Metadata Result from a json object.
129121
/// </summary>
@@ -155,7 +147,6 @@ public static MetadataResult<Movie> YTDLJsonToMovie(YTDLData json)
155147

156148
return result;
157149
}
158-
159150
/// <summary>
160151
/// Provides a MusicVideo Metadata Result from a json object.
161152
/// </summary>
@@ -187,7 +178,6 @@ public static MetadataResult<MusicVideo> YTDLJsonToMusicVideo(YTDLData json)
187178

188179
return result;
189180
}
190-
191181
/// <summary>
192182
/// Provides a Episode Metadata Result from a json object.
193183
/// </summary>
@@ -279,5 +269,4 @@ public static MetadataResult<Series> YTDLJsonToSeries(YTDLData json)
279269
return result;
280270
}
281271
}
282-
283272
}

Jellyfin.Plugin.YTINFOReader/Jellyfin.Plugin.YTINFOReader.csproj

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@
22
<PropertyGroup>
33
<TargetFramework>net6.0</TargetFramework>
44
<RootNamespace>Jellyfin.Plugin.YTINFOReader</RootNamespace>
5-
<Version>1.1.0.0</Version>
5+
<Version>1.1.0.1</Version>
66
<FileVersion>$(Version)</FileVersion>
77
<AssemblyVersion>$(Version)</AssemblyVersion>
88
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
99
</PropertyGroup>
10-
<ItemGroup>
11-
<None Remove="Configuration\configPage.html" />
12-
</ItemGroup>
13-
<ItemGroup>
14-
<EmbeddedResource Include="Configuration\configPage.html" />
15-
</ItemGroup>
16-
1710
<ItemGroup>
1811
<PackageReference Include="Jellyfin.Controller" Version="10.8.0-beta2" />
1912
<PackageReference Include="Jellyfin.Data" Version="10.8.0" />
Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.IO.Abstractions;
4-
using Jellyfin.Plugin.YTINFOReader.Configuration;
52
using Jellyfin.Plugin.YTINFOReader.Helpers;
63
using MediaBrowser.Common.Configuration;
74
using MediaBrowser.Common.Plugins;
85
using MediaBrowser.Model.Plugins;
96
using MediaBrowser.Model.Serialization;
10-
using Microsoft.Extensions.DependencyInjection;
117

128
namespace Jellyfin.Plugin.YTINFOReader
139
{
14-
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
10+
public class Plugin : BasePlugin<BasePluginConfiguration>
1511
{
1612
public override string Name => Constants.PLUGIN_NAME;
1713
public static Plugin Instance { get; private set; }
@@ -20,27 +16,5 @@ public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
2016
{
2117
Instance = this;
2218
}
23-
24-
public IEnumerable<PluginPageInfo> GetPages()
25-
{
26-
return new[] {
27-
new PluginPageInfo {
28-
Name = this.Name,
29-
EmbeddedResourcePath = string.Format("{0}.Configuration.configPage.html", GetType().Namespace)
30-
}
31-
};
32-
}
33-
}
34-
35-
/// <summary>
36-
/// Register webhook services.
37-
/// </summary>
38-
public class PluginServiceRegistrator : IPluginServiceRegistrator
39-
{
40-
/// <inheritdoc />
41-
public void RegisterServices(IServiceCollection serviceCollection)
42-
{
43-
serviceCollection.AddScoped<System.IO.Abstractions.IFileSystem, FileSystem>();
44-
}
4519
}
4620
}

0 commit comments

Comments
 (0)