-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerVLC.py
199 lines (165 loc) · 6.38 KB
/
playerVLC.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import vlc
import pandora
import webbrowser
import urllib
import re
import tempfile
import os
CachePath = tempfile.gettempdir()
class volcanoPlayer(object):
def __init__( self ):
self.pandora = pandora.Pandora()
self.curStation = ""
self.curSong = -1
self.playing = False
self.skip = {'live':False, 'remix':False, 'edit':False, 'ban':False}
self.die = False
self.settings = {"username":"", "password":""}
self.skinName = "Default"
self.song = None
self.songinfo = []
self.displaysongs = []
self.songCount = 0
self.songChangeCallBack = None
self.curVolume = 75
self.player = vlc.MediaPlayer()
def setAutoSkip( self, sType, sBool ):
self.skip[sType] = sBool
def setChangeCallBack( self, callback ):
self.songChangeCallBack = callback
def auth( self, user, passwd):
self.settings['username'] = user
self.settings['password'] = passwd
try:
self.pandora.connect(self.settings['username'], self.settings['password'])
except:
pass
def setVolume( self, newVol ):
self.player.audio_set_volume( newVol )
self.curVolume = newVol
def playSong( self ):
self.playing = True
self.player.play()
def pauseSong( self ):
self.playing = False
self.player.pause()
def skipSong( self ):
self.nextSong()
def setStation( self, station ):
self.curStation = pandora.Station(self.pandora, station)
def getStations( self ):
return self.pandora.get_stations()
def getStation( self ):
return self.curStation
def getCurSongInfo( self ):
return self.songinfo[self.curSong]
def getSongInfo( self ):
return self.songinfo
def getStationFromName( self, name):
stations = self.getStations()
for station in stations:
if station['stationName'] == name:
return station
def getSongDuration( self ):
print "Getting Song duration"
seconds = self.player.get_length() / 1000.0
print "Starting Seconds %s"%seconds
mins = 0
while seconds >= 60:
seconds -= 60
mins += 1
print "Minutes %s Seconds %s"%(mins, seconds)
return mins, seconds
def getSongRating( self ):
return self.songinfo[self.curSong]['rating']
def search( self, searchstring ):
return self.pandora.search(searchstring)
def createStation( self, station ):
self.pandora.add_station_by_music_id(station)
def deleteStation( self, station ):
pandora.Station(self.pandora, station).delete()
def renameStation( self, station, name ):
pandora.Station(self.pandora, station).rename(name)
def banSong( self ):
info = self.songinfo[self.curSong]
info['object'].rate('ban')
def tiredSong( self ):
info = self.songinfo[self.curSong]
info['object'].set_tired()
def loveSong( self ):
info = self.songinfo[self.curSong]
info['object'].rate('love')
def clearSongs( self ):
self.song = None
self.songCount = 0
self.curSong = -1
self.songinfo = []
self.displaysongs = []
def addSongs( self ):
playlist = self.curStation.get_playlist()
for song in playlist:
info = { "title" : song.title, \
"artist" : song.artist, \
"album" : song.album, \
"thumbnail" : song.artRadio, \
"url" : str(song.audioUrl), \
"rating" : song.rating, \
"object" : song, \
"caching" : False, \
"localpath" : False
}
#Apply Filters
if (re.search('\[.*mix.*\]', info['title'].lower()) or re.search('\(.*mix.*\)', info['title'].lower())) and self.skip['remix']:
if self.skip['ban']:
info['object'].rate('ban')
elif (re.search('\[.*live.*\]', info['title'].lower()) or re.search('\(.*live.*\)', info['title'].lower())) and self.skip['live']:
if self.skip['ban']:
info['object'].rate('ban')
elif (re.search('\[.*edit.*\]', info['title'].lower()) or re.search('\(.*edit.*\)', info['title'].lower())) and self.skip['edit']:
if self.skip['ban']:
info['object'].rate('ban')
else:
#If it isn't filtered out, add it to play list.
self.songinfo.append(info)
if not self.song:
self.startPlaying()
def cacheSong( self, songNumber ):
info = self.songinfo[songNumber]
if not info["caching"]:
print "Caching song %s"%info['title']
info["caching"] = True
urllib.urlretrieve(str(info['url']), os.path.join(CachePath, "%s.mp3"%info['title']))
info["localpath"] = os.path.join(CachePath, "%s.mp3"%info['title'])
def startPlaying( self ):
self.nextSong()
def setAudioFormat( self, fmt ):
self.pandora.set_audio_format("%sQuality"%fmt.lower())
def nextSong( self, event=False ):
self.curSong += 1
info = self.songinfo[self.curSong]
if self.player.is_playing():
self.player.stop()
self.player = vlc.MediaPlayer()
self.player.audio_set_volume( self.curVolume )
self.event_manager = self.player.event_manager()
self.event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, self.nextSong)
info = self.songinfo[self.curSong]
self.displaysongs.append(info)
self.song = info['title']
if info['localpath']:
print "Playing song from cache"
self.player.set_media(vlc.Media(info['localpath']))
else:
print "Playing song live from URL"
self.player.set_media(vlc.Media(info['url']))
self.playing = True
self.player.play()
self.songChangeCallBack()
self.player.audio_set_delay( 2500 )
print self.player.audio_get_delay()
if self.curSong >= len(self.songinfo)-1:
self.addSongs()
self.songCount += 1
if self.songCount >= 15:
self.songCount = 0
self.auth(self.settings['username'], self.settings['password'])