Ejemplo n.º 1
0
 def playlistinfo(self):
     with mpd.connect(self.host, self.port) as client:
         info = client.playlistinfo()
     info = [item for item in info if item]
     for item in info:
         normalize(item, {'title' : ('file',), 'artist' : tuple()})
         item['duration'] = fmt_time(item.get('time', 0))
     return info
Ejemplo n.º 2
0
 def search(self, type, what):
     self.last_search = (type, what)
     with mpd.connect(self.host, self.port) as client:
         results = client.search(type, what)
     results = [x for x in results if 'file' in x and x['file'].strip() != '']
     for result in results:
         normalize(result, {'title' : ('file',)})
     self.last_search_results = results
     return results
Ejemplo n.º 3
0
 def list(self, uri):
     with mpd.connect(self.host, self.port) as client:
         listing = client.lsinfo(uri)
     for d in listing:
         if 'directory' in d:
             d['dirname'] = d['directory'].split('/')[-1]
         if 'file' in d:
             normalize(d, {'title' : ('file',)})
     return listing
Ejemplo n.º 4
0
def connect_mpd(mpd):
    # Connect with MPD
    #------------------------------------------------
    global debug
    connected = False
    retry_count = 3
    i = 1
    while connected == False:
        connected = True
        try:
            mpd.connect(TEST_MPD_HOST, TEST_MPD_PORT)
        except SocketError as e:
            connected = False
        if connected == False:
            if debug: print "Couldn't connect. Retrying"
            i = i + 1
            if i > retry_count:
                return (9)
            time.sleep(3)
    if debug: print("Connected to MPD-Server")
    if debug: print "MPD-Version: %s" % mpd.mpd_version
    return (0)
Ejemplo n.º 5
0
 def status(self):
     with mpd.connect(self.host, self.port) as client:
         status = client.status()
         current_song = client.currentsong()
     try:
         a,b = status.pop('time')
         status['time'] = a.seconds
         status['duration'] = b.seconds
         status['title'] = current_song['title']
         status['artist'] = current_song['artist']
     except:
         pass
     return status
Ejemplo n.º 6
0
 def info(self):
     with mpd.connect(self.host, self.port) as client:
         info = client.lsinfo()
     return info
Ejemplo n.º 7
0
 def seek(self, song, time):
     with mpd.connect(self.host, self.port) as client:
         client.seek(song, time)
Ejemplo n.º 8
0
 def next(self): 
     with mpd.connect(self.host, self.port) as client:
         client.next()
Ejemplo n.º 9
0
 def load(self, song):
     with mpd.connect(self.host, self.port) as client:
         client.load(song)
Ejemplo n.º 10
0
 def delete(self, song):
     with mpd.connect(self.host, self.port) as client:
         client.delete(song)
Ejemplo n.º 11
0
 def clear(self):
     with mpd.connect(self.host, self.port) as client:
         client.clear()
Ejemplo n.º 12
0
 def stop(self): 
     with mpd.connect(self.host, self.port) as client:
         client.stop()
Ejemplo n.º 13
0
 def listplaylists(self):
     with mpd.connect(self.host, self.port) as client:
         info = client.listplaylists()
     return info
Ejemplo n.º 14
0
			for name, scrobbles in album_stats.items():
				artists[artist_name].albums[name].scrobbles = scrobbles
		except KeyError:
			print artist_name + " no longer in library"

def normalize_stats(artists):
	for artist in artists.values():
		for album in artist.albums.values():
			num_tracks = len(album.songs)
			album.times_listened = album.scrobbles / float(num_tracks)
		
network = pylast.LastFMNetwork(api_key = API_KEY, api_secret = API_SECRET)

mpd = mpd.MPDClient()
mpd.connect("127.0.0.1", 6600)
songs = mpd.listallinfo()

artists = create_artist_list(songs, DIRECTORY, SUB_DIRECTORY, True)
genres = create_genre_list(artists)

load_stats(artists, "stats.bin")

#fetch_album_stats(artists, network)

try:
	#fetch_listener_stats(artists, network)
	pass
except httplib.BadStatusLine:
	print "retrying"
Ejemplo n.º 15
0
 def play(self): 
     with mpd.connect(self.host, self.port) as client:
         client.play()
Ejemplo n.º 16
0
 def pause(self): 
     with mpd.connect(self.host, self.port) as client:
         client.pause(1)
Ejemplo n.º 17
0
 def setvol(self,x): 
     with mpd.connect(self.host, self.port) as client:
         client.setvol(x)
Ejemplo n.º 18
0
 def currentsong(self):
     with mpd.connect(self.host, self.port) as client:
         current_song = client.currentsong()
     normalize(current_song, {'title' : ('file',), 'artist' : tuple()})
     return current_song
Ejemplo n.º 19
0
 def add(self, *songs):
     with mpd.connect(self.host, self.port) as client:
         for song in songs:
             client.add(song)
Ejemplo n.º 20
0
				self.redirect(url)
			except:
				self.redirect("http://img.schredder.me/200x200")

class PlaylistHandler(tornado.web.RequestHandler):
	def get(self):
		pl = self.get_arguments("pl")
		if len(pl) > 0:
			self.write(json.dumps(mpd.listplaylist(pl[0])))

		self.write(json.dumps(mpd.listplaylists()))

ArtistArtCache = {}
AlbumArtCache = {}
mpd = mpd.MPDClient()
application = tornado.web.Application([
	(r"/artist", ArtistHandler),
	(r"/artistArt", ArtistArtHandler),
	(r"/albums", AlbumHandler),
	(r"/albumArt", AlbumArtHandler),
	(r"/albums/title", TitleHandler),
	(r"/playlist", PlaylistHandler),
	(r"/", tornado.web.RedirectHandler, {"url": "/index.html"}),
	(r"/music/(.*)", tornado.web.StaticFileHandler, {"path": MUSIC_PATH}),
	(r"/(.*)", tornado.web.StaticFileHandler, {"path": "static/"})
])

if __name__ == "__main__":
	mpd.connect("localhost", 6600)
	application.listen(8888)
	tornado.ioloop.IOLoop.instance().start()
Ejemplo n.º 21
0
 def previous(self): 
     with mpd.connect(self.host, self.port) as client:
         client.previous()