Last change
on this file since 30007 was 30007, checked in by davidb, 9 years ago |
Gets Jamendo JSON (stats and musicinfo) based on a file-based ID list
|
-
Property svn:executable
set to
*
|
File size:
1.3 KB
|
Rev | Line | |
---|
[30007] | 1 | #!/usr/bin/python
|
---|
| 2 |
|
---|
| 3 | import json
|
---|
| 4 | import os
|
---|
| 5 | import os.path
|
---|
| 6 | import urllib
|
---|
| 7 | import sys
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | base_url = "http://api.jamendo.com/v3.0/tracks/"
|
---|
| 11 | base_url_args = base_url + "?client_id=54cc3f68&format=jsonpretty&audioformat=mp32&audiodlformat=flac"
|
---|
| 12 |
|
---|
| 13 | # OK, there are also the include fields 'licenses' and 'lyrics' but for GCUX, there are currently considered unnecessary
|
---|
| 14 |
|
---|
| 15 | base_url_args = base_url_args + "&include=musicinfo+stats"
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | argc = len(sys.argv)
|
---|
| 19 |
|
---|
| 20 | input_file = sys.argv[1] if (argc==2) or (argc==3) else "jamendo-evened-out-dataset-trackids.json"
|
---|
| 21 | output_dir = sys.argv[2] if argc==3 else "download-json-evened-out"
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | if not os.path.isdir(output_dir):
|
---|
| 25 | print "Creating directory: " + output_dir
|
---|
| 26 | os.mkdir(output_dir)
|
---|
| 27 |
|
---|
| 28 | evened_out_json_data=open(input_file).read()
|
---|
| 29 | evened_out_jamendo_ids=json.loads(evened_out_json_data)
|
---|
| 30 |
|
---|
| 31 | for jid in evened_out_jamendo_ids:
|
---|
| 32 |
|
---|
| 33 | output_filename = os.path.join(output_dir ,jid + ".json")
|
---|
| 34 |
|
---|
| 35 | if os.path.isfile(output_filename):
|
---|
| 36 | print " Skipping Track ID " + jid + " as downloaded JSON file already exists"
|
---|
| 37 | continue
|
---|
| 38 |
|
---|
| 39 | download_url = base_url_args + "&id=" + jid
|
---|
| 40 | print "Downloading: " + download_url
|
---|
| 41 | download_url_handle = urllib.urlopen(download_url)
|
---|
| 42 |
|
---|
| 43 | json_data = download_url_handle.read()
|
---|
| 44 |
|
---|
| 45 | with open(output_filename, "w") as json_ofile:
|
---|
| 46 | json_ofile.write(json_data)
|
---|
| 47 | json_ofile.close()
|
---|
| 48 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.