-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
30 lines (24 loc) · 1.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import argparse
from songs import get_songs, extract_details
from matches import matches
from playlist import extract_id_from_uri
import json
def get_args():
parser = argparse.ArgumentParser(description='Use a query string to search a list of spotify playlists')
parser.add_argument('--playlist', "-p", help="spotify playlist URI", required=True, action="append")
parser.add_argument('--query', "-q", help="query string", required=True)
parser.add_argument('--verbose', "-v", help="verbose output", action="store_false", default=False)
return parser.parse_args()
def build_url(uri):
return "https://open.spotify.com/playlist/" + extract_id_from_uri(uri)
def run():
args = get_args()
urls = [build_url(uri) for uri in args.playlist]
songs = [song for url in urls for song in get_songs(url)]
matched_songs = matches(args.query, songs)
if args.verbose:
print(json.dumps(matched_songs))
else:
print(json.dumps([extract_details(song) for song in matched_songs]))
if __name__ == "__main__":
run()