Skip to content

Commit

Permalink
Merge pull request #7 from ArabCoders/dev
Browse files Browse the repository at this point in the history
Added support for playlist.
  • Loading branch information
arabcoders authored Sep 11, 2023
2 parents 81b2c86 + 190cb2e commit 6994271
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 12 deletions.
19 changes: 19 additions & 0 deletions Jellyfin.Plugin.YTINFOReader.Providers.Tests/UtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ public void GetYouTubeChannelIds(string fn, string expected)
Assert.Equal(expected, result);
}

[Theory]
[InlineData("Foo", "")]
[InlineData("Cool playlist [PLirUFnHsz2_v-j-wQfot7uYSeoRgFv0K0].info.json", "PLirUFnHsz2_v-j-wQfot7uYSeoRgFv0K0")]
[InlineData("Cool playlist [youtube-PLirUFnHsz2_v-j-wQfot7uYSeoRgFv0K0].info.json", "PLirUFnHsz2_v-j-wQfot7uYSeoRgFv0K0")]
[InlineData("Cool playlist using channel id [UCU_fSrQkYzBBe9jtep0EIIg].info.json", "")]
[InlineData("Cool playlist using channel id [youtube-UCU_fSrQkYzBBe9jtep0EIIg].info.json", "")]
public void GetYouTubePlaylistIds(string fn, string expected)
{
var rxp = new Regex(Constants.PLAYLIST_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
var result = "";
if (rxp.IsMatch(fn))
{
MatchCollection match = rxp.Matches(fn);
result = match[0].Groups["id"].ToString();
}

Assert.Equal(expected, result);
}

[Fact]
public void CreatePersonTest()
{
Expand Down
64 changes: 60 additions & 4 deletions Jellyfin.Plugin.YTINFOReader/ExternalId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace Jellyfin.Plugin.YTINFOReader
{
public class VideoExternalId : IExternalId
{
public bool Supports(IHasProviderIds item)
=> item is Movie || item is Episode || item is MusicVideo;
public bool Supports(IHasProviderIds item) => item is Movie || item is Episode || item is MusicVideo;

public string ProviderName => Constants.PLUGIN_NAME;

Expand All @@ -24,14 +23,71 @@ public bool Supports(IHasProviderIds item)

public class SeriesExternalId : IExternalId
{
public bool Supports(IHasProviderIds item) => item is Series;
public bool Supports(IHasProviderIds item)
{
if (false == item.ProviderIds.TryGetValue(Constants.PLUGIN_NAME, out var id))
{
return false;
}

var isChannel = id.StartsWith("UC") || id.StartsWith("HC");

return item is Series && isChannel;
}

public string ProviderName => Constants.PLUGIN_NAME;

public string Key => Constants.PLUGIN_NAME;

public ExternalIdMediaType? Type => null;
public ExternalIdMediaType? Type => ExternalIdMediaType.Series;

public string UrlFormatString => Constants.CHANNEL_URL;
}

public class PlaylistExternalId : IExternalId
{
public bool Supports(IHasProviderIds item)
{
if (false == item.ProviderIds.TryGetValue(Constants.PLUGIN_NAME, out var id))
{
return false;
}

var isPlaylist = id.StartsWith("PL") || id.StartsWith("UU") || id.StartsWith("FL") || id.StartsWith("LP") || id.StartsWith("RD");

return item is Series && isPlaylist;
}

public string ProviderName => Constants.PLUGIN_NAME;

public string Key => Constants.PLUGIN_NAME;

public ExternalIdMediaType? Type => ExternalIdMediaType.Series;

public string UrlFormatString => Constants.PLAYLIST_URL;
}

public class PlaylistSeasonExternalId : IExternalId
{
public bool Supports(IHasProviderIds item)
{
if (false == item.ProviderIds.TryGetValue(Constants.PLUGIN_NAME, out var id))
{
return false;
}

var isPlaylist = id.StartsWith("PL") || id.StartsWith("UU") || id.StartsWith("FL") || id.StartsWith("LP") || id.StartsWith("RD");

return item is Season && isPlaylist;
}

public string ProviderName => Constants.PLUGIN_NAME;

public string Key => Constants.PLUGIN_NAME;

public ExternalIdMediaType? Type => ExternalIdMediaType.Season;

public string UrlFormatString => Constants.PLAYLIST_URL;
}

}
4 changes: 4 additions & 0 deletions Jellyfin.Plugin.YTINFOReader/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ public class Constants
public const string CHANNEL_RX = @"(?<=\[)(?:youtube-)?(?<id>(UC|HC)[a-zA-Z0-9\-_]{22})(?=\])";
public const string VIDEO_URL = "https://www.youtube.com/watch?v={0}";
public const string VIDEO_RX = @"(?<=\[)(?:youtube-)?(?<id>[a-zA-Z0-9\-_]{11})(?=\])";

public const string PLAYLIST_RX = @"\[(?:youtube\-)?(?<id>PL[^\[\]]{16}|PL[^\[\]]{32}|(UU|FL|LP|RD)[^\[\]]{22})\]";

public const string PLAYLIST_URL = "https://www.youtube.com/playlist?list={0}";
}
}
7 changes: 7 additions & 0 deletions Jellyfin.Plugin.YTINFOReader/Helpers/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public static string GetYTID(string name)
return match[0].Groups["id"].ToString();
}

var rxp = new Regex(Constants.PLAYLIST_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
if (rxp.IsMatch(name))
{
MatchCollection match = rxp.Matches(name);
return match[0].Groups["id"].ToString();
}

var rx = new Regex(Constants.VIDEO_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
if (rx.IsMatch(name))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Jellyfin.Plugin.YTINFOReader</RootNamespace>
<AssemblyVersion>1.0.0.3</AssemblyVersion>
<FileVersion>1.0.0.3</FileVersion>
<Version>1.0.0.3</Version>
<AssemblyVersion>1.0.0.4</AssemblyVersion>
<FileVersion>1.0.0.4</FileVersion>
<Version>1.0.0.4</Version>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ private string GetSeriesInfo(string path)
matcher.AddInclude("**/*.jpg");
matcher.AddInclude("**/*.png");
matcher.AddInclude("**/*.webp");
Regex rx = new Regex(Constants.CHANNEL_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
Regex rxc = new Regex(Constants.CHANNEL_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
Regex rxp = new Regex(Constants.PLAYLIST_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
string infoPath = "";
foreach (string file in matcher.GetResultsInFullPath(path))
{
if (rx.IsMatch(file))
if (rxc.IsMatch(file) || rxp.IsMatch(file))
{
infoPath = file;
break;
Expand Down
5 changes: 3 additions & 2 deletions Jellyfin.Plugin.YTINFOReader/Provider/LocalSeriesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ private string GetSeriesInfo(string path)
_logger.LogDebug("YTLocalSeries GetSeriesInfo: {Path}", path);
Matcher matcher = new();
matcher.AddInclude("**/*.info.json");
Regex rx = new Regex(Constants.CHANNEL_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
Regex rxc = new Regex(Constants.CHANNEL_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
Regex rxp = new Regex(Constants.PLAYLIST_RX, RegexOptions.Compiled | RegexOptions.IgnoreCase);
string infoPath = "";
foreach (string file in matcher.GetResultsInFullPath(path))
{
if (rx.IsMatch(file))
if (rxc.IsMatch(file) || rxp.IsMatch(file))
{
infoPath = file;
break;
Expand Down
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: "yt-dlp Info Reader"
guid: "83b77e24-9fce-4ee0-a794-73fdfa972e64"
version: "1.0.0.3"
version: "1.0.0.4"
targetAbi: "10.7.0.0"
owner: "arabcoders"
overview: "Read yt-dlp and compatiable INFO json metadata files."
Expand Down

0 comments on commit 6994271

Please sign in to comment.