def select_laps_to_render(videos, lap_comparison_mode=False, select_sessions=False): if select_sessions: return select_sessions_to_render(videos) laps = {} for video in videos: for lap in video.matched_laps: print lap['lap'] key = float(lap['lap']) laps[key] = lap lap["render"] = False keys = laps.keys() keys.sort() title = 'Select laps to render' if lap_comparison_mode: title = "Select at most 2 laps to render in side-by-side mode" picker = Picker(title=title, options=keys) picker.start() opts = picker.getSelected() if lap_comparison_mode: opts = opts[:2] for lap in opts: laps[lap]['render'] = True
def select_sessions_to_render(videos): s_videos = {} for video in videos: key = str(video) s_videos[key] = video for lap in video.matched_laps: lap["render"] = False keys = s_videos.keys() keys.sort() title = 'Select sessions to render' picker = Picker(title=title, options=keys) picker.window_width = 150 picker.window_height = 30 picker.start() opts = picker.getSelected() for videoname in opts: video = s_videos[videoname] for lap in video.matched_laps: lap['render'] = True
def download_singles(self): """ Downloads songs based on youtube search. Takes a string as an input. """ cm = common() try: os.chdir("singles") except: os.mkdir("singles") os.chdir("singles") Console().print( Columns([ Panel( "\ntip:\n [bold white]* give the name of song and the artist for better search results)\n * you could paste the youtube video url itself if you're looking for a specific song.[/bold white]\n" ) ])) s = input("\nEnter the song name: ") print(f"\nLoading search results for {s}...\n") s = s.replace(" ", "+") # Get top 7 video URLs video_url = cm.get_url(s) j = 1 names = [] for i in video_url: if len(video_url) == 0: print( "\nThere were no results :(\nmaybe try checking the spelling of the song\n" ) quit() try: t = pafy.new(i) names.append(f"{j} - {t.title} ({t.duration})") j += 1 except: j += 1 # print(traceback.format_exc()) # time.sleep(2) continue picker = Picker( names, "Select your choice using arrow keys or press q to quit", indicator=" => ") picker.register_custom_handler(ord('q'), lambda picker: exit()) picker.register_custom_handler(ord('Q'), lambda picker: exit()) op, c = picker.start() Console().print( Columns([ Panel( f"\nDownload size: [green]{int((pafy.new(video_url[c]).getbestaudio().get_filesize()/1048576)*100)/100} MB[/green]\n" ) ])) print() print("\nWould you like an mp3 or flac conversion?\n") Console().rule( "[bold]**** Here's a quick comparison on both codec ****[bold]", style="black", align="center") print("\n") table = Table(show_header=True, header_style="bold cyan") table.add_column("Avaliable Codec") table.add_column("Bit-rate") table.add_column("File Size") table.add_column("Remarks") table.add_row("mp3", "320kbps (default)", "~7.3MB for 3min song", "Standard codec with normal experience") table.add_row() table.add_row( "flac", "usually >800kbps (1713kbps while testing, 5x of mp3)", "~39MB for 3min song", "Takes fair amount of disk space but gives amazing experience") Console().print(table) Console().rule( "\n[bold]Note: this step [red]does not use internet[/red] [bold]\n", style="black", align="center") print('\nIf you are confused on what to select, select mp3 (default)') z = input("\tEnter\n\t1/flac/f - flac\n\tany key - mp3 : ") cm.download_song(video_url[c], '', '', z) print("\n\n") Console().print( Columns([ Panel( f"\n Your song is downloaded in \"[bold cyan]/musicDL downloads/singles[/bold cyan]\" folder on desktop \n" ) ])) print("\n\n") time.sleep(3) picker = Picker( ["Open the song directory", "Open the song itself"], "Select your choice using arrow keys or press q to quit", indicator=" => ") picker.register_custom_handler(ord('q'), lambda picker: 'qq') picker.register_custom_handler(ord('Q'), lambda picker: 'QQ') _, op = picker.start() if op == 0: if sys.platform == 'win32' or os.name == 'nt': os.startfile(".") elif sys.platform == 'linux' or os.name == 'posix': subprocess.call(['xdg-open', '.']) elif op == 1: file = pafy.new(video_url[c - 1]).title a, t = get_artist_title(file) if file + ".mp3" in os.listdir(): if sys.platform == 'win32' or os.name == 'nt': os.startfile(file + ".mp3") elif sys.platform == 'linux' or os.name == 'posix': subprocess.call(['xdg-open', file + ".mp3"]) elif t + " - " + a + ".mp3" in os.listdir(): if sys.platform == 'win32' or os.name == 'nt': os.startfile(t + " - " + a + ".mp3") elif sys.platform == 'linux' or os.name == 'posix': subprocess.call(['xdg-open', t + " - " + a + ".mp3"]) else: files = glob.glob("./*") song = max(files, key=os.path.getctime) if sys.platform == 'win32' or os.name == 'nt': os.startfile(song) elif sys.platform == 'linux' or os.name == 'posix': subprocess.call(['xdg-open', song]) else: return