Merge pull request #49 from tubearchivist/bugfix/sync-usernames
JF->TA Sync fix
This commit is contained in:
@@ -28,6 +28,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata
|
|||||||
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||||
{
|
{
|
||||||
private readonly IUserManager _userManager;
|
private readonly IUserManager _userManager;
|
||||||
|
private readonly IUserDataManager _userDataManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Plugin"/> class.
|
/// Initializes a new instance of the <see cref="Plugin"/> class.
|
||||||
@@ -63,6 +64,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata
|
|||||||
sessionManager.PlaybackProgress += OnPlaybackProgress;
|
sessionManager.PlaybackProgress += OnPlaybackProgress;
|
||||||
LibraryManager = libraryManager;
|
LibraryManager = libraryManager;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
_userDataManager = userDataManager;
|
||||||
userDataManager.UserDataSaved += OnWatchedStatusChange;
|
userDataManager.UserDataSaved += OnWatchedStatusChange;
|
||||||
|
|
||||||
var taToJellyfinProgressSyncTask = new TAToJellyfinProgressSyncTask(logger, libraryManager, userManager, userDataManager);
|
var taToJellyfinProgressSyncTask = new TAToJellyfinProgressSyncTask(logger, libraryManager, userManager, userDataManager);
|
||||||
@@ -173,7 +175,8 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata
|
|||||||
{
|
{
|
||||||
if (Instance!.Configuration.JFTASync && eventArgs.Users.Any(u => Instance!.Configuration.JFUsernameFrom.Equals(u.Username, StringComparison.Ordinal)))
|
if (Instance!.Configuration.JFTASync && eventArgs.Users.Any(u => Instance!.Configuration.JFUsernameFrom.Equals(u.Username, StringComparison.Ordinal)))
|
||||||
{
|
{
|
||||||
BaseItem? channel = LibraryManager.GetItemById(eventArgs.Item.ParentId);
|
BaseItem? season = LibraryManager.GetItemById(eventArgs.Item.ParentId);
|
||||||
|
BaseItem? channel = LibraryManager.GetItemById(season!.ParentId);
|
||||||
BaseItem? collection = LibraryManager.GetItemById(channel!.ParentId);
|
BaseItem? collection = LibraryManager.GetItemById(channel!.ParentId);
|
||||||
if (collection?.Name.ToLower(CultureInfo.CurrentCulture) == Instance?.Configuration.CollectionTitle.ToLower(CultureInfo.CurrentCulture) && eventArgs.PlaybackPositionTicks != null)
|
if (collection?.Name.ToLower(CultureInfo.CurrentCulture) == Instance?.Configuration.CollectionTitle.ToLower(CultureInfo.CurrentCulture) && eventArgs.PlaybackPositionTicks != null)
|
||||||
{
|
{
|
||||||
@@ -224,6 +227,17 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata
|
|||||||
{
|
{
|
||||||
Logger.LogCritical("POST /watched returned {StatusCode} for item {ItemName} ({VideoYTId}) with watched status {IsPlayed}", statusCode, eventArgs.Item.Name, itemYTId, isPlayed);
|
Logger.LogCritical("POST /watched returned {StatusCode} for item {ItemName} ({VideoYTId}) with watched status {IsPlayed}", statusCode, eventArgs.Item.Name, itemYTId, isPlayed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventArgs.Item is Episode)
|
||||||
|
{
|
||||||
|
var progress = _userDataManager.GetUserData(user, eventArgs.Item).PlaybackPositionTicks / TimeSpan.TicksPerSecond;
|
||||||
|
var videoId = Utils.GetVideoNameFromPath(eventArgs.Item.Path);
|
||||||
|
statusCode = await TubeArchivistApi.GetInstance().SetProgress(videoId, progress).ConfigureAwait(true);
|
||||||
|
if (statusCode != System.Net.HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
Logger.LogCritical("{Message}", $"POST /video/{videoId}/progress returned {statusCode} for video {eventArgs.Item.Name} with progress {progress} seconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Data.Enums;
|
using Jellyfin.Data.Enums;
|
||||||
@@ -45,7 +46,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Tasks
|
|||||||
public string Name => "JFToTubeArchivistProgressSyncTask";
|
public string Name => "JFToTubeArchivistProgressSyncTask";
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public string Description => "This tasks syncs TubeArchivist playback progresses to Jellyfin";
|
public string Description => "This tasks syncs Jellyfin playback progresses to TubeArchivist";
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public string Category => "TubeArchivistMetadata";
|
public string Category => "TubeArchivistMetadata";
|
||||||
@@ -63,13 +64,12 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Tasks
|
|||||||
_logger.LogInformation("Starting Jellyfin->TubeArchivist playback progresses synchronization.");
|
_logger.LogInformation("Starting Jellyfin->TubeArchivist playback progresses synchronization.");
|
||||||
var taApi = TubeArchivistApi.GetInstance();
|
var taApi = TubeArchivistApi.GetInstance();
|
||||||
var videosCount = 0;
|
var videosCount = 0;
|
||||||
foreach (var jfUsername in Plugin.Instance!.Configuration.GetJFUsernamesToArray())
|
var jfUsername = Plugin.Instance!.Configuration.JFUsernameFrom;
|
||||||
{
|
|
||||||
var user = _userManager.GetUserByName(jfUsername);
|
var user = _userManager.GetUserByName(jfUsername);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("{Message}", $"Jellyfin user with username {jfUsername} not found");
|
_logger.LogInformation("{Message}", $"Jellyfin user with username {jfUsername} not found");
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var collectionItem = _libraryManager.GetItemList(new InternalItemsQuery
|
var collectionItem = _libraryManager.GetItemList(new InternalItemsQuery
|
||||||
@@ -113,26 +113,10 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation("Found a total of {VideosCount} videos", videosCount);
|
_logger.LogInformation("Found a total of {VideosCount} videos", videosCount);
|
||||||
|
|
||||||
var processedVideosCount = 0;
|
var processedVideosCount = 0;
|
||||||
foreach (var jfUsername in Plugin.Instance!.Configuration.GetJFUsernamesToArray())
|
|
||||||
{
|
|
||||||
var user = _userManager.GetUserByName(jfUsername);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("{Message}", $"Jellyfin user with username {jfUsername} not found");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var collectionItem = _libraryManager.GetItemList(new InternalItemsQuery
|
|
||||||
{
|
|
||||||
Name = Plugin.Instance?.Configuration.CollectionTitle,
|
|
||||||
IncludeItemTypes = new[] { BaseItemKind.CollectionFolder }
|
|
||||||
}).FirstOrDefault();
|
|
||||||
|
|
||||||
if (collectionItem == null)
|
if (collectionItem == null)
|
||||||
{
|
{
|
||||||
var message = $"Collection '{Plugin.Instance?.Configuration.CollectionTitle}' not found.";
|
var message = $"Collection '{Plugin.Instance?.Configuration.CollectionTitle}' not found.";
|
||||||
@@ -167,12 +151,8 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Tasks
|
|||||||
foreach (Episode video in videos)
|
foreach (Episode video in videos)
|
||||||
{
|
{
|
||||||
var videoYTId = Utils.GetVideoNameFromPath(video.Path);
|
var videoYTId = Utils.GetVideoNameFromPath(video.Path);
|
||||||
var playbackProgress = _userDataManager.GetUserData(user, video).PlaybackPositionTicks / TimeSpan.TicksPerSecond;
|
_logger.LogInformation("{VideoYtId}", videoYTId);
|
||||||
var statusCode = await taApi.SetProgress(videoYTId, playbackProgress).ConfigureAwait(true);
|
HttpStatusCode statusCode;
|
||||||
if (statusCode != System.Net.HttpStatusCode.OK)
|
|
||||||
{
|
|
||||||
_logger.LogCritical("{Message}", $"POST /video/{videoYTId}/progress returned {statusCode} for video {video.Name} with progress {progress} seconds");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isChannelCheckedForWatched && channel.IsPlayed(user))
|
if (!isChannelCheckedForWatched && channel.IsPlayed(user))
|
||||||
{
|
{
|
||||||
@@ -198,6 +178,17 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Tasks
|
|||||||
{
|
{
|
||||||
_logger.LogCritical("{Message}", $"POST /watched returned {statusCode} for video {video.Name} ({videoYTId}) with wacthed status {isVideoPlayed}");
|
_logger.LogCritical("{Message}", $"POST /watched returned {statusCode} for video {video.Name} ({videoYTId}) with wacthed status {isVideoPlayed}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("{Message}", isVideoPlayed);
|
||||||
|
if (!isVideoPlayed)
|
||||||
|
{
|
||||||
|
var playbackProgress = _userDataManager.GetUserData(user, video).PlaybackPositionTicks / TimeSpan.TicksPerSecond;
|
||||||
|
statusCode = await taApi.SetProgress(videoYTId, playbackProgress).ConfigureAwait(true);
|
||||||
|
if (statusCode != System.Net.HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
_logger.LogCritical("{Message}", $"POST /video/{videoYTId}/progress returned {statusCode} for video {video.Name} with progress {progress} seconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processedVideosCount++;
|
processedVideosCount++;
|
||||||
@@ -206,7 +197,6 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation("Time elapsed: {Time}", DateTime.Now - start);
|
_logger.LogInformation("Time elapsed: {Time}", DateTime.Now - start);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user