Exemplo n.º 1
0
    def __init__(self, libclass, libtags):
        MockTag.__init__(self)

        self.__tags = CaselessDict()
        tags = self.__tags

        tags.update(self.load(libtags['~filename'])[0])
        tags['__tag_read'] = u'QuodLibet'

        self.library = libclass
        self.remove = partial(libclass.delete, track=libtags)
        self._libtags = libtags

        for key, value in libtags.items():
            if not value and not isinstance(value, (int, long)):
                continue
            if key in mapping:
                tags.update(mapping[key](value))
            else:
                if not isinstance(value, unicode):  #Strings
                    try:
                        value = unicode(value, 'utf8', 'replace')
                    except (TypeError, ValueError):
                        try:
                            value = unicode(value)  #Usually numbers
                        except:
                            traceback.print_exc()
                            continue
                tags[key] = [value]
        del (tags['~filename'])

        self.filepath = libtags['~filename']
        self.set_attrs(ATTRIBUTES, self.__tags)
        self.update_tag_list()
Exemplo n.º 2
0
    def __init__(self, libclass, libtags):
        MockTag.__init__(self)

        self.__tags = CaselessDict()
        tags = self.__tags

        tags.update(self.load(libtags['~filename'])[0])
        tags['__tag_read'] = u'QuodLibet'

        self.library = libclass
        self.remove = partial(libclass.delete, track=libtags)
        self._libtags = libtags

        for key, value in libtags.items():
            if not value and not isinstance(value, (int, long)):
                continue
            if key in mapping:
                tags.update(mapping[key](value))
            else:
                if not isinstance(value, unicode): #Strings
                    try: value = unicode(value, 'utf8', 'replace')
                    except (TypeError, ValueError):
                        try: value = unicode(value) #Usually numbers
                        except:
                            traceback.print_exc()
                            continue
                tags[key] = [value]
        del(tags['~filename'])

        self.filepath = libtags['~filename']
        self.set_attrs(ATTRIBUTES, self.__tags)
        self.update_tag_list()
Exemplo n.º 3
0
def parse_album_page(page, album_source, url=None):
    cursor = Cursor(page, album_source)
    if url:
        cursor.output = CaselessDict({'CurrentUrl': url})
        cursor.album = CaselessDict({'CurrentUrl': url})

    cursor.parse_page()
    info = convert_dict(cursor.album)
    if hasattr(cursor.tracks, 'items'):
        tracks = []
        for field, values in cursor.tracks.items():
            values = convert_value(values)
            if tracks:
                for d, v in zip(tracks, values):
                    d[field] = v
            else:
                tracks = [{field: v} for v in values]
    else:
        tracks = [_f for _f in map(convert_dict, cursor.tracks) if _f]
    return (info, tracks)
Exemplo n.º 4
0
 def __init__(self, text, source_lines):
     self.text = text
     self.all_lines = [z + ' ' for z in text.split('\n')] + [' ']
     self.all_lowered = [z.lower() for z in self.all_lines]
     self.lineno = 0
     self.charno = 0
     self.cache = ''
     self.source = source_lines
     self.debug = False
     self._field = ''
     self.tracks = []
     self.album = CaselessDict()
     self.num_loop = 0
     self.output = self.album
     self.stop = False
     self.track_fields = set(['track'])
Exemplo n.º 5
0
class Tag(MockTag):
    """Use as base for all tag classes."""
    mapping = audioinfo.mapping.get('puddletag', {})
    revmapping = audioinfo.revmapping.get('puddletag', {})
    IMAGETAGS = ()

    def __init__(self, libclass, libtags):
        MockTag.__init__(self)

        self.__tags = CaselessDict()
        tags = self.__tags

        tags.update(self.load(libtags['~filename'])[0])
        tags['__tag_read'] = u'QuodLibet'

        self.library = libclass
        self.remove = partial(libclass.delete, track=libtags)
        self._libtags = libtags

        for key, value in libtags.items():
            if not value and not isinstance(value, (int, long)):
                continue
            if key in mapping:
                tags.update(mapping[key](value))
            else:
                if not isinstance(value, unicode):  #Strings
                    try:
                        value = unicode(value, 'utf8', 'replace')
                    except (TypeError, ValueError):
                        try:
                            value = unicode(value)  #Usually numbers
                        except:
                            traceback.print_exc()
                            continue
                tags[key] = [value]
        del (tags['~filename'])

        self.filepath = libtags['~filename']
        self.set_attrs(ATTRIBUTES, self.__tags)
        self.update_tag_list()

    def get_filepath(self):
        return MockTag.get_filepath(self)

    def set_filepath(self, val):
        self.__tags.update(MockTag.set_filepath(self, val))

    filepath = property(get_filepath, set_filepath)

    images = property(lambda s: [], lambda s: [])

    def __contains__(self, key):
        if self.revmapping:
            key = self.revmapping.get(key, key)
        return key in self.__tags

    def __deepcopy__(self, memo=None):
        tag = Tag(self._libclass, self._libtags)
        tag.update(deepcopy(self.__tags))
        return tag

    @del_deco
    def __delitem__(self, key):
        if key.startswith('__'):
            return
        else:
            if key == 'track':
                del (self._libtags['tracknumber'])
                del (self.__tags['track'])
            else:
                if key in self._libtags:
                    del (self._libtags[key])
                    del (self.__tags[key])

    @getdeco
    def __getitem__(self, key):
        return self.__tags[key]

    @setdeco
    def __setitem__(self, key, value):
        if key.startswith('__'):
            if key == '__total':
                set_total(self, value)
            elif key in fn_hash:
                setattr(self, fn_hash[key], value)
        elif isempty(value):
            if key in self:
                del (self[key])
            else:
                return
        else:
            self.__tags[key] = unicode_list(value)

    def delete(self):
        raise NotImplementedError

    @keys_deco
    def keys(self):
        return self.__tags.keys()

    def save(self, justrename=False):
        libtags = self._libtags
        tags = self.__tags
        newartist = to_string(tags.get('artist', [u'']))
        oldartist = libtags.get('artist', u'')

        newalbum = to_string(tags.get('album', [u'']))
        oldalbum = libtags.get('album', u'')

        self._libtags.update(self._tolibformat())
        self._libtags.write()
        if (newartist != oldartist) or (newalbum != oldalbum):
            self.library.update(oldartist, oldalbum, libtags)
        self.library.edited = True
        self.update_tag_list()

    def _tolibformat(self):
        libtags = {}
        tags = stringtags(self.__tags).items()
        for key, value in tags:
            if key in revmapping:
                libtags.update(revmapping[key](value))
            elif key.startswith('__'):
                continue
            else:
                libtags[key] = value

        libtags['~filename'] = self.filepath
        return libtags

    def update_tag_list(self):
        l = tags_in_file(self.filepath)
        if l:
            self.__tags['__tag'] = u'QuodLibet, ' + u', '.join(l)
        else:
            self.__tags['__tag'] = u'QuodLibet'
Exemplo n.º 6
0
class Tag(MockTag):
    """Use as base for all tag classes."""
    mapping = audioinfo.mapping.get('puddletag', {})
    revmapping = audioinfo.revmapping.get('puddletag', {})
    IMAGETAGS = ()

    def __init__(self, libclass, libtags):
        MockTag.__init__(self)

        self.__tags = CaselessDict()
        tags = self.__tags

        tags.update(self.load(libtags['~filename'])[0])
        tags['__tag_read'] = u'QuodLibet'

        self.library = libclass
        self.remove = partial(libclass.delete, track=libtags)
        self._libtags = libtags

        for key, value in libtags.items():
            if not value and not isinstance(value, (int, long)):
                continue
            if key in mapping:
                tags.update(mapping[key](value))
            else:
                if not isinstance(value, unicode): #Strings
                    try: value = unicode(value, 'utf8', 'replace')
                    except (TypeError, ValueError):
                        try: value = unicode(value) #Usually numbers
                        except:
                            traceback.print_exc()
                            continue
                tags[key] = [value]
        del(tags['~filename'])

        self.filepath = libtags['~filename']
        self.set_attrs(ATTRIBUTES, self.__tags)
        self.update_tag_list()

    def get_filepath(self):
        return MockTag.get_filepath(self)

    def set_filepath(self,  val):
        self.__tags.update(MockTag.set_filepath(self, val))

    filepath = property(get_filepath, set_filepath)

    images = property(lambda s: [], lambda s: [])

    def __contains__(self, key):
        if self.revmapping:
            key = self.revmapping.get(key, key)
        return key in self.__tags

    def __deepcopy__(self, memo=None):
        tag = Tag(self._libclass, self._libtags)
        tag.update(deepcopy(self.__tags))
        return tag

    @del_deco
    def __delitem__(self, key):
        if key.startswith('__'):
            return
        else:
            if key == 'track':
                del(self._libtags['tracknumber'])
                del(self.__tags['track'])
            else:
                if key in self._libtags:
                    del(self._libtags[key])
                    del(self.__tags[key])

    @getdeco
    def __getitem__(self, key):
        return self.__tags[key]

    @setdeco
    def __setitem__(self, key, value):
        if key.startswith('__'):
            if key == '__total':
                set_total(self, value)
            elif key in fn_hash:
                setattr(self, fn_hash[key], value)
        elif isempty(value):
            if key in self:
                del(self[key])
            else:
                return
        else:
            self.__tags[key] = unicode_list(value)

    def delete(self):
        raise NotImplementedError

    @keys_deco
    def keys(self):
        return self.__tags.keys()

    def save(self, justrename = False):
        libtags = self._libtags
        tags = self.__tags
        newartist = to_string(tags.get('artist', [u'']))
        oldartist = libtags.get('artist', u'')

        newalbum = to_string(tags.get('album', [u'']))
        oldalbum = libtags.get('album', u'')

        self._libtags.update(self._tolibformat())
        self._libtags.write()
        if (newartist != oldartist) or (newalbum != oldalbum):
            self.library.update(oldartist, oldalbum, libtags)
        self.library.edited = True
        self.update_tag_list()

    def _tolibformat(self):
        libtags = {}
        tags = stringtags(self.__tags).items()
        for key, value in tags:
            if key in revmapping:
                libtags.update(revmapping[key](value))
            elif key.startswith('__'):
                continue
            else:
                libtags[key] = value

        libtags['~filename'] = self.filepath
        return libtags

    def update_tag_list(self):
        l = tags_in_file(self.filepath)
        if l:
            self.__tags['__tag'] = u'QuodLibet, ' + u', '.join(l)
        else:
            self.__tags['__tag'] = u'QuodLibet'