@ -33,202 +33,207 @@ public class Worker : BackgroundService
@@ -33,202 +33,207 @@ public class Worker : BackgroundService
// need to strip program name (head) from command line args
string [ ] arguments = Environment . GetCommandLineArgs ( ) . Skip ( 1 ) . ToArray ( ) ;
await rootCommand . InvokeAsync ( arguments ) ;
ParseResult parseResult = rootCommand . Parse ( arguments ) ;
await parseResult . InvokeAsync ( stoppingToken ) ;
_ appLifetime . StopApplication ( ) ;
}
private RootCommand ConfigureCommandLine ( )
{
var forceOption = new System . CommandLine . Option < bool > (
"--force" ,
description : "Force scanning" ,
parseArgument : _ = > true )
var forceOption = new System . CommandLine . Option < bool > ( "--force" )
{
AllowMultipleArgumentsPerToken = true ,
Arity = ArgumentArity . Zero
Arity = ArgumentArity . Zero ,
Description = "Force scanning" ,
DefaultValueFactory = _ = > false
} ;
var deepOption = new System . CommandLine . Option < bool > (
"--deep" ,
description : "Deep scan" ,
parseArgument : _ = > true )
var deepOption = new System . CommandLine . Option < bool > ( "--deep" )
{
AllowMultipleArgumentsPerToken = true ,
Arity = ArgumentArity . Zero
Arity = ArgumentArity . Zero ,
Description = "Deep scan" ,
DefaultValueFactory = _ = > false
} ;
var libraryIdArgument = new Argument < int > ( "library-id" , "The library id to scan" ) ;
var mediaSourceIdArgument = new Argument < int > ( "media-source-id" , "The media source id to scan" ) ;
var libraryIdArgument = new Argument < int > ( "library-id" )
{
Description = "The library id to scan"
} ;
var mediaSourceIdArgument = new Argument < int > ( "media-source-id" )
{
Description = "The media source id to scan"
} ;
var scanLocalCommand = new Command ( "scan-local" , "Scan a local library" ) ;
scanLocalCommand . AddArgument ( libraryIdArgument ) ;
scanLocalCommand . AddOption ( forceOption ) ;
scanLocalCommand . Arguments . Add ( libraryIdArgument ) ;
scanLocalCommand . Options . Add ( forceOption ) ;
var scanPlexCommand = new Command ( "scan-plex" , "Scan a Plex library" ) ;
scanPlexCommand . AddA rgument ( libraryIdArgument ) ;
scanPlexCommand . Add Option( forceOption ) ;
scanPlexCommand . Add Option( deepOption ) ;
scanPlexCommand . Arguments . Add ( libraryIdArgument ) ;
scanPlexCommand . Options . Add ( forceOption ) ;
scanPlexCommand . Options . Add ( deepOption ) ;
var scanPlexCollectionsCommand = new Command ( "scan-plex-collections" , "Scan Plex collections" ) ;
scanPlexCollectionsCommand . AddA rgument ( mediaSourceIdArgument ) ;
scanPlexCollectionsCommand . Add Option( forceOption ) ;
scanPlexCollectionsCommand . Arguments . Add ( mediaSourceIdArgument ) ;
scanPlexCollectionsCommand . Options . Add ( forceOption ) ;
var scanEmbyCommand = new Command ( "scan-emby" , "Scan an Emby library" ) ;
scanEmbyCommand . AddA rgument ( libraryIdArgument ) ;
scanEmbyCommand . Add Option( forceOption ) ;
scanEmbyCommand . Add Option( deepOption ) ;
scanEmbyCommand . Arguments . Add ( libraryIdArgument ) ;
scanEmbyCommand . Options . Add ( forceOption ) ;
scanEmbyCommand . Options . Add ( deepOption ) ;
var scanEmbyCollectionsCommand = new Command ( "scan-emby-collections" , "Scan Emby collections" ) ;
scanEmbyCollectionsCommand . AddA rgument ( mediaSourceIdArgument ) ;
scanEmbyCollectionsCommand . Add Option( forceOption ) ;
scanEmbyCollectionsCommand . Arguments . Add ( mediaSourceIdArgument ) ;
scanEmbyCollectionsCommand . Options . Add ( forceOption ) ;
var scanJellyfinCommand = new Command ( "scan-jellyfin" , "Scan a Jellyfin library" ) ;
scanJellyfinCommand . AddA rgument ( libraryIdArgument ) ;
scanJellyfinCommand . Add Option( forceOption ) ;
scanJellyfinCommand . Add Option( deepOption ) ;
scanJellyfinCommand . Arguments . Add ( libraryIdArgument ) ;
scanJellyfinCommand . Options . Add ( forceOption ) ;
scanJellyfinCommand . Options . Add ( deepOption ) ;
var scanJellyfinCollectionsCommand = new Command ( "scan-jellyfin-collections" , "Scan Jellyfin collections" ) ;
scanJellyfinCollectionsCommand . AddA rgument ( mediaSourceIdArgument ) ;
scanJellyfinCollectionsCommand . Add Option( forceOption ) ;
scanJellyfinCollectionsCommand . Arguments . Add ( mediaSourceIdArgument ) ;
scanJellyfinCollectionsCommand . Options . Add ( forceOption ) ;
scanLocalCommand . SetHandler (
async context = >
scanLocalCommand . SetAction (
async ( parseResult , token ) = >
{
if ( IsScanningEnabled ( ) )
{
bool force = context . P arseResult. GetValueForOption ( forceOption ) ;
bool force = p arseResult. GetValue ( forceOption ) ;
SetProcessPriority ( force ) ;
int libraryId = context . Pa rseResult. GetValueForArgument ( libraryIdArgument ) ;
int libraryId = pa rseResult. GetValue ( libraryIdArgument ) ;
using IServiceScope scope = _ serviceScopeFactory . CreateScope ( ) ;
IMediator mediator = scope . ServiceProvider . GetRequiredService < IMediator > ( ) ;
var scan = new ScanLocalLibrary ( libraryId , force ) ;
await mediator . Send ( scan , con text . GetCancellationT oken( ) ) ;
await mediator . Send ( scan , token ) ;
}
} ) ;
scanPlexCommand . SetHandler (
async context = >
scanPlexCommand . SetAction (
async ( parseResult , token ) = >
{
if ( IsScanningEnabled ( ) )
{
bool force = context . P arseResult. GetValueForOption ( forceOption ) ;
bool force = p arseResult. GetValue ( forceOption ) ;
SetProcessPriority ( force ) ;
bool deep = context . P arseResult. GetValueForOption ( deepOption ) ;
int libraryId = context . Pa rseResult. GetValueForArgument ( libraryIdArgument ) ;
bool deep = p arseResult. GetValue ( deepOption ) ;
int libraryId = pa rseResult. GetValue ( libraryIdArgument ) ;
using IServiceScope scope = _ serviceScopeFactory . CreateScope ( ) ;
IMediator mediator = scope . ServiceProvider . GetRequiredService < IMediator > ( ) ;
var scan = new SynchronizePlexLibraryById ( libraryId , force , deep ) ;
await mediator . Send ( scan , con text . GetCancellationT oken( ) ) ;
await mediator . Send ( scan , token ) ;
}
} ) ;
scanPlexCollectionsCommand . SetHandler (
async context = >
scanPlexCollectionsCommand . SetAction (
async ( parseResult , token ) = >
{
if ( IsScanningEnabled ( ) )
{
bool force = context . P arseResult. GetValueForOption ( forceOption ) ;
bool force = p arseResult. GetValue ( forceOption ) ;
SetProcessPriority ( force ) ;
int mediaSourceId = context . Pa rseResult. GetValueForArgument ( mediaSourceIdArgument ) ;
int mediaSourceId = pa rseResult. GetValue ( mediaSourceIdArgument ) ;
using IServiceScope scope = _ serviceScopeFactory . CreateScope ( ) ;
IMediator mediator = scope . ServiceProvider . GetRequiredService < IMediator > ( ) ;
var scan = new SynchronizePlexCollections ( mediaSourceId , force ) ;
await mediator . Send ( scan , con text . GetCancellationT oken( ) ) ;
await mediator . Send ( scan , token ) ;
}
} ) ;
scanEmbyCommand . SetHandler (
async context = >
scanEmbyCommand . SetAction (
async ( parseResult , token ) = >
{
if ( IsScanningEnabled ( ) )
{
bool force = context . P arseResult. GetValueForOption ( forceOption ) ;
bool force = p arseResult. GetValue ( forceOption ) ;
SetProcessPriority ( force ) ;
bool deep = context . P arseResult. GetValueForOption ( deepOption ) ;
int libraryId = context . Pa rseResult. GetValueForArgument ( libraryIdArgument ) ;
bool deep = p arseResult. GetValue ( deepOption ) ;
int libraryId = pa rseResult. GetValue ( libraryIdArgument ) ;
using IServiceScope scope = _ serviceScopeFactory . CreateScope ( ) ;
IMediator mediator = scope . ServiceProvider . GetRequiredService < IMediator > ( ) ;
var scan = new SynchronizeEmbyLibraryById ( libraryId , force , deep ) ;
await mediator . Send ( scan , con text . GetCancellationT oken( ) ) ;
await mediator . Send ( scan , token ) ;
}
} ) ;
scanEmbyCollectionsCommand . SetHandler (
async context = >
scanEmbyCollectionsCommand . SetAction (
async ( parseResult , token ) = >
{
if ( IsScanningEnabled ( ) )
{
bool force = context . P arseResult. GetValueForOption ( forceOption ) ;
bool force = p arseResult. GetValue ( forceOption ) ;
SetProcessPriority ( force ) ;
int mediaSourceId = context . Pa rseResult. GetValueForArgument ( mediaSourceIdArgument ) ;
int mediaSourceId = pa rseResult. GetValue ( mediaSourceIdArgument ) ;
using IServiceScope scope = _ serviceScopeFactory . CreateScope ( ) ;
IMediator mediator = scope . ServiceProvider . GetRequiredService < IMediator > ( ) ;
var scan = new SynchronizeEmbyCollections ( mediaSourceId , force ) ;
await mediator . Send ( scan , con text . GetCancellationT oken( ) ) ;
await mediator . Send ( scan , token ) ;
}
} ) ;
scanJellyfinCommand . SetHandler (
async context = >
scanJellyfinCommand . SetAction (
async ( parseResult , token ) = >
{
if ( IsScanningEnabled ( ) )
{
bool force = context . P arseResult. GetValueForOption ( forceOption ) ;
bool force = p arseResult. GetValue ( forceOption ) ;
SetProcessPriority ( force ) ;
bool deep = context . P arseResult. GetValueForOption ( deepOption ) ;
int libraryId = context . Pa rseResult. GetValueForArgument ( libraryIdArgument ) ;
bool deep = p arseResult. GetValue ( deepOption ) ;
int libraryId = pa rseResult. GetValue ( libraryIdArgument ) ;
using IServiceScope scope = _ serviceScopeFactory . CreateScope ( ) ;
IMediator mediator = scope . ServiceProvider . GetRequiredService < IMediator > ( ) ;
var scan = new SynchronizeJellyfinLibraryById ( libraryId , force , deep ) ;
await mediator . Send ( scan , con text . GetCancellationT oken( ) ) ;
await mediator . Send ( scan , token ) ;
}
} ) ;
scanJellyfinCollectionsCommand . SetHandler (
async context = >
scanJellyfinCollectionsCommand . SetAction (
async ( parseResult , token ) = >
{
if ( IsScanningEnabled ( ) )
{
bool force = context . P arseResult. GetValueForOption ( forceOption ) ;
bool force = p arseResult. GetValue ( forceOption ) ;
SetProcessPriority ( force ) ;
int mediaSourceId = context . Pa rseResult. GetValueForArgument ( mediaSourceIdArgument ) ;
int mediaSourceId = pa rseResult. GetValue ( mediaSourceIdArgument ) ;
using IServiceScope scope = _ serviceScopeFactory . CreateScope ( ) ;
IMediator mediator = scope . ServiceProvider . GetRequiredService < IMediator > ( ) ;
var scan = new SynchronizeJellyfinCollections ( mediaSourceId , force ) ;
await mediator . Send ( scan , con text . GetCancellationT oken( ) ) ;
await mediator . Send ( scan , token ) ;
}
} ) ;
var rootCommand = new RootCommand ( ) ;
rootCommand . AddComman d( scanLocalCommand ) ;
rootCommand . AddComman d( scanPlexCommand ) ;
rootCommand . AddComman d( scanPlexCollectionsCommand ) ;
rootCommand . AddComman d( scanEmbyCommand ) ;
rootCommand . AddComman d( scanEmbyCollectionsCommand ) ;
rootCommand . AddComman d( scanJellyfinCommand ) ;
rootCommand . AddComman d( scanJellyfinCollectionsCommand ) ;
rootCommand . Subcommands . Ad d( scanLocalCommand ) ;
rootCommand . Subcommands . Ad d( scanPlexCommand ) ;
rootCommand . Subcommands . Ad d( scanPlexCollectionsCommand ) ;
rootCommand . Subcommands . Ad d( scanEmbyCommand ) ;
rootCommand . Subcommands . Ad d( scanEmbyCollectionsCommand ) ;
rootCommand . Subcommands . Ad d( scanJellyfinCommand ) ;
rootCommand . Subcommands . Ad d( scanJellyfinCollectionsCommand ) ;
return rootCommand ;
}