예제 #1
0
def get_duration(f):
    mc = memcache.Client(['127.0.0.1:11211'], debug=0)
    key = escape_generic(f)
    d = mc.get(key)
    if d is not None:
        return d
    else:
        d = 0
    info = MediaInfo.parse(f)
    for track in info.tracks:
        if getattr(track, 'duration') is not None:
            d = track.duration
            break
    mc.set(key, d)
    return d
예제 #2
0
def get_duration(f):
    mc = memcache.Client(['127.0.0.1:11211'], debug=0)
    key = escape_generic(f)
    d = mc.get(key)
    if d is not None:
        return d
    else:
        d = 0
    info = MediaInfo.parse(f)
    for track in info.tracks:
        if getattr(track, 'duration') is not None:
            d = track.duration
            break
    mc.set(key, d)
    return d
예제 #3
0
def get_json(url, data):
    url = '%s?%s' % (url, urllib.urlencode(OrderedDict(sorted(data.items()))))
#    print url
    cache_dir = os.path.join(os.path.dirname(__file__), '..', 'resources', 'cache')
    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)
    fn = os.path.join(cache_dir, escape_generic(url))
    if os.path.exists(fn):
        with open(fn, "r") as f:
            return simplejson.loads(f.read())
    opener = urllib2.build_opener()
    opener.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)')]
    response = opener.open(url)
    data = response.read()
    if not os.path.exists(fn):
        with open(fn, "w") as f:
            f.write(data)
    data = simplejson.loads(data)
    return data
예제 #4
0
def get_json(url, data):
    url = '%s?%s' % (url, urllib.urlencode(OrderedDict(sorted(data.items()))))
    #    print url
    cache_dir = os.path.join(os.path.dirname(__file__), '..', 'resources',
                             'cache')
    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)
    fn = os.path.join(cache_dir, escape_generic(url))
    if os.path.exists(fn):
        with open(fn, "r") as f:
            return simplejson.loads(f.read())
    opener = urllib2.build_opener()
    opener.addheaders = [(
        'User-agent',
        'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)'
    )]
    response = opener.open(url)
    data = response.read()
    if not os.path.exists(fn):
        with open(fn, "w") as f:
            f.write(data)
    data = simplejson.loads(data)
    return data