Changeset 87:615396b21744


Ignore:
Timestamp:
Sep 2, 2009, 10:09:34 AM (11 years ago)
Author:
David Fraser <davidf@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@88
Message:

Improved login, added sampleswap-sourced public domain sound, handle aiff conversion, don't parse parameters in config files

Location:
data/sounds
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • data/sounds/get-sources

    r85 r87  
    1313    import pymedia.muxer as muxer
    1414except ImportError, e:
    15     logging.warning("pymedia not installed, will use transcode to convert files: %s", e)
     15    logging.info("pymedia not installed, will use transcode to convert files: %s", e)
    1616    acodec = None
    1717    muxer = None
     
    2121    if filename is None:
    2222        filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sources.txt")
    23     source_config = ConfigParser.SafeConfigParser()
     23    source_config = ConfigParser.RawConfigParser()
    2424    source_config.read(filename)
    2525    for section in source_config.sections():
    2626        yield section, dict(source_config.items(section))
    2727
    28 def convert_audio(source_filename, target_filename, source_ext, target_ext):
     28def convert_audio(source_filename, target_filename, source_format, target_format):
    2929    """converts audio between files"""
     30    logging.info("Converting %s (format %s) to %s (format %s)", source_filename, source_format, target_filename, target_format)
    3031    if not acodec or not muxer:
    31         logging.info("Could not convert audio files: will try use transcode")
    32         subprocess.call(["transcode", "-y", "null,%s" % target_ext, "-i", source_filename, "-o", target_filename])
     32        logging.debug("pymedia not present: will try use transcode")
     33        if source_format == "aiff":
     34            source_format = "mplayer"
     35        options = ["-y", "null,%s" % target_format, "-i", source_filename, "-o", target_filename]
     36        if source_format not in ["wav", "mp3", "ogg"]:
     37            options += ["-x", "null,%s" % source_format]
     38        subprocess.call(["transcode"] + options)
    3339        return
    34     logging.info("Converting %s (format %s) to %s (format %s)", source_filename, source_ext, target_filename, target_ext)
    3540    source_file = open(source_filename, 'rb')
    3641    s = source_file.read(8192)
    37     dm = muxer.Demuxer(source_ext)
     42    dm = muxer.Demuxer(source_format)
    3843    frames = dm.parse(s)
    3944    print dm.hasHeader(), dm.getInfo()
     
    4449   
    4550    params = {
    46     'id': acodec.getCodecId(target_ext),
     51    'id': acodec.getCodecId(target_format),
    4752    'bitrate': r.bitrate,
    4853    'sample_rate': r.sample_rate,
    49     'ext': target_ext,
     54    'ext': target_format,
    5055    'channels': r.channels }
    5156    enc = acodec.Encoder(params)
     
    7075        url = options.pop("url")
    7176        params = urllib.urlencode(options)
     77        logging.info("Logging in to %s", url)
    7278        f = opener.open(url, params)
    7379        contents = f.read()
     
    7783
    7884if __name__ == "__main__":
     85    logging.getLogger().setLevel(logging.INFO)
    7986    target_dir = os.path.dirname(os.path.abspath(__file__))
    80     web_config = ConfigParser.SafeConfigParser()
     87    web_config = ConfigParser.RawConfigParser()
    8188    web_config.read(os.path.join(target_dir, "web.ini"))
    8289    opener = handle_logins(web_config)
     
    9198        if not os.path.exists(download_filename):
    9299            url = source_options["url"]
     100            logging.info("Downloading %s to %s", url, download_filename)
    93101            contents = opener.open(url).read()
    94102            if "<html" in contents[:1024].lower():
     
    100108        filename = os.path.join(target_dir, filename)
    101109        if not os.path.exists(filename):
    102             convert_audio(download_filename, filename, orig_ext, target_ext)
     110            orig_format = source_options.get("originalformat", orig_ext)
     111            target_format = source_options.get("targetformat", target_ext)
     112            convert_audio(download_filename, filename, orig_format, target_format)
    103113
  • data/sounds/sources.txt

    r85 r87  
    1515OriginalExtension: wav
    1616
     17[chicken3.ogg]
     18URL: http://www.sampleswap.org/SAMPLESWAP/SFX%20AND%20UNUSUAL%20SOUNDS/sfx%20cheesy%20lo-fi/Chicken.aif
     19Source: http://www.sampleswap.org/filebrowser-new.php?d=SFX+AND+UNUSUAL+SOUNDS%2Fsfx+cheesy+lo-fi%2F
     20License: Public Domain
     21OriginalExtension: aiff
     22
  • data/sounds/web.ini.sample

    r86 r87  
    66login: login
    77
     8[sampleswap]
     9url: http://www.sampleswap.org/login.php
     10username: username
     11password: password
     12autologin: on
     13login: Log In
    814
     15
Note: See TracChangeset for help on using the changeset viewer.