summaryrefslogtreecommitdiff
path: root/jamos
diff options
context:
space:
mode:
authorJackson Taylor <jackson@jacksontaylor.xyz>2021-11-09 21:17:54 -0500
committerJackson Taylor <jackson@jacksontaylor.xyz>2022-04-05 16:51:54 -0400
commit2a0d5283b1de4e4a2a77e672bb0121923db9568f (patch)
tree16538725161e54ff5ddd39707939cf016c9d479d /jamos
parent14828c7dc6ac429364467534abc70e1cfa6c1281 (diff)
Download and tag music files
Diffstat (limited to 'jamos')
-rwxr-xr-xjamos57
1 files changed, 41 insertions, 16 deletions
diff --git a/jamos b/jamos
index 9fa639e..573dc1d 100755
--- a/jamos
+++ b/jamos
@@ -1,45 +1,70 @@
#!/usr/bin/env python3
+import datetime
+import glob
+import json
+import music_tag
import os
from os.path import isfile, join
+from pathlib import Path
import readline
import youtube_dl
-# MUSIC_DIRECTORY = "~/Music"
-MUSIC_DIRECTORY = "./music"
+
+# MUSIC_DIRECTORY = "~/Music/"
+MUSIC_DIRECTORY = "./music/"
COMMANDS = ['extra', 'extension', 'stuff', 'errors',
'email', 'foobar', 'foo']
FILES = []
DIRECTORIES = []
+AUDIO_OPTIONS = {
+ 'format': 'bestaudio/best',
+ 'cookiefile': 'cookies.txt',
+ 'outtmpl': MUSIC_DIRECTORY + '%(title)s.%(ext)s',
+ 'postprocessors': [
+ {'key': 'FFmpegExtractAudio','preferredcodec': 'mp3',
+ 'preferredquality': '192',
+ },
+ {'key': 'FFmpegMetadata'},
+ ],
+ 'writeinfojson': True
+ }
+
+ytdl = youtube_dl.YoutubeDL(AUDIO_OPTIONS)
+
+
# 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
+ # return "https://music.youtube.com/playlist?list=OLAK5uy_lHnMUbm8pKsyMTRQNCrjM2v4CPvIJUWq0&feature=share" # Button the busker
+ # return "https://music.youtube.com/playlist?list=PLC-Ro2Hd9eWm1ZPIAsxFcfg2JoOlTO0Oj&feature=share" # broken hearts and dirty windows volume 2
+ # return "https://music.youtube.com/playlist?list=PLC-Ro2Hd9eWkX4hDamDvyB5G-vxLTEBKl&feature=share" # dev playlist
+ return "https://music.youtube.com/playlist?list=PLC-Ro2Hd9eWkoElrTZIcCVCcdxBQzojsZ&feature=share" # missing playlist
def download_song(song_url):
"""
Download a song using youtube url and song title
"""
+ return ytdl.extract_info(song_url, download=True)
- 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)
+def write_metadata_to_song_file(file, metadata):
+ f = music_tag.load_file(file)
+
+ f['name'] = metadata['title']
+ f['artist'] = metadata['artist']
+ f['album'] = metadata['album']
+ f['year'] = format_youtube_date(metadata['release_date'])
- print(info_dict['artist'])
+ f.save()
+def format_youtube_date(date):
+ fmt = "%Y%m%d"
+ d = datetime.datetime.strptime(date, fmt)
+ return d.year
def sort_stuff():
# read in all the files and directories to move