Jump to content

Immediate Scan of folder avoiding timers


Recommended Posts

ginjaninja
Posted

I am writing a plugin that copy files and appends tags to the subsequent library items

I have it working lazily, looking for the item added event before tagging the library object but i would like to force a scan of the folder immediately avoiding the debounce timer.

There seems to be lots of talk on forums but no actual solution, save an old rest endpoints  (no longer present on swagger) used by an autoscanutility.

The target are folders in a path in scope of a  library (but not ingested yet).

i dont want to subscribe to have them scanned at a later point.

Prefer to use a native plugin but rest api is fine too.

any ideas?

thanks

ginjaninja
Posted
ComingSoonEntryPoint.RegisterPendingPath(folderPath);
this.logger.Info("ManageComingSoon: [Step 2] Releasing LibraryMonitor suppression with immediate refresh for {0}", folderPath);
this.libraryMonitor.ReportFileSystemChangeComplete(folderPath, true);
this.logger.Info("ManageComingSoon: [Step 3] ReportFileSystemChangeComplete called – FileRefresher should start shortly");

// Tag is applied by ComingSoonEntryPoint.OnItemAdded when ItemAdded fires.
this.logger.Info("ManageComingSoon: Placeholder created. Awaiting FileRefresher ingest and ItemAdded.");

I think this a reasonable approach?

it seem emby needs to do all the ffmpeg and provider lookups prior, rather than instantiating the library object 1st and then decorating it with information that comes from the analysis and providers.

For completeness with emby paradigm and my learning, might i consider registering as a metadata provider, could my plugin give the known TMDBID for this movies file path to onward providers. (so no mistakes are possible)..if that is a thing i can go and investigate.

 

thanks

Posted
Quote

this.libraryMonitor.ReportFileSystemChangeComplete(folderPath, true);

Yes, this is sufficient, however the timer is just internal behavior and currently cannot be avoided.

ginjaninja
Posted

For forced scans, emulating what can be achieved in the dashbaord, i end up using post to api within the items/X/refresh endpoint. Couldnt get this to work from native methods.

private async Task CallRefreshEndpointAsync(
    IHttpClient httpClient, string baseUrl, long internalId, string roleLabel,
    string apiKey, MetadataRefreshMode mode, string stageLabel, CancellationToken token)
{
    string url = string.Format(
        "{0}/Items/{1}/Refresh?Recursive=true&MetadataRefreshMode={2}&ImageRefreshMode={2}&ReplaceAllMetadata=false&ReplaceAllImages=false&api_key={3}",
        baseUrl.TrimEnd('/'),
        internalId,
        mode,
        Uri.EscapeDataString(apiKey));

    this.logger.Info(
        "[{0}] POST /Items/{1}/Refresh — target=({2}) InternalId={1} Mode={3}",
        stageLabel, internalId, roleLabel, mode);

    var options = new HttpRequestOptions
    {
        Url = url,
        CancellationToken = token,
        TimeoutMs = 15000,
        LogErrors = true,
    };

    using (var response = await httpClient.Post(options).ConfigureAwait(false))
    {
        this.logger.Info(
            "[{0}] POST /Items/{1}/Refresh ({2}) returned (2xx implied)",
            stageLabel, internalId, roleLabel);
    }
}

For disk moves Ai gave me this pattern. Its not  tested to destruction  but its going the job of persisting a movie id on path change
 

ctx.Movie.Path = ctx.MovieNewVideoPath;
ctx.Movie.ParentId = ctx.DestinationFolder.InternalId;

this.itemRepository.SaveItem(ctx.Movie, token);
LogItemState("Pipeline/Advanced - tag+path+ParentId SaveItem (persisted directly)", "Movie", ctx.Movie);

this.libraryManager.UpdateItem(ctx.Movie, ctx.DestinationFolder, ItemUpdateType.MetadataEdit, null);
LogItemState("Pipeline/Advanced - UpdateItem (cache/event refresh)", "Movie", ctx.Movie);

 

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...