Skip to content

Commit

Permalink
Partial Update to 10.8
Browse files Browse the repository at this point in the history
  • Loading branch information
danieladov committed Mar 30, 2022
1 parent 4eecae6 commit e778df8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 135 deletions.
17 changes: 5 additions & 12 deletions Jellyfin.Plugin.ThemeSongs/Jellyfin.Plugin.ThemeSongs.csproj
@@ -1,19 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>true</IsPackable>
<AssemblyVersion>10.7.0.2</AssemblyVersion>
<FileVersion>10.7.0.2</FileVersion>
<AssemblyVersion>10.8.0.0</AssemblyVersion>
<FileVersion>10.8.0.0</FileVersion>
<Authors />
<Company />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.6.0" />
<PackageReference Include="Jellyfin.Controller" Version="10.8.0-alpha5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="YoutubeExplode" Version="5.1.9" />
<PackageReference Include="YouTubeSearch" Version="2.2.6" />
</ItemGroup>

<ItemGroup>
Expand All @@ -26,12 +24,7 @@
</ItemGroup>

<ItemGroup>
<Reference Include="YoutubeExplode">
<HintPath>..\..\jellyfin-plugin-template\Jellyfin.Plugin.Template\YoutubeExplode.dll</HintPath>
</Reference>
<Reference Include="YouTubeSearch">
<HintPath>..\..\jellyfin-plugin-template\Jellyfin.Plugin.Template\YouTubeSearch.dll</HintPath>
</Reference>

</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions Jellyfin.Plugin.ThemeSongs/Jellyfin.Plugin.ThemeSongs.csproj.bak
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>true</IsPackable>
<AssemblyVersion>10.7.0.2</AssemblyVersion>
<FileVersion>10.7.0.2</FileVersion>
<Authors />
<Company />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.8.0-alpha5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<None Remove="Configuration\configurationpage.html" />
<EmbeddedResource Include="Configuration\configurationpage.html" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

<ItemGroup>

</ItemGroup>

</Project>
34 changes: 0 additions & 34 deletions Jellyfin.Plugin.ThemeSongs/ScheduledTasks/ThemeSongsTasks.cs
Expand Up @@ -41,38 +41,4 @@ public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
public string Description => "Scans all libraries to download TV Theme Songs";
public string Category => "Theme Songs";
}

public class DownloadMoviesThemeSongsTask : IScheduledTask
{
private readonly ILogger<ThemeSongsManager> _logger;
private readonly ThemeSongsManager _themeSongsManager;

public DownloadMoviesThemeSongsTask(ILibraryManager libraryManager, ILogger<ThemeSongsManager> logger)
{
_logger = logger;
_themeSongsManager = new ThemeSongsManager(libraryManager, logger);
}
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
_logger.LogInformation("Starting plugin, Downloading Theme Songs...");
_themeSongsManager.DownloadAllMoviesThemeSongsAsync();
_logger.LogInformation("All theme songs downloaded");
return Task.CompletedTask;
}

public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
// Run this task every 24 hours
yield return new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerInterval,
IntervalTicks = TimeSpan.FromHours(24).Ticks
};
}

public string Name => "Download Movies Theme Songs (beta)";
public string Key => "DownloadMoviesThemeSongs";
public string Description => "Scans all libraries to download Movies Theme Songs";
public string Category => "Theme Songs";
}
}
93 changes: 4 additions & 89 deletions Jellyfin.Plugin.ThemeSongs/ThemeSongsManager.cs
Expand Up @@ -12,8 +12,7 @@
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging;
using YouTubeSearch;
using YoutubeExplode;
using Jellyfin.Data.Enums;

namespace Jellyfin.Plugin.ThemeSongs

Expand All @@ -37,30 +36,20 @@ private IEnumerable<Series> GetSeriesFromLibrary()
{
return _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] {nameof(Series)},
IncludeItemTypes = new[] {BaseItemKind.Series},
IsVirtualItem = false,
Recursive = true,
HasTvdbId = true
}).Select(m => m as Series);
}

private IEnumerable<Movie> GetMoviesFromLibrary()
{
return _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { nameof(Movie) },
IsVirtualItem = false,
Recursive = true,
HasImdbId = true
}).Select(m => m as Movie);
}

public void DownloadAllThemeSongs()
{
var series = GetSeriesFromLibrary();
foreach (var serie in series)
{
if (serie.ThemeSongIds.Count() == 0)
if (serie.GetThemeSongs().Count() == 0)
{
var tvdb = serie.GetProviderId(MetadataProvider.Tvdb);
var themeSongPath = Path.Join(serie.Path, "theme.mp3");
Expand All @@ -78,84 +67,10 @@ public void DownloadAllThemeSongs()
_logger.LogInformation("{seriesName} theme song not in database, or no internet connection", serie.Name);
}
}
}


}

public async Task DownloadAllMoviesThemeSongsAsync()
{
_logger.LogInformation("1");
VideoSearch videoSearch = new VideoSearch();
var movies = GetMoviesFromLibrary();
_logger.LogInformation(movies.Count().ToString());
foreach (var movie in movies)
{

var title = movie.OriginalTitle + " bso " + movie.ProductionYear;
_logger.LogInformation(title);

var results = await videoSearch.GetVideos(title, 1);


var link = results[0].getUrl();
_logger.LogInformation(link);
try
{

await downloadYoutubeAudioAsync(movie.Path, link);
}
catch (Exception e)
{
_logger.LogInformation(e.Message);
_logger.LogInformation("error");

}
}
}

private async Task downloadYoutubeAudioAsync(String path, String link)
{
var youtube = new YoutubeClient();
var streamManifest = await youtube.Videos.Streams.GetManifestAsync(parseLink(link));
_logger.LogInformation(parseLink(link));
var streamInfo = streamManifest.GetAudioOnly().FirstOrDefault();

if (streamInfo != null)
{

// Download the stream to file
await youtube.Videos.Streams.DownloadAsync(streamInfo, Path.Join(path, "theme.mp3"));
}
}

private String parseLink(String link)
{
var str = link.ToCharArray();
String result = "";
bool symbolReached = false;
foreach (var character in str)
{


if (symbolReached)
{
result += character;
}

if (character == '=')
{
symbolReached = true;
}

}
return result;
}
}





private void OnTimerElapsed()
{
// Stop the timer until next update
Expand Down

0 comments on commit e778df8

Please sign in to comment.