Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
feat: add themes for tv shows (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Jan 12, 2024
1 parent e8dfcff commit 9e10bed
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 202 deletions.
133 changes: 103 additions & 30 deletions Jellyfin.Plugin.Themerr.Tests/FixtureJellyfinServer.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider;
using Movie = MediaBrowser.Controller.Entities.Movies.Movie;

namespace Jellyfin.Plugin.Themerr.Tests;

/// <summary>
/// This class is used as a fixture for the Jellyfin server with mock movies
/// This class is used as a fixture for the Jellyfin server with mock media items (movies and series).
/// </summary>
public class FixtureJellyfinServer
{
/// <summary>
/// Mock movies to use for testing
/// Mock media items to use for testing
/// </summary>
/// <returns>List containing mock <see cref="Movie"/> objects.</returns>
public static List<Movie> MockMovies()
/// <returns>List containing mock <see cref="BaseItem"/> objects.</returns>
public static List<BaseItem> MockItems()
{
return new List<Movie>
return new List<BaseItem>
{
new()
new Movie
{
Name = "Elephants Dream",
ProductionYear = 2006,
Expand All @@ -26,7 +29,7 @@ public static List<Movie> MockMovies()
{ MetadataProvider.Tmdb.ToString(), "9761"},
}
},
new()
new Movie
{
Name = "Sita Sings the Blues",
ProductionYear = 2008,
Expand All @@ -36,7 +39,7 @@ public static List<Movie> MockMovies()
{ MetadataProvider.Tmdb.ToString(), "20529"},
}
},
new()
new Movie
{
Name = "Big Buck Bunny",
ProductionYear = 2008,
Expand All @@ -46,7 +49,7 @@ public static List<Movie> MockMovies()
{ MetadataProvider.Tmdb.ToString(), "10378"},
}
},
new()
new Movie
{
Name = "Sintel",
ProductionYear = 2010,
Expand All @@ -56,18 +59,38 @@ public static List<Movie> MockMovies()
{ MetadataProvider.Tmdb.ToString(), "45745"},
}
},
new Series
{
Name = "Game of Thrones",
ProductionYear = 2011,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt0944947"},
{ MetadataProvider.Tmdb.ToString(), "1399"},
}
},
new Series
{
Name = "The 100",
ProductionYear = 2014,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt2661044"},
{ MetadataProvider.Tmdb.ToString(), "48866"},
}
}
};
}

/// <summary>
/// Mock movies without an associated theme in ThemerrDB to use for testing
/// Mock items without an associated theme in ThemerrDB to use for testing
/// </summary>
/// <returns>List containing mock <see cref="Movie"/> objects.</returns>
public static List<Movie> MockMovies2()
/// <returns>List containing mock <see cref="BaseItem"/> objects.</returns>
public static List<BaseItem> MockItems2()
{
return new List<Movie>
return new List<BaseItem>
{
new()
new Movie
{
Name = "Themerr Test Movie",
ProductionYear = 1970,
Expand All @@ -77,17 +100,46 @@ public static List<Movie> MockMovies2()
{ MetadataProvider.Tmdb.ToString(), "0"},
}
},
new Series
{
Name = "Themerr Test Show",
ProductionYear = 1970,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt0000000"},
{ MetadataProvider.Tmdb.ToString(), "0"},
}
},
};
}

/// <summary>
/// Create mock movies from stub video
/// Mock items which are not supported by Themerr
/// </summary>
/// <returns>List containing mock <see cref="BaseItem"/> objects.</returns>
public static List<BaseItem> UnsupportedMockItems()
{
return new List<BaseItem>
{
new MusicAlbum
{
Name = "Themerr Test Album",
},
new MusicArtist
{
Name = "Themerr Test Artist",
},
};
}

/// <summary>
/// Create mock items from stub video
/// </summary>
[Fact]
[Trait("Category", "Init")]
private void CreateMockMovies()
private void CreateMockItems()
{
var mockMovies = MockMovies();
var mockItems = MockItems();

// get the stub video path based on the directory of this file
var stubVideoPath = Path.Combine(
Expand All @@ -97,29 +149,50 @@ private void CreateMockMovies()

Assert.True(File.Exists(stubVideoPath), "Could not find ./data/video_stub.mp4");

foreach (var movie in mockMovies)
foreach (var item in mockItems)
{
// copy the ./data/video_stub.mp4 to the movie folder "movie.Name (movie.ProductionYear)"
var movieFolder = Path.Combine(
var itemFolder = Path.Combine(
"themerr_jellyfin_tests",
$"{movie.Name} ({movie.ProductionYear})");
$"{item.Name} ({item.ProductionYear})");

// create the movie folder
Directory.CreateDirectory(movieFolder);
Directory.CreateDirectory(itemFolder);

// copy the video_stub.mp4 to the movie folder, renaming it based on movie name
var movieVideoPath = Path.Combine(
movieFolder,
$"{movie.Name} ({movie.ProductionYear}).mp4");
string? itemVideoPath = null;
if (item is Movie)
{
// copy the video_stub.mp4 to the movie folder, renaming it based on movie name
itemVideoPath = Path.Combine(
itemFolder,
$"{item.Name} ({item.ProductionYear}).mp4");
}
else if (item is Series)
{
// season folder
var seasonFolder = Path.Combine(
itemFolder,
"Season 01");
Directory.CreateDirectory(seasonFolder);

// copy the video_stub.mp4 to the season folder, renaming it based on series name
itemVideoPath = Path.Combine(
seasonFolder,
$"{item.Name} ({item.ProductionYear}) - S01E01 - Episode Name.mp4");
}
else
{
Assert.Fail($"Unknown item type: {item.GetType()}");
}

// if file does not exist
if (!File.Exists(movieVideoPath))
if (!File.Exists(itemVideoPath))
{
// copy the stub video to the movie folder
File.Copy(stubVideoPath, movieVideoPath);
// copy the stub video to the item folder
File.Copy(stubVideoPath, itemVideoPath);
}

Assert.True(File.Exists(movieVideoPath), $"Could not find {movieVideoPath}");
Assert.True(File.Exists(itemVideoPath), $"Could not find {itemVideoPath}");
}
}
}
Loading

0 comments on commit 9e10bed

Please sign in to comment.