From 3b444c3b40659c2d6a94b465fd2fbeaecee37452 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Wed, 30 Mar 2011 06:20:45 +0200 Subject: play: use basename only for the title part of the tag --- README | 10 ++++------ play.py | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README b/README index 27fbcd6..b372a7d 100644 --- a/README +++ b/README @@ -15,14 +15,12 @@ Usage: Miscellaneous: In order for either mp3info (ID3) or ogginfo to work, both - corresponding python modules have to be installed. Quickest - support for MP3 tags can be added by getting 'ID3.py' from the - id3-py project: http://id3-py.sourceforge.net or by installing - the (much more popular) 'pyid3lib' package provided by your OS - distribution. + corresponding python modules have to be installed. Play can + use 'id3-py' or 'pyid3lib' for MP3 tags, and 'pyvorbis' for + OGG tags. A playlist can contain URLs, but the playlist itself will have - to be local. For mpeg streaming splay is recommended. + to be local. For mpeg streaming use splay or mplayer. It is also possible to pipe a playlist to play, as stdin will be reopened on startup unless it is attached to a tty. diff --git a/play.py b/play.py index 8f38cda..64b1b6f 100755 --- a/play.py +++ b/play.py @@ -1121,15 +1121,17 @@ class PlaylistWindow(TagListWindow): def get_tag(pathname): if re.compile("^http://").match(pathname) or not os.path.exists(pathname): return pathname + tags = {} - # FIXME: use magic instead of file extensions to identify OGGs and MP3s + tagb = "N/A - " + os.path.basename(pathname) + if re.compile(".*\.ogg$", re.I).match(pathname): try: import ogg.vorbis vf = ogg.vorbis.VorbisFile(pathname) vc = vf.comment() tags = vc.as_dict() - except: return os.path.basename(pathname) + except: return tagb elif re.compile(".*\.mp3$", re.I).match(pathname): try: import ID3 @@ -1146,27 +1148,27 @@ def get_tag(pathname): for tag, fid in tagtoframeid.items(): try: index = vc.index(fid) - tags[tag] = (vc[index]['text'],) + tags[tag] = (vc[index]["text"],) except ValueError: - tags[tag] = ("N/A",) + if tag in ["ARTIST", "TITLE"]: tags[tag] = ("",) + else: tags[tag] = ("N/A",) except: pass - except: return os.path.basename(pathname) + except: return tagb else: - return os.path.basename(pathname) + return tagb artist = tags.get("ARTIST", [""])[0] title = tags.get("TITLE", [""])[0] - tag = os.path.basename(pathname) try: import codecs if artist and title: - tag = codecs.latin_1_encode(artist)[0] + " - " + codecs.latin_1_encode(title)[0] + tagb = codecs.latin_1_encode(artist)[0] + " - " + codecs.latin_1_encode(title)[0] elif artist: - tag = artist + tagb = artist elif title: - tag = title - return codecs.latin_1_encode(tag)[0] - except: return tag + tagb = title + return codecs.latin_1_encode(tagb)[0] + except: return tagb # ------------------------------------------ class Player: -- cgit v1.2.3