4242from ytmdl .utils .ytdl import is_ytdl_config_present
4343from ytmdl .yt import is_yt_url
4444from ytmdl .__version__ import __version__
45+ from typing import Tuple
4546
4647# init colorama for windows
4748init ()
@@ -111,7 +112,7 @@ def arguments():
111112 metadata_group .add_argument ("--ask-meta-name" , help = "Ask the user to enter a separate \
112113 name for searching the metadata (Default: false)" , action = "store_true" )
113114 metadata_group .add_argument ("--on-meta-error" , help = "What to do if adding the metadata fails \
114- for some reasong like lack of metadata or perhaps a network issue. \
115+ for some reason like lack of metadata or perhaps a network issue. \
115116 Options are {}" .format (defaults .DEFAULT .ON_ERROR_OPTIONS ),
116117 type = str , default = None )
117118
@@ -156,6 +157,9 @@ def arguments():
156157 action = "store_true" )
157158 parser .add_argument ('--ytdl-config' , help = "Path to the youtube-dl config location or the "
158159 "directory" , default = None , metavar = "PATH" , type = str )
160+ parser .add_argument ("--dont-transcode" , help = "Don't transcode the audio after \
161+ downloading. Applicable for OPUS format only. (Default: false)" ,
162+ action = "store_true" )
159163
160164 playlist_group = parser .add_argument_group ("Playlist" )
161165 playlist_group .add_argument (
@@ -228,7 +232,8 @@ def arguments():
228232def main (args ):
229233 """Run on program call."""
230234
231- song_name = extract_song_name (args )
235+ song_name , verify_name = extract_song_name (args )
236+ logger .debug ("verify title: " , str (verify_name ))
232237
233238 # Extract the archive file contents
234239 is_download_archive = args .download_archive is not None
@@ -292,7 +297,15 @@ def main(args):
292297 # Try to extract the chapters
293298 chapters = yt .get_chapters (link , args .ytdl_config )
294299
295- songs_to_download = [{}]
300+ # Add the current passed song as the only entry here
301+ # This dictionary will be cleared if the song is found to be containing
302+ # chapters.
303+ #
304+ # Moreover, the `is_original` field is **not** present from the youtube
305+ # response which would force the following code to verify the title
306+ # for chapters which is the behavior we want.
307+ songs_to_download = [{'title' : song_name , 'is_original' : not verify_name }]
308+
296309 # If the chapters are present, we will have to iterate and extract each chapter
297310 if chapters and not args .ignore_chapters :
298311 logger .info ("The song has chapters in it." ,
@@ -302,12 +315,15 @@ def main(args):
302315 for chapter in chapters :
303316 songs_to_download .append (chapter )
304317
305- logger .debug (songs_to_download )
318+ logger .debug ("songs to download: " , str ( songs_to_download ) )
306319 for song in songs_to_download :
307320 song_title = song .get ("title" , yt_title )
308321 start_time = song .get ("start_time" , None )
309322 end_time = song .get ("end_time" , None )
310323
324+ is_original = song .get ("is_original" , False )
325+ logger .debug ("is original: " , str (is_original ))
326+
311327 if "title" in song .keys ():
312328 logger .debug ("Has the attribute" )
313329 # Update the song_metadata with the name of the chapter
@@ -318,7 +334,7 @@ def main(args):
318334 # NOTE: Check if skip meta is passed, we don't need to
319335 # extract the new title.
320336 song_metadata = utility .get_new_title (song_metadata ) if \
321- not ( args .keep_chapter_name and args .skip_meta ) else song_metadata
337+ ( not args .keep_chapter_name and not args .skip_meta and not is_original ) else song_metadata
322338
323339 # Pass the song for post processing
324340 try :
@@ -369,7 +385,8 @@ def post_processing(
369385 logger .debug (stream )
370386 # Try to convert the song
371387 try :
372- conv_name = convert (path , passed_format , start_time , end_time )
388+ conv_name = convert (path , passed_format , start_time ,
389+ end_time , args .dont_transcode )
373390 except ConvertError as convert_error :
374391 logger .critical ('ERROR: {}' .format (convert_error ))
375392 return
@@ -414,6 +431,16 @@ def post_processing(
414431 add_song_to_archive (
415432 stream = stream , youtube_link = link ) if is_download_archive else None
416433
434+ # If no metadata was selected, just do a dry cleanup and skip the
435+ # song
436+ if track_selected is None :
437+ if dir .dry_cleanup (conv_name , song_name ):
438+ logger .info ("Done" )
439+ elif not args .ignore_errors or args .on_meta_error == 'exit' :
440+ logger .critical (
441+ ". Pass `--ignore-errors` or `on-meta-error` to ignore this." )
442+ return
443+
417444 if dir .cleanup ([track_selected ], 0 , passed_format , remove_cached = False ):
418445 logger .info ("Done" )
419446
@@ -484,12 +511,12 @@ def pre_checks(args):
484511 "Song Name is required. Check 'ytmdl --help' for help." )
485512
486513
487- def extract_song_name (args ) -> str :
514+ def extract_song_name (args ) -> Tuple [ str , bool ] :
488515 """Extract the name of the song from the given args"""
489516 logger .debug (args .SONG_NAME )
490517
491518 if args .SONG_NAME :
492- return " " .join (args .SONG_NAME )
519+ return " " .join (args .SONG_NAME ), False
493520
494521 # If song name is not passed then try to extract
495522 # the title of the song using the URL.
@@ -501,7 +528,7 @@ def extract_song_name(args) -> str:
501528 if not args .ignore_errors :
502529 logger .critical ("Wasn't able to extract song data." ,
503530 "Use `--ignore-errors` to ignore this error" )
504- return
531+ return None , False
505532
506533 # Ask the user if they want to go with the extracted
507534 # title or if they would like to change it.
@@ -511,8 +538,9 @@ def extract_song_name(args) -> str:
511538 # passed.
512539 if not args .title_as_name and not args .skip_meta and verify_title :
513540 song_name = utility .get_new_title (song_name )
541+ verify_title = False
514542
515- return song_name
543+ return song_name , verify_title
516544
517545
518546def extract_data ():
0 commit comments