Пример #1
0
 def run(self):
     while(self.__running):
         current = mpc.sysCmd('mpc current')
         if(len(current.strip()) == 0):
             next = self.__player.next()
             if next is None:
                 self.__running = False
             else:
                 url = Player.api.get_stream_url(next)
                 mpc.telnetCmd('clear')
                 mpc.telnetCmd('add ' + str(url))
                 mpc.telnetCmd('play')    
         time.sleep(3)
     mpc.log('Stopping Update Thread')
Пример #2
0
 def previous(self):
     index = 0
     if Player.playlist is None:
         return None
         
     for track in Player.playlist:
         if(track.get('id') != Player.current):
             index+=1;
         else:
             break
             
     index-=1
     mpc.log('Calculated previous track index: ' + str(index) + ' of ' + str(len(Player.playlist)))
     if index >= 0:
         Player.current = Player.playlist[index].get('id')
     else:
         Player.current = Player.playlist[0].get('id')
     return Player.current
Пример #3
0
 def next(self):
     index = 0
     if Player.playlist is None:
         return None
         
     for track in Player.playlist:
         if(track.get('id') != Player.current):
             index+=1
         else:
             break
             
     index+=1            
     mpc.log('Calculated next track index: ' + str(index) + ' of ' + str(len(Player.playlist)))
     if index < len(Player.playlist):
         Player.current = Player.playlist[index].get('id')
     else:
         Player.current = None
     return Player.current
Пример #4
0
def setCredentials():
    login = request.forms.login
    password = request.forms.password
    
    global api
    global loggedIn
    result = api.login(login, password, perform_upload_auth=False)
    if(result):
        loggedIn = True
        mpc.log('Google login successful')
        loadGoogleData()
        config.set('Google', 'login', login)
        config.set('Google', 'password', password)
    else:
        mpc.log('Google login failed')
        config.set('Google', 'login', login)
        config.set('Google', 'password', '')
        
    with open(googleConfigFile, 'wb') as configfile:
        config.write(configfile)
        
    return str(result)    
Пример #5
0
def loadGoogleData():
    mpc.log('Google login successful')
    songDict = api.get_all_songs()
    mpc.log('Loaded ' + str(len(songDict)) + ' songs')
    
    for song in songDict:
        album = str(unicode(song['album']).encode('utf-8'))
        albumArtUrl = str(unicode(song.get('albumArtUrl','')).encode('utf-8'))
        artist = str(unicode(song.get('artist','')).encode('utf-8'))
        title = str(unicode(song.get('title','')).encode('utf-8'))
        year = str(song['year'])
        id = song['id']
		
        #build album data
        albumDict = albumStore.get(album, dict())
        albumDict.update({'album':album})
        albumDict.update({'year':year})
        albumDict.update({'albumArtUrl':albumArtUrl})
        albumDict.update({'artist':artist})
        albumStore.update({album:albumDict})	
        #add tracks
        tracks = albumDict.get('tracks', [])
        trackDict = createTrackDict(song)
        tracks.append(trackDict)
        tracks.sort(key=operator.itemgetter('track'))
        albumDict.update({'tracks':tracks})
        albumDict.update({'totalTracks':len(tracks)})
        
        #build artist data
        artistDict = artistStore.get(artist, dict())
        artistDict.update({'artist':artist})
        artistTracksList = artistDict.get('tracks', [])
        artistTrackDict = createTrackDict(song)
        artistTracksList.append(artistTrackDict)
        artistTracksList.sort(key=operator.itemgetter('name'))
        artistDict.update({'tracks':artistTracksList})
        artistDict.update({'totalTracks':len(artistTracksList)})
        artistStore.update({artist:artistDict})
   
    convertDictToSortedList(albumStore, albumList)
    convertDictToSortedList(artistStore, artistList)
   	
    mpc.log('Finished Google API initalization')
    return True