PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 37ms app.codeStats 0ms

/examples/videx/vreverse.py

http://echo-nest-remix.googlecode.com/
Python | 48 lines | 37 code | 3 blank | 8 comment | 0 complexity | 1746dfbe7ca589cae67ca32524e1925c MD5 | raw file
 1#!/usr/bin/env python
 2# encoding: utf-8
 3"""
 4vreverse.py
 5
 6Created by Ben Lacker on 2009-06-19.
 7Copyright (c) 2009 __MyCompanyName__. All rights reserved.
 8"""
 9
10import sys
11import os
12
13from echonest import video
14
15usage = """
16Usage: 
17    python vreverse.py <beats|tatums> <inputFilename> <outputFilename>
18
19Example:
20    python vreverse.py beats YouCanCallMeAl.mpg AlMeCallCanYou.mpg
21"""
22
23
24def main(toReverse, inputFilename, outputFilename):
25    if inputFilename.startswith("http://"):
26        av = video.loadavfromyoutube(inputFilename)
27    else:
28        av = video.loadav(inputFilename)
29    if toReverse == 'tatums':
30        chunks = av.audio.analysis.tatums
31    elif toReverse == 'beats':
32        chunks = av.audio.analysis.beats
33    chunks.reverse()
34    out = video.getpieces(av, chunks)
35    out.save(outputFilename)
36
37if __name__ == '__main__':
38    try :
39        toReverse = sys.argv[1]
40        inputFilename = sys.argv[2]
41        outputFilename = sys.argv[3]
42    except :
43        print usage
44        sys.exit(-1)
45    if not toReverse in ["beats", "tatums"]:
46        print usage
47        sys.exit(-1)
48    main(toReverse, inputFilename, outputFilename)