Skip to content

Commit

Permalink
Remove a lot of unused Plex code
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Nov 12, 2023
1 parent 74201ae commit cd6af10
Show file tree
Hide file tree
Showing 30 changed files with 33 additions and 2,352 deletions.
2 changes: 1 addition & 1 deletion Shoko.Commons
Submodule Shoko.Commons updated 1 files
+1 −1 Shoko.Models
5 changes: 2 additions & 3 deletions Shoko.Server/API/v2/Models/common/Episode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Shoko.Models.Enums;
using Shoko.Server.Extensions;
using Shoko.Server.Models;
using Shoko.Server.PlexAndKodi;
using Shoko.Server.Repositories;

namespace Shoko.Server.API.v2.Models.common;
Expand Down Expand Up @@ -87,7 +86,7 @@ internal static Episode GenerateFromAnimeEpisode(HttpContext ctx, SVR_AnimeEpiso
ep.summary = cae.Description;

ep.year = cae.AniDB_AirDate?.Year.ToString(CultureInfo.InvariantCulture);
ep.air = cae.AniDB_AirDate?.ToPlexDate();
ep.air = cae.AniDB_AirDate?.ToISO8601Date();

ep.votes = cae.AniDB_Votes;
ep.rating = cae.AniDB_Rating;
Expand Down Expand Up @@ -155,7 +154,7 @@ internal static Episode GenerateFromAnimeEpisode(HttpContext ctx, SVR_AnimeEpiso
var airdate = tvep.AirDate;
if (airdate != null)
{
ep.air = airdate.Value.ToPlexDate();
ep.air = airdate.Value.ToISO8601Date();
ep.year = airdate.Value.Year.ToString(CultureInfo.InvariantCulture);
}
}
Expand Down
12 changes: 9 additions & 3 deletions Shoko.Server/API/v2/Models/common/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using Microsoft.Extensions.DependencyInjection;
using Shoko.Models.Enums;
using Shoko.Models.PlexAndKodi;
using Shoko.Server.Extensions;
using Shoko.Server.Filters;
using Shoko.Server.Models;
using Shoko.Server.PlexAndKodi;
using Shoko.Server.Repositories;

namespace Shoko.Server.API.v2.Models.common;
Expand Down Expand Up @@ -79,7 +79,7 @@ public static Group GenerateFromAnimeGroup(HttpContext ctx, SVR_AnimeGroup ag, i

GenerateSizes(g, ael, uid);

g.air = anime.AirDate?.ToPlexDate() ?? string.Empty;
g.air = anime.AirDate?.ToISO8601Date() ?? string.Empty;

g.rating = Math.Round(ag.AniDBRating / 100, 1).ToString(CultureInfo.InvariantCulture);
g.summary = anime.Description ?? string.Empty;
Expand Down Expand Up @@ -150,12 +150,18 @@ public static Group GenerateFromAnimeGroup(HttpContext ctx, SVR_AnimeGroup ag, i
return g;
}

private static IEnumerable<T> Randomize<T>(IEnumerable<T> source, int seed = -1)
{
var rnd = seed == -1 ? new Random() : new Random(seed);
return source.OrderBy(item => rnd.Next());
}

public static void PopulateArtFromAniDBAnime(HttpContext ctx, IEnumerable<SVR_AniDB_Anime> animes, Group grp,
bool allpics, int pic)
{
var rand = new Random();

foreach (var anime in animes.Randomize())
foreach (var anime in Randomize(animes))
{
var tvdbIDs = RepoFactory.CrossRef_AniDB_TvDB.GetByAnimeID(anime.AnimeID).ToList();
var fanarts = tvdbIDs
Expand Down
8 changes: 4 additions & 4 deletions Shoko.Server/API/v2/Models/common/Serie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
using Shoko.Models.Server;
using Shoko.Server.Commands;
using Shoko.Server.Commands.AniDB;
using Shoko.Server.Extensions;
using Shoko.Server.Models;
using Shoko.Server.PlexAndKodi;
using Shoko.Server.Repositories;

namespace Shoko.Server.API.v2.Models.common;
Expand Down Expand Up @@ -115,7 +115,7 @@ public static Serie GenerateFromAniDB_Anime(HttpContext ctx, SVR_AniDB_Anime ani
var airdate = anime.AirDate.Value;
if (airdate != DateTime.MinValue)
{
sr.air = airdate.ToPlexDate();
sr.air = airdate.ToISO8601Date();
}
}

Expand Down Expand Up @@ -603,8 +603,8 @@ public int CompareTo(object obj)
}

// Does it have an air date? Sort by it
if (!string.IsNullOrEmpty(a.air) && !a.air.Equals(DateTime.MinValue.ToPlexDate()) &&
!string.IsNullOrEmpty(air) && !air.Equals(DateTime.MinValue.ToPlexDate()))
if (!string.IsNullOrEmpty(a.air) && !a.air.Equals(DateTime.MinValue.ToISO8601Date()) &&
!string.IsNullOrEmpty(air) && !air.Equals(DateTime.MinValue.ToISO8601Date()))
{
if (DateTime.TryParseExact(a.air, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None,
out var d1) &&
Expand Down
1 change: 0 additions & 1 deletion Shoko.Server/API/v2/Modules/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Shoko.Server.Commands;
using Shoko.Server.Commands.AniDB;
using Shoko.Server.Extensions;
using Shoko.Server.PlexAndKodi;
using Shoko.Server.Providers.AniDB;
using Shoko.Server.Providers.AniDB.Interfaces;
using Shoko.Server.Providers.TraktTV;
Expand Down
3 changes: 2 additions & 1 deletion Shoko.Server/Databases/MySQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Shoko.Server.Databases;
public class MySQL : BaseDatabase<MySqlConnection>
{
public override string Name { get; } = "MySQL";
public override int RequiredVersion { get; } = 120;
public override int RequiredVersion { get; } = 121;


private List<DatabaseCommand> createVersionTable = new()
Expand Down Expand Up @@ -746,6 +746,7 @@ public class MySQL : BaseDatabase<MySqlConnection>
new DatabaseCommand(119, 4, DatabaseFixes.MigrateGroupFilterToFilterPreset),
new DatabaseCommand(119, 5, DatabaseFixes.DropGroupFilter),
new DatabaseCommand(120, 1, "ALTER TABLE AnimeGroup DROP COLUMN SortName;"),
new DatabaseCommand(121, 1, "ALTER TABLE AnimeEpisode DROP COLUMN PlexContractVersion;ALTER TABLE AnimeEpisode DROP COLUMN PlexContractBlob;ALTER TABLE AnimeEpisode DROP COLUMN PlexContractSize;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractVersion;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractBlob;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractSize;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractVersion;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractBlob;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractSize;"),
};

private DatabaseCommand linuxTableVersionsFix = new("RENAME TABLE versions TO Versions;");
Expand Down
3 changes: 2 additions & 1 deletion Shoko.Server/Databases/SQLServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Shoko.Server.Databases;
public class SQLServer : BaseDatabase<SqlConnection>
{
public override string Name { get; } = "SQLServer";
public override int RequiredVersion { get; } = 113;
public override int RequiredVersion { get; } = 114;

public override void BackupDatabase(string fullfilename)
{
Expand Down Expand Up @@ -689,6 +689,7 @@ public override bool HasVersionsTable()
new DatabaseCommand(112, 4, DatabaseFixes.MigrateGroupFilterToFilterPreset),
new DatabaseCommand(112, 5, DatabaseFixes.DropGroupFilter),
new DatabaseCommand(113, 1, "ALTER TABLE AnimeGroup DROP COLUMN SortName;"),
new DatabaseCommand(114, 1, "ALTER TABLE AnimeEpisode DROP COLUMN PlexContractVersion;ALTER TABLE AnimeEpisode DROP COLUMN PlexContractBlob;ALTER TABLE AnimeEpisode DROP COLUMN PlexContractSize;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractVersion;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractBlob;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractSize;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractVersion;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractBlob;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractSize;"),
};

private static Tuple<bool, string> DropDefaultsOnAnimeEpisode_User(object connection)
Expand Down
3 changes: 2 additions & 1 deletion Shoko.Server/Databases/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SQLite : BaseDatabase<SqliteConnection>
{
public override string Name { get; } = "SQLite";

public override int RequiredVersion { get; } = 106;
public override int RequiredVersion { get; } = 107;


public override void BackupDatabase(string fullfilename)
Expand Down Expand Up @@ -680,6 +680,7 @@ public override void CreateDatabase()
new DatabaseCommand(105, 4, DatabaseFixes.MigrateGroupFilterToFilterPreset),
new DatabaseCommand(105, 5, DatabaseFixes.DropGroupFilter),
new DatabaseCommand(106, 1, "ALTER TABLE AnimeGroup DROP COLUMN SortName;"),
new DatabaseCommand(107, 1, "ALTER TABLE AnimeEpisode DROP COLUMN PlexContractVersion;ALTER TABLE AnimeEpisode DROP COLUMN PlexContractBlob;ALTER TABLE AnimeEpisode DROP COLUMN PlexContractSize;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractVersion;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractBlob;ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractSize;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractVersion;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractBlob;ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractSize;"),
};

private static Tuple<bool, string> DropLanguage(object connection)
Expand Down
101 changes: 4 additions & 97 deletions Shoko.Server/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Shoko.Commons.Extensions;
Expand All @@ -8,70 +9,17 @@ namespace Shoko.Server.Extensions;

public static class StringExtensions
{
public static void Deconstruct(this IList<string> list, out string first, out IList<string> rest) {
first = list.Count > 0 ? list[0] : "";
rest = list.Skip(1).ToList();
}

public static void Deconstruct(this IList<string> list, out string first, out string second, out IList<string> rest) {
first = list.Count > 0 ? list[0] : "";
second = list.Count > 1 ? list[1] : "";
rest = list.Skip(2).ToList();
}

public static void Deconstruct(this IList<string> list, out string first, out string second, out string third, out IList<string> rest) {
first = list.Count > 0 ? list[0] : "";
second = list.Count > 1 ? list[1] : "";
third = list.Count > 2 ? list[2] : "";
rest = list.Skip(3).ToList();
}

public static void Deconstruct(this IList<string> list, out string first, out string second, out string third, out string forth, out IList<string> rest) {
first = list.Count > 0 ? list[0] : "";
second = list.Count > 1 ? list[1] : "";
third = list.Count > 2 ? list[2] : "";
forth = list.Count > 3 ? list[3] : "";
rest = list.Skip(4).ToList();
}

public static bool Contains(this string item, string other, StringComparison comparer)
public static string ToISO8601Date(this DateTime dt)
{
if (item == null || other == null)
{
return false;
}

return item.IndexOf(other, comparer) >= 0;
}

public static void ShallowCopyTo(this object s, object d)
{
foreach (var pis in s.GetType().GetProperties())
{
foreach (var pid in d.GetType().GetProperties())
{
if (pid.Name == pis.Name)
{
pid.GetSetMethod().Invoke(d, new[] { pis.GetGetMethod().Invoke(s, null) });
}
}
}
}

public static void AddRange<K, V>(this IDictionary<K, V> dict, IDictionary<K, V> otherdict)
{
if (dict == null || otherdict == null)
{
return;
}

otherdict.ForEach(a =>
{
if (!dict.ContainsKey(a.Key))
{
dict.Add(a.Key, a.Value);
}
});
return dt.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
}

public static bool FindInEnumerable(this IEnumerable<string> items, IEnumerable<string> list)
Expand Down Expand Up @@ -108,26 +56,11 @@ public static bool FindInEnumerable(this IEnumerable<string> items, IEnumerable<
return listHash.Overlaps(itemHash);
}

public static bool FindInEnumerable(this IEnumerable<int> items, IEnumerable<int> list)
{
if (items == null || list == null)
{
return false;
}

return list.ToHashSet().Overlaps(items.ToHashSet());
}

public static bool FindIn(this string item, IEnumerable<string> list)
{
return list.Contains(item, StringComparer.InvariantCultureIgnoreCase);
}

public static int? ParseNullableInt(this string input)
{
return int.TryParse(input, out var output) ? output : (int?)null;
}

public static bool IsWithinErrorMargin(this DateTime value1, DateTime value2, TimeSpan error)
{
if (value1 > value2)
Expand All @@ -142,30 +75,4 @@ public static bool EqualsInvariantIgnoreCase(this string value1, string value2)
{
return value1.Equals(value2, StringComparison.InvariantCultureIgnoreCase);
}

public static string SplitCamelCaseToWords(this string strInput)
{
var strOutput = new StringBuilder();
int intCurrentCharPos;
var intLastCharPos = strInput.Length - 1;
for (intCurrentCharPos = 0; intCurrentCharPos <= intLastCharPos; intCurrentCharPos++)
{
var chrCurrentInputChar = strInput[intCurrentCharPos];
var chrPreviousInputChar = chrCurrentInputChar;

if (intCurrentCharPos > 0)
{
chrPreviousInputChar = strInput[intCurrentCharPos - 1];
}

if (char.IsUpper(chrCurrentInputChar) && char.IsLower(chrPreviousInputChar))
{
strOutput.Append(' ');
}

strOutput.Append(chrCurrentInputChar);
}

return strOutput.ToString();
}
}
37 changes: 0 additions & 37 deletions Shoko.Server/Models/SVR_AnimeGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
using Shoko.Models;
using Shoko.Models.Client;
using Shoko.Models.Enums;
using Shoko.Models.PlexAndKodi;
using Shoko.Models.Server;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Server.Databases;
using Shoko.Server.Extensions;
using Shoko.Server.LZ4;
using Shoko.Server.Repositories;
using Shoko.Server.Repositories.NHibernate;
using Shoko.Server.Settings;
using Shoko.Server.Tasks;
using Shoko.Server.Utilities;
using AnimeType = Shoko.Models.Enums.AnimeType;
using EpisodeType = Shoko.Models.Enums.EpisodeType;

Expand Down Expand Up @@ -127,38 +122,6 @@ public CL_AnimeGroup_User GetUserContract(int userid, HashSet<GroupFilterConditi
return contract;
}

public Video GetPlexContract(int userid)
{
return GetOrCreateUserRecord(userid).PlexContract;
}

private SVR_AnimeGroup_User GetOrCreateUserRecord(int userid)
{
var rr = GetUserRecord(userid);
if (rr != null)
{
return rr;
}

rr = new SVR_AnimeGroup_User(userid, AnimeGroupID)
{
WatchedCount = 0,
UnwatchedEpisodeCount = 0,
PlayedCount = 0,
StoppedCount = 0,
WatchedEpisodeCount = 0,
WatchedDate = null
};
RepoFactory.AnimeGroup_User.Save(rr);
return rr;
}

public static bool IsRelationTypeInExclusions(string type)
{
var list = Utils.SettingsProvider.GetSettings().AutoGroupSeriesRelationExclusions;
return list.Any(a => a.Equals(type, StringComparison.InvariantCultureIgnoreCase));
}

public SVR_AnimeGroup_User GetUserRecord(int userID)
{
return RepoFactory.AnimeGroup_User.GetByUserAndGroupID(userID, AnimeGroupID);
Expand Down
Loading

0 comments on commit cd6af10

Please sign in to comment.