X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Ftrack.py;h=5b25bd33527bad5e94ef2eb043990a1eb4dc755b;hb=0264d2f9cea7c5e60ac71234ee4f7de78b338850;hp=52d1ce2197ddd7e15d45144efbd9e9502cb492dc;hpb=611f98994247324793027cae02d77e5a8efd0f42;p=mpd-sima.git diff --git a/sima/lib/track.py b/sima/lib/track.py index 52d1ce2..5b25bd3 100644 --- a/sima/lib/track.py +++ b/sima/lib/track.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009, 2010, 2011, 2013 Jack Kaliko +# Copyright (c) 2009, 2010, 2011, 2013, 2014 Jack Kaliko # Copyright (c) 2009 J. Alexander Treuman (Tag collapse method) # Copyright (c) 2008 Rick van Hattem # @@ -23,24 +23,26 @@ import time +from .meta import Artist -class Track(object): +class Track: """ Track object. - Instanciate with mpd replies. + Instanciate with Player replies. """ - def __init__(self, file=None, time=0, pos=0, **kwargs): + def __init__(self, file=None, time=0, pos=-1, **kwargs): self.title = self.artist = self.album = self.albumartist = '' - self._pos = pos - self.empty = False + self.musicbrainz_artistid = None + self.pos = int(pos) + self._empty = False self._file = file if not kwargs: - self.empty = True - self.time = time + self._empty = True + self._time = time self.__dict__.update(**kwargs) - self.tags_to_collapse = list(['artist', 'album', 'title', 'date', - 'genre', 'albumartist']) + self.tags_to_collapse = ['artist', 'album', 'title', 'date', + 'genre', 'albumartist'] # have tags been collapsed? self.collapse_tags_bool = False self.collapsed_tags = list() @@ -60,12 +62,6 @@ class Track(object): self.collapsed_tags.append(tag) self.__dict__.update({tag: ', '.join(set(value))}) - def get_filename(self): - """return filename""" - if not self.file: - return None - return self.file - def __repr__(self): return '%s(artist="%s", album="%s", title="%s", filename="%s")' % ( self.__class__.__name__, @@ -103,12 +99,7 @@ class Track(object): return hash(self) != hash(other) def __bool__(self): - return not self.empty - - @property - def pos(self): - """return position of track in the playlist""" - return int(self._pos) + return not self._empty @property def file(self): @@ -135,13 +126,12 @@ class Track(object): fmt = '%M:%S' return time.strftime(fmt, temps) - -def main(): - pass - -# Script starts here -if __name__ == '__main__': - main() + def get_artist(self): + """Get artist object from track""" + name = self.artist + if self.albumartist and self.albumartist != 'Various Artists': + name = self.albumartist + return Artist(name=name, mbid=self.musicbrainz_artistid) # VIM MODLINE # vim: ai ts=4 sw=4 sts=4 expandtab