Fix JFToTubearchivistProgressSyncTask
This commit is contained in:
@@ -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