@@ -75,6 +75,9 @@ private Command PodcastImportIndexDef()
7575 Command cmd = new ( "kpPodcastImportIndex" , "Import existing podcast memory index" )
7676 {
7777 Args . Arg < string > ( "filePath" , "Path to existing podcast index" ) ,
78+ Options . Arg < string > ( "startAt" , "ISO date: When the podcast occurred" ) ,
79+ Options . Arg < int > ( "length" , "In minutes" ) ,
80+ Options . Arg < bool > ( "buildIndex" , "Also build index" , true )
7881 } ;
7982 cmd . SetAction ( this . PodcastImportIndexAsync ) ;
8083 return cmd ;
@@ -84,6 +87,46 @@ private async Task PodcastImportIndexAsync(ParseResult args, CancellationToken c
8487 {
8588 NamedArgs namedArgs = new ( args ) ;
8689 string ? filePath = namedArgs . Get ( "filePath" ) ;
90+ if ( string . IsNullOrEmpty ( filePath ) )
91+ {
92+ return ;
93+ }
94+ string ext = Path . GetExtension ( filePath ) ;
95+ string podcastName = Path . GetFileNameWithoutExtension ( filePath ) ;
96+ if ( ext . Equals ( "json" , StringComparison . OrdinalIgnoreCase ) )
97+ {
98+ await ImportExistingIndexAsync ( namedArgs , filePath , podcastName , cancellationToken ) ;
99+ }
100+ else
101+ {
102+ await ImportTranscriptAsync ( namedArgs , filePath , podcastName , cancellationToken ) ;
103+ }
104+ }
105+
106+ private async Task ImportTranscriptAsync ( NamedArgs namedArgs , string filePath , string podcastName , CancellationToken cancellationToken )
107+ {
108+ UnloadCurrent ( ) ;
109+ Podcast podcast = CreatePodcast ( podcastName , true ) ;
110+ SetCurrent ( podcast ) ;
111+
112+ string ? startAt = namedArgs . Get < string > ( "startAt" ) ;
113+ DateTimeOffset ? startDate = ! string . IsNullOrEmpty ( startAt ) ? DateTimeOffset . Parse ( startAt ) : null ;
114+
115+ await podcast . ImportTranscriptAsync (
116+ filePath ,
117+ podcastName ,
118+ startDate ,
119+ namedArgs . Get < int > ( "length" )
120+ ) ;
121+
122+ if ( namedArgs . Get < bool > ( "buildIndex" ) )
123+ {
124+ await podcast . UpdateIndexAsync ( cancellationToken ) ;
125+ }
126+ }
127+
128+ private async Task ImportExistingIndexAsync ( NamedArgs namedArgs , string filePath , string podcastName , CancellationToken cancellationToken )
129+ {
87130 var data = ConversationJsonSerializer . ReadFromFile < PodcastMessage > ( filePath ! ) ;
88131 if ( data is null )
89132 {
@@ -94,7 +137,6 @@ private async Task PodcastImportIndexAsync(ParseResult args, CancellationToken c
94137
95138 UnloadCurrent ( ) ;
96139
97- string ? podcastName = Path . GetFileNameWithoutExtension ( filePath ) ?? throw new NotSupportedException ( ) ;
98140 KnowProWriter . WriteLine ( ConsoleColor . Cyan , $ "Importing { podcastName } ") ;
99141 var podcast = CreatePodcast ( podcastName , true ) ;
100142 try
@@ -129,6 +171,7 @@ private async Task PodcastImportIndexAsync(ParseResult args, CancellationToken c
129171 }
130172 }
131173
174+
132175 private Podcast CreatePodcast ( string name , bool createNew )
133176 {
134177 MemorySettings settings = new MemorySettings ( ) ;
0 commit comments