root/other-projects/mirex/grand-challenge/generate-jamendo-dataset/scripts-2015/get-evened-out-json.py @ 30007

Revision 30007, 1.3 KB (checked in by davidb, 5 years ago)

Gets Jamendo JSON (stats and musicinfo) based on a file-based ID list

  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2
3import json
4import os
5import os.path
6import urllib
7import sys
8
9
10base_url = "http://api.jamendo.com/v3.0/tracks/"
11base_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
15base_url_args = base_url_args + "&include=musicinfo+stats"
16
17
18argc = len(sys.argv)
19
20input_file  = sys.argv[1] if (argc==2) or (argc==3)  else "jamendo-evened-out-dataset-trackids.json"
21output_dir = sys.argv[2] if argc==3 else "download-json-evened-out"
22
23
24if not os.path.isdir(output_dir):
25    print "Creating directory: " + output_dir
26    os.mkdir(output_dir)
27
28evened_out_json_data=open(input_file).read()
29evened_out_jamendo_ids=json.loads(evened_out_json_data)
30
31for 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 browser.