Jump to content

Best path for cleaning up duplicate People profiles / folders?


Go to solution Solved by Smitty018210,

Recommended Posts

ginjaninja
Posted (edited)

good find..

could be this then

https://dev.emby.media/reference/pluginapi/MediaBrowser.Controller.Entities.BaseItem.html#MediaBrowser_Controller_Entities_BaseItem_GetInternalMetadataPath
and this GetImagePath(BaseItem, ImageType)

https://dev.emby.media/reference/pluginapi/MediaBrowser.Controller.Entities.BaseItemExtensions.html

edit seems the ai gods agree
 

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Tasks;

namespace Emby.PersonPathExporter
{
    public class ExportPersonPathsTask : IScheduledTask
    {
        private readonly ILibraryManager _libraryManager;
        private readonly ILogger _logger;

        // Emby automatically injects dependencies via the constructor
        public ExportPersonPathsTask(ILibraryManager libraryManager, ILogManager logManager)
        {
            _libraryManager = libraryManager;
            _logger = logManager.GetLogger(Name);
        }

        public string Name => "Export Person Paths and Metadata";
        public string Key => "ExportPersonPathsAndMetadataTask";
        public string Description => "Logs the InternalMetadataPath and ImagePath for every person in the Emby library.";
        public string Category => "Maintenance";

        public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
        {
            _logger.Info("Starting Person Path Export task...");

            // Query items of type 'Person' recursively across the entire database
            var query = new InternalItemsQuery
            {
                IncludeItemTypes = new[] { Tuple.Create(typeof(Person).Name, false) },
                Recursive = true
            };

            var people = _libraryManager.GetItemList(query);

            if (people == null || people.Length == 0)
            {
                _logger.Info("No people found in the library database.");
                progress.Report(100);
                return;
            }

            int totalCount = people.Length;
            int currentCount = 0;

            _logger.Info($"Found {totalCount} people. Iterating and logging paths...");

            foreach (var item in people)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (item is Person person)
                {
                    // Extract paths
                    string name = person.Name ?? "Unknown";
                    string internalMetadataPath = person.InternalMetadataPath ?? "No internal metadata path available";
                    
                    // Retrieve the primary image path if it exists
                    string imagePath = person.GetImagePath(ImageType.Primary) ?? "No primary image path found";

                    // Output directly to Emby server's primary logs
                    _logger.Info($"Person: {name} | MetadataPath: {internalMetadataPath} | ImagePath: {imagePath}");
                }

                currentCount++;
                progress.Report((double)currentCount / totalCount * 100);
            }

            _logger.Info("Finished exporting person paths.");
            await Task.CompletedTask;
        }

        public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
        {
            // Provides a template for manual execution, but can be scheduled to run weekly if needed
            return new[]
            {
                new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerManual }
            };
        }
    }
}

 

Edited by ginjaninja

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...