def go_pafy(raw_song, meta_tags): """Parse track from YouTube.""" if misc.is_youtube(raw_song): track_info = pafy.new(raw_song) else: track_url = generate_youtube_url(raw_song, meta_tags) if track_url is None: track_info = None else: track_info = pafy.new(track_url) return track_info
def grab_single(raw_song, number=None): """Logic behind downloading a song.""" if number: islist = True else: islist = False content = go_pafy(raw_song) if content is None: return if misc.is_youtube(raw_song): raw_song = slugify(content.title).replace('-', ' ') # print '[number]. [artist] - [song]' if downloading from list # otherwise print '[artist] - [song]' print(get_youtube_title(content, number)) # generate file name of the song to download meta_tags = generate_metadata(raw_song) songname = content.title if meta_tags is not None: refined_songname = generate_songname(meta_tags) if not refined_songname == ' - ': songname = refined_songname file_name = misc.sanitize_title(songname) if not check_exists(file_name, raw_song, islist=islist): if download_song(file_name, content): print('') input_song = file_name + args.input_ext output_song = file_name + args.output_ext convert.song(input_song, output_song, args.folder, avconv=args.avconv, verbose=args.verbose) if not args.input_ext == args.output_ext: os.remove(os.path.join(args.folder, input_song)) if not args.no_metadata: metadata.embed(os.path.join(args.folder, output_song), meta_tags) else: print('No audio streams available')