tag-music.py (1051B)
1 #!/usr/bin/env python3 2 3 import music_tag 4 from os.path import expanduser 5 import os 6 import json 7 import sys 8 import requests 9 10 home = expanduser("~") 11 xdg_data_home = os.environ["XDG_DATA_HOME"] 12 xdg_cache_home = os.environ["XDG_CACHE_HOME"] 13 art_file = xdg_cache_home + "/art.jpg" 14 15 inputFile = sys.argv[1] 16 genre = sys.argv[2] 17 albumArt = sys.argv[3] 18 19 cleanName = inputFile.replace(" - Topic", "") 20 21 split = cleanName.replace(".m4a", "").split(" -- ") 22 23 artist = split[1] 24 title = split[0] 25 album = split[2] 26 27 file = music_tag.load_file(inputFile) 28 file["title"] = title 29 file["artist"] = artist 30 file["album"] = album 31 file["genre"] = genre 32 33 if not albumArt == "file.jpg": 34 r = requests.get(albumArt) 35 with open(art_file, "wb")as out: 36 out.write(r.content) 37 38 with open(art_file, "rb") as img: 39 file["artwork"] = img.read() 40 41 file.save() 42 43 metadata = xdg_data_home + "/regexghost/script-data/songs-metadata.csv" 44 f = open(metadata, "a") 45 f.write(inputFile.replace(" -- ", " - ") + "|" + title + "|" + artist + "|" + album + "|" + albumArt + "|" + genre + "\n") 46 f.close() 47 48