-
-
Save bonelifer/3e3eae40ac58c64d51920a7fdf26045b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import csv | |
import beets.library | |
from termcolor import colored | |
import beets.ui | |
LIBRARYDB = '/home/MYUSER/.config/beets/library.db' | |
EXPORTIFY_CSV = './spotify.csv' | |
def main(): | |
with open(EXPORTIFY_CSV, 'r') as csv_file: | |
csv_reader = csv.reader(csv_file) | |
output = '' | |
for line in csv_reader: | |
artist = line[0] | |
album = line[1] | |
[strippedartist, strippedalbum] = strip_dashes(artist), strip_dashes(album) | |
if exists_in_library(strippedartist, strippedalbum): | |
output += colored(f'{artist} ::: {album}', 'green', force_color=True) | |
else: | |
output += colored(f'{artist} ::: {album}', 'red', force_color=True) | |
output += '\n' | |
print(output) | |
# Not sure why queries don't work if they have dashes. Fuck it we remove the dash and everything after it | |
def strip_dashes(string): | |
return string.split('-')[0] | |
def add_quotes(string): | |
if "'" in string and '"' in string: | |
print("I literally can't process a CSV line if it has both single and double quotes. Sorry!") | |
exit(1) | |
elif "'" in string: | |
return '"' + string + '"' | |
else: | |
return "'" + string + "'" | |
def exists_in_library(artist, album): | |
lib = beets.library.Library(LIBRARYDB) | |
[artist, album] = add_quotes(artist), add_quotes(album) | |
res = lib.albums(f'albumartist:{artist} album:{album}') | |
if res.get(): | |
return True | |
else: | |
return False | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment