@@ -17,7 +17,7 @@ export default class DownloadCLient {
1717 * */
1818 @LogMethod ( { scope, message : "Downloading files..." } )
1919 static async downloadFiles (
20- filenamePrefix : string ,
20+ filename : string ,
2121 urls : string [ ] ,
2222 authToken : string ,
2323 keepZip = false
@@ -29,22 +29,34 @@ export default class DownloadCLient {
2929 keepZip &&
3030 ( await Promise . all (
3131 buffers . map ( ( buffer , idx ) =>
32- DownloadCLient . save ( buffer , `/${ filenamePrefix } -${ idx } .zip` )
32+ DownloadCLient . save ( buffer , `/${ filename } -${ idx } .zip` )
3333 )
3434 ) ) ;
3535
3636 const paths = await Promise . all (
3737 buffers . map ( ( buffer , idx ) =>
38- DownloadCLient . unzip ( buffer , `/${ filenamePrefix } -${ idx } ` )
38+ DownloadCLient . unzip ( buffer , `/${ filename } -${ idx } ` )
3939 )
4040 ) ;
4141
42- const finalPath = path . join ( DOWNLOAD_DIR , filenamePrefix ) ;
42+ const finalPath = path . join ( DOWNLOAD_DIR , filename ) ;
4343 await DownloadCLient . mergeDirectories ( paths , finalPath ) ;
4444
4545 return [ finalPath , zipped_files ] ;
4646 }
4747
48+ /**
49+ * Save Audiobook object as JSON file alongside the downloaded files.
50+ */
51+ @LogMethod ( { scope, message : "Saving metadata..." } )
52+ static async saveMetadata (
53+ book : Audiobook ,
54+ filepath : string
55+ ) : Promise < void > {
56+ const metadataPath = path . join ( filepath , "metadata.json" ) ;
57+ fs . writeFileSync ( metadataPath , JSON . stringify ( book , null , 2 ) ) ;
58+ }
59+
4860 /** Downloads a file from a URL and returns the data as a Uint8Array */
4961 @LogMethod ( { scope, message : "Downloading file..." } )
5062 private static async download (
0 commit comments