Mercurial > vixm
changeset 30:860c891de6bb master
Remove lots of xmms-related code & get ready to make the whole program a
standalone player
author | Josef "Jeff" Sipek <jeffpc@josefsipek.net> |
---|---|
date | Fri, 03 Nov 2006 22:49:09 -0500 |
parents | e40bdeee5e14 |
children | 4fba4ccab723 |
files | run vixm/control.py vixm/player.py vixm/song.py vixm/ui.py |
diffstat | 5 files changed, 80 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/run Mon Sep 04 21:34:27 2006 -0400 +++ b/run Fri Nov 03 22:49:09 2006 -0500 @@ -6,5 +6,5 @@ from vixm import ui -ui.run() +ui.run("list.m3u")
--- a/vixm/control.py Mon Sep 04 21:34:27 2006 -0400 +++ b/vixm/control.py Fri Nov 03 22:49:09 2006 -0500 @@ -15,7 +15,7 @@ - quit Quits the program. The optional '!' forces the termination regardless of any unsaved work""" - ui.shutdown = True + ui.play.shutdown = True def cmd_number(ui, start, stop, args): """[range]n [playlistid] @@ -46,7 +46,7 @@ return s = ui.lists[playlist.LIST_DEFAULT][id] - print "Enqueuing song: %s (%s)" % (s["title"], util.strtime(s["time"])) + print "Enqueuing song: %s (%s)" % (str(s), util.strtime(s["time"])) ui.lists[playlist.LIST_PRIO].enqueue(s) def cmd_dequeue(ui, start, stop, args): @@ -65,7 +65,7 @@ for i in range(start-1, stop): s = l[start-1] - print "Dequeuing song: %s (%s)" % (s["title"], + print "Dequeuing song: %s (%s)" % (str(s), util.strtime(s["time"])) l.dequeue(s) @@ -119,7 +119,7 @@ if number: pfx = "%d. " % (i,) - print "%s%s (%s)" % (pfx, s["title"], + print "%s%s (%s)" % (pfx, str(s), util.strtime(s["time"])) i += 1 @@ -161,7 +161,7 @@ pos = xmms.control.get_playlist_pos() current = ui.lists[playlist.LIST_DEFAULT][pos] - print "%d. %s (%s/%s)" % (pos+1, current["title"], + print "%d. %s (%s/%s)" % (pos+1, str(current), util.strtime(xmms.control.get_output_time()), util.strtime(current["time"]))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vixm/player.py Fri Nov 03 22:49:09 2006 -0500 @@ -0,0 +1,15 @@ +import time +from threading import Thread + +class playerThread(Thread): + def __init__(self, lists): + Thread.__init__(self) + + self.shutdown = False + + self.lists = lists + + def run(self): + while not self.shutdown: + time.sleep(0.5) +
--- a/vixm/song.py Mon Sep 04 21:34:27 2006 -0400 +++ b/vixm/song.py Fri Nov 03 22:49:09 2006 -0500 @@ -6,14 +6,46 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. -import xmms +import ID3 class song(dict): - def __init__(self, pos): - self["file"] = xmms.control.get_playlist_file(pos) - self["time"] = xmms.control.get_playlist_time(pos) + def __init__(self, filename, pos): + id3 = ID3.ID3(filename) + + self["file"] = filename + + try: + self["album"] = id3["ALBUM"] + except KeyError: + self["album"] = "unknown" + + try: + self["artist"] = id3["ARTIST"] + except KeyError: + self["artist"] = "unknown" + + try: + self["title"] = id3["TITLE"] + except KeyError: + print "%s doesn't have a title!..using filename" % (filename,) + self["title"] = filename + + try: + self["year"] = id3["YEAR"] + except KeyError: + self["year"] = "unknown" + + try: + self["genre"] = id3["GENRE"] + except KeyError: + self["genre"] = "unknown" + + self["time"] = 0 self["pos"] = pos - self["title"] = xmms.control.get_playlist_title(pos) def __str__(self): - return self["title"] + return "%s - %s" % (self["artist"], self["title"]) + + def play(self): + # play the actual song + pass
--- a/vixm/ui.py Mon Sep 04 21:34:27 2006 -0400 +++ b/vixm/ui.py Fri Nov 03 22:49:09 2006 -0500 @@ -10,9 +10,9 @@ from threading import Thread import xmms -import playlist, song, util, control +import playlist, song, util, control, player -def run(): +def run(filename): """ this is where we start execution """ # first, let's create the two playlists @@ -24,17 +24,27 @@ # read in the info for all the songs in XMMS's playlist print "Loading songs from XMMS's playlist..." songs = [] - listlength = xmms.control.get_playlist_length() - for i in range(0,listlength): - s = song.song(i) + idx = 0 + for l in open(filename, "r").readlines(): + if l[0] == "#": + continue + + s = song.song(l[:-1], idx) lists[playlist.LIST_DEFAULT].enqueue(s) + + idx += 1 + print "Instanciating player thread..." + play = player.playerThread(lists) + play.start() + print "Instanciating ui thread..." - ui = uiThread(lists) + ui = uiThread(play, lists) ui.start() last = None - while not ui.shutdown: + while not play.shutdown: + """ # check which song we are playing now pos = xmms.control.get_playlist_pos() current = lists[playlist.LIST_DEFAULT][pos] @@ -57,7 +67,7 @@ print "WTF is going on?!" # update last played song - last = current + last = current""" # sleep time.sleep(0.5) @@ -65,11 +75,11 @@ class uiThread(Thread): """ This is the main ui thread class, it does all the magic necessary to have a vi-like interface """ - def __init__(self, lists): + def __init__(self, play, lists): Thread.__init__(self) + self.play = play self.lists = lists - self.shutdown = False # commad list: # quit 'q[!]' @@ -227,7 +237,7 @@ print "%d. %s" % (idx, str(song)) def run(self): - while not self.shutdown: + while not self.play.shutdown: tmp = sys.stdin.readline().strip() if tmp.startswith("/"):