Mercurial > rinkhals
annotate data/sounds/get-sources @ 85:782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
author | David Fraser <davidf@sjsoft.com> |
---|---|
date | Wed, 02 Sep 2009 09:33:55 +0000 |
parents | |
children | 615396b21744 |
rev | line source |
---|---|
85
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
2 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
3 """Script to fetch sources defined in sources.txt""" |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
4 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
5 import ConfigParser |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
6 import logging |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
7 import os |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
8 import subprocess |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
9 import urllib |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
10 import urllib2 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
11 try: |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
12 import pymedia.audio.acodec as acodec |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
13 import pymedia.muxer as muxer |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
14 except ImportError, e: |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
15 logging.warning("pymedia not installed, will use transcode to convert files: %s", e) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
16 acodec = None |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
17 muxer = None |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
18 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
19 def iter_sources(filename=None): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
20 """fetches a bunch of sound sources from the descriptions in the given filename""" |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
21 if filename is None: |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
22 filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sources.txt") |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
23 source_config = ConfigParser.SafeConfigParser() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
24 source_config.read(filename) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
25 for section in source_config.sections(): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
26 yield section, dict(source_config.items(section)) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
27 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
28 def convert_audio(source_filename, target_filename, source_ext, target_ext): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
29 """converts audio between files""" |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
30 if not acodec or not muxer: |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
31 logging.info("Could not convert audio files: will try use transcode") |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
32 subprocess.call(["transcode", "-y", "null,%s" % target_ext, "-i", source_filename, "-o", target_filename]) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
33 return |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
34 logging.info("Converting %s (format %s) to %s (format %s)", source_filename, source_ext, target_filename, target_ext) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
35 source_file = open(source_filename, 'rb') |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
36 s = source_file.read(8192) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
37 dm = muxer.Demuxer(source_ext) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
38 frames = dm.parse(s) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
39 print dm.hasHeader(), dm.getInfo() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
40 dec = acodec.Decoder(dm.streams[0]) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
41 frame = r[0] |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
42 r = dec.decode(frame[1]) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
43 print r.sample_rate, r.channels, r.bitrate, r.sample_length |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
44 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
45 params = { |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
46 'id': acodec.getCodecId(target_ext), |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
47 'bitrate': r.bitrate, |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
48 'sample_rate': r.sample_rate, |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
49 'ext': target_ext, |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
50 'channels': r.channels } |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
51 enc = acodec.Encoder(params) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
52 enc.setInfo(dec.getInfo()) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
53 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
54 target_file = open(target_filename, 'wb') |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
55 while len(s): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
56 frames = enc.encode(r.data) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
57 target_file.write(enc.mux(frames)) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
58 s = source_file.read(1024) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
59 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
60 r = dec.decode(s) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
61 target_file.write(enc.flush()) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
62 target_file.close() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
63 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
64 def handle_logins(config): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
65 """logs in to necessary sites and returns urllib2 opener with cookies set up""" |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
66 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
67 urllib2.install_opener(opener) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
68 for section in config.sections(): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
69 options = dict(config.items(section)) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
70 url = options.pop("url") |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
71 params = urllib.urlencode(options) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
72 f = opener.open(url, params) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
73 contents = f.read() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
74 f.close() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
75 # params = urllib.urlencode({'username': 'davidfraser', 'password': 'QwpCAlZe', 'autologin': 'on', 'login': 'login', 'redirect': '../index.php'}) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
76 return opener |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
77 |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
78 if __name__ == "__main__": |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
79 target_dir = os.path.dirname(os.path.abspath(__file__)) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
80 web_config = ConfigParser.SafeConfigParser() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
81 web_config.read(os.path.join(target_dir, "web.ini")) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
82 opener = handle_logins(web_config) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
83 for filename, source_options in iter_sources(os.path.join(target_dir, "sources.txt")): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
84 download_filename = filename |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
85 orig_ext = source_options.get("originalextension", None) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
86 if orig_ext: |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
87 target_name, target_ext = os.path.splitext(download_filename) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
88 download_filename = target_name + "." + orig_ext |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
89 target_ext = target_ext.lstrip(".").lower() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
90 download_filename = os.path.join(target_dir, download_filename) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
91 if not os.path.exists(download_filename): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
92 url = source_options["url"] |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
93 contents = opener.open(url).read() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
94 if "<html" in contents[:1024].lower(): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
95 logging.error("%s returned HTML rather than file contents", url) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
96 continue |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
97 f = open(download_filename, "wb") |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
98 f.write(contents) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
99 f.close() |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
100 filename = os.path.join(target_dir, filename) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
101 if not os.path.exists(filename): |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
102 convert_audio(download_filename, filename, orig_ext, target_ext) |
782e45d70ea8
Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
David Fraser <davidf@sjsoft.com>
parents:
diff
changeset
|
103 |