Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some updates #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 33 additions & 8 deletions retrieve-identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
import struct
import urllib.parse, urllib.request
import json
import signal
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-s", "--skip", dest="skip", default=0,
help="Amount of lines to skip from the input file")
parser.add_argument("-i",
dest="input_filename",
default="spotify.csv",
help="Input file (CSV)")
parser.add_argument("-o",
dest="output_filename",
default="itunes.csv",
help="Output file (CSV)")

args = parser.parse_args()


def retrieve_itunes_identifier(title, artist):
Expand Down Expand Up @@ -34,22 +51,30 @@ def retrieve_itunes_identifier(title, artist):

itunes_identifiers = []

output_file = open(args.output_filename, 'w', encoding='utf-8')

def signal_handler(signal, frame):
output_file.close()
sys.exit(0)

with open('spotify.csv', encoding='utf-8') as playlist_file:
signal.signal(signal.SIGINT, signal_handler)

i = 0
skip = int(args.skip)
with open(args.input_filename, encoding='utf-8') as playlist_file:
playlist_reader = csv.reader(playlist_file)
next(playlist_reader)

for row in playlist_reader:
title, artist = row[1], row[2]
i += 1
if i < skip:
continue
itunes_identifier = retrieve_itunes_identifier(title, artist)

if itunes_identifier:
itunes_identifiers.append(itunes_identifier)
print("{} - {} => {}".format(title, artist, itunes_identifier))
output_file.write(str(itunes_identifier) + "\n")
print("{}. {} - {} => {}".format(i, title, artist, itunes_identifier))
else:
print("{} - {} => Not Found".format(title, artist))


with open('itunes.csv', 'w', encoding='utf-8') as output_file:
for itunes_identifier in itunes_identifiers:
output_file.write(str(itunes_identifier) + "\n")
print("{}. {} - {} => Not Found".format(i, title, artist))