source: other-projects/mirex/grand-challenge/generate-jamendo-dataset/scripts-2015/get-evened-out-json.py@ 30011

Last change on this file since 30011 was 30011, checked in by davidb, 9 years ago

Tweak to the JSON filename used

  • Property svn:executable set to *
File size: 1.3 KB
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-10000-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 repository browser.