diff options
author | Jackson Taylor <jackson@jacksontaylor.xyz> | 2021-11-08 18:07:55 -0500 |
---|---|---|
committer | Jackson Taylor <jackson@jacksontaylor.xyz> | 2022-04-05 16:51:51 -0400 |
commit | 74192947c3772d44398a2d25aa3e7b3460ee8625 (patch) | |
tree | e60324c019e0cedc42ac90f0704c65e1fb809ea8 /jamos | |
parent | ef09547257f90ac8d0fea2870d515d5d43b859eb (diff) |
Merge sort script and jamos
I have had a script to organize files into their folders based on user
input. I didn't want to lose these functions so I merged the two into
the jamos script
Diffstat (limited to 'jamos')
-rwxr-xr-x | jamos | 112 |
1 files changed, 112 insertions, 0 deletions
@@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +import os +from os.path import isfile, join +import readline +import youtube_dl + +# MUSIC_DIRECTORY = "~/Music" +MUSIC_DIRECTORY = "./music" + +COMMANDS = ['extra', 'extension', 'stuff', 'errors', + 'email', 'foobar', 'foo'] +FILES = [] +DIRECTORIES = [] + +# TODO: Pull via command line args +def get_playlist_url(): + # return "https://music.youtube.com/watch?v=Enm0XL7xx_E&feature=share" # Deer Tick + # return "https://music.youtube.com/watch?v=hJLb0zPBzkE&feature=share" # You Worry Me + return "https://music.youtube.com/playlist?list=OLAK5uy_lHnMUbm8pKsyMTRQNCrjM2v4CPvIJUWq0&feature=share" # Button the busker + + +def download_song(song_url): + """ + Download a song using youtube url and song title + """ + + ydl_opts = { + 'format': 'bestaudio/best', + 'postprocessors': [ + {'key': 'FFmpegExtractAudio','preferredcodec': 'mp3', + 'preferredquality': '192', + }, + {'key': 'FFmpegMetadata'}, + ], + 'write-info-json': True + } + + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + info_dict = ydl.extract_info(song_url, download=True) + + print(info_dict['artist']) + + +def sort_stuff(): + # read in all the files and directories to move + get_all_files() + + # setup tab completion + readline.parse_and_bind("tab: complete") + readline.set_completer(complete) + + in_directory = False + + # loop over all the files left and + print(len(FILES)) + for f in FILES: + in_directory = False + while not in_directory: + print(f) + directory = input('Enter directory: ') + if directory in DIRECTORIES: + move_file(directory, f) + in_directory = True + if directory == "refresh": + get_directories() + + +def complete(text, state): + for cmd in DIRECTORIES: + if cmd.startswith(text): + if not state: + return cmd + else: + state -= 1 + + +def get_all_files(): + files = os.listdir() + global FILES + global DIRECTORIES + + for f in files: + if os.path.isfile(f): + FILES.append(f) + elif os.path.isdir(f): + DIRECTORIES.append(f) + else: + raise Exception("File wasn't a file or directory! " + f) + FILES.sort() + + +def get_directories(): + files = os.listdir() + global DIRECTORIES + + for f in files: + if os.path.isdir(f): + DIRECTORIES.append(f) + + +def move_file(d, f): + # print("directory " + d + " file: " + f) + print(d + "/" + f) + os.rename(f, (d + "/" + f)) + + +if __name__ == "__main__": + # Get the playlist url from youtube music + playlist_url = get_playlist_url() + + download_song(playlist_url) + |