summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Taylor <jackson@jacksontaylor.xyz>2021-11-09 21:18:26 -0500
committerJackson Taylor <jackson@jacksontaylor.xyz>2022-04-05 16:51:55 -0400
commitc383aa2c3ff3cf2f0de69937023c6cecc8bdc1f3 (patch)
tree0180d00830d9d4027205bc9ce9fd66e39a72bb9c
parent2a0d5283b1de4e4a2a77e672bb0121923db9568f (diff)
Move files once done tagging
-rwxr-xr-xjamos43
1 files changed, 26 insertions, 17 deletions
diff --git a/jamos b/jamos
index 573dc1d..7e80212 100755
--- a/jamos
+++ b/jamos
@@ -99,19 +99,16 @@ def complete(text, state):
state -= 1
-def get_all_files():
- files = os.listdir()
- global FILES
- global DIRECTORIES
+def get_all_files(directory):
+ things = glob.glob(os.path.join(directory, '*.mp3'))
- 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()
+ files = []
+
+ for thing in things:
+ if os.path.isfile(thing):
+ files.append(thing)
+
+ return files
def get_directories():
@@ -123,15 +120,27 @@ def get_directories():
DIRECTORIES.append(f)
-def move_file(d, f):
- # print("directory " + d + " file: " + f)
- print(d + "/" + f)
- os.rename(f, (d + "/" + f))
+def move_file(file, metadata):
+ p = os.path.join(MUSIC_DIRECTORY, metadata['artist'].replace(' ', '_').lower(), metadata['album'].replace(' ', '_').lower())
+ Path(p).mkdir( parents=True, exist_ok=True )
+
+ os.rename(file, os.path.join(p, metadata['artist'].replace(' ', '_').lower() + '_' + metadata['title'].replace(' ', '_').lower() + '.mp3'))
+
if __name__ == "__main__":
- # Get the playlist url from youtube music
+ # Get the playlist url from the command line
playlist_url = get_playlist_url()
+ # Download the songs
download_song(playlist_url)
+ files = get_all_files(MUSIC_DIRECTORY)
+
+ for f in files:
+ json_data = None
+ with open(f.replace('.mp3', '.info.json')) as json_file:
+ json_data = json.load(json_file)
+ write_metadata_to_song_file(f, json_data)
+ move_file(f, json_data)
+