summarylogtreecommitdiffstats
path: root/echoplay
blob: 90a4e83c28db341eb4cd54aeb7e41f02b72d5c54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
import commands,sys,urllib,pprint,os
from pyechonest import artist,config
config.ECHO_NEST_API_KEY="OHKKQGH5SBDHBWRQI"

usage = """
Usage:

    echoplay <options> ARTIST

OPTIONS:

	-p Play stream of artists music

	-d Download artists music

	-v Download videos of artist

        -s Find similar artists

"""

def main(argument, band):
    alist = artist.search_artists(band)
    if (len(alist) > 0):
        print band
        if argument=='-d':
            for audio in alist[0].audio():
                url=audio['url']
                i = url.rfind('/')
                file = url[i+1:]
                print "Downloading File:"
                print url, "->", file
                urllib.urlretrieve(url, file)
        if argument=='-p':
            for audio in alist[0].audio():
                url=audio['url']
                print "playing: ",band," - ",audio['title']
                print os.system("gst-launch-0.10 playbin2 uri=" + url + ">/dev/null")
        if argument=='-v':
            for video in alist[0].video():
                url=video['url']
                print "Downloading video....",url
                output = commands.getoutput("youtube-dl -t " + url)
                print output
        if argument=='-s':
            print 'Artists similar to', alist[0].name
	    for sim in alist[0].similar():
                print " ", sim.name
        else:
	    print "\nERROR: Option not recognised, please use a valid option"
	    print usage
    else:
	print "Sorry, artist not found"

if __name__ == '__main__':
    import sys
    try :
        argument = sys.argv[1]
        band = sys.argv[2]
    except :
        print usage
        sys.exit(-1)
    main(argument,band)