Last change
on this file was 30009, checked in by davidb, 9 years ago |
Fixed a minor typo in variable name
|
-
Property svn:executable
set to
*
|
File size:
1.3 KB
|
Line | |
---|
1 | #!/usr/bin/python
|
---|
2 |
|
---|
3 | import os
|
---|
4 | import os.path
|
---|
5 |
|
---|
6 | import json
|
---|
7 | import sys
|
---|
8 |
|
---|
9 | argc = len(sys.argv)
|
---|
10 |
|
---|
11 | input_dir = sys.argv[1] if (argc==2) or (argc==3) else "download-json-all"
|
---|
12 | output_dir = sys.argv[2] if argc==3 else "download-audio"
|
---|
13 |
|
---|
14 | if not os.path.isdir(output_dir):
|
---|
15 | print "Creating directory: " + output_dir
|
---|
16 | os.mkdir(output_dir)
|
---|
17 |
|
---|
18 |
|
---|
19 | json_files = [ jf for jf in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir,jf)) ]
|
---|
20 |
|
---|
21 | for jf in json_files:
|
---|
22 | json_filename = os.path.join(input_dir,jf)
|
---|
23 | json_data=open(json_filename).read()
|
---|
24 | data = json.loads(json_data)
|
---|
25 |
|
---|
26 | for rec in data[u'results']:
|
---|
27 |
|
---|
28 | id = int(rec[u'id'])
|
---|
29 | prefix = id//1000
|
---|
30 |
|
---|
31 | output_prefix_dir = os.path.join(output_dir,str(prefix));
|
---|
32 | if not os.path.isdir(output_prefix_dir):
|
---|
33 | print "Creating " + output_prefix_dir
|
---|
34 | os.mkdir(output_prefix_dir)
|
---|
35 |
|
---|
36 | output_filename = os.path.join(output_prefix_dir, str(id) + ".mp3")
|
---|
37 |
|
---|
38 | if not os.path.isfile(output_filename):
|
---|
39 | audio_download_url = rec[u'audio']
|
---|
40 |
|
---|
41 | cmd = "wget -O " + output_filename + " \"" + audio_download_url + "\""
|
---|
42 |
|
---|
43 | print "Downloading:" +cmd
|
---|
44 | os.system(cmd)
|
---|
45 | else:
|
---|
46 | print "Already downloaded: " + output_filename + " => skipping"
|
---|
47 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.