示例#1
0
    def convertTrack(self, track, artist=None, album=None, convert=True):
        if artist is None:
            artist = track[-2]
        if album is None:
            album = track[-1]

        if convert:
            if track[4]:
                self.cursor.execute(u"SELECT DISTINCT BINARY name FROM composer WHERE id = BINARY %s", (track[4],))
                composer = self.cursor.fetchall()[0][0]
            else:
                composer = u""

            if track[5]:
                self.cursor.execute(u"SELECT DISTINCT BINARY name FROM genre WHERE id = BINARY %s", (track[5],))
                genre = self.cursor.fetchall()[0][0]
            else:
                genre = u""

            if track[7]:
                self.cursor.execute(u"SELECT DISTINCT BINARY name FROM year WHERE id = BINARY %s", (track[7],))
                year = self.cursor.fetchall()[0][0]
            else:
                year = u""
        else:
            composer = track[4]
            genre = track[5]
            year = track[7]

        filename = track[0][1:]
        temp = {
            "__filename": filename,
            "__folder": dirname(filename),
            "__created": audioinfo.strtime(track[2]),
            "__modified": audioinfo.strtime(track[3]),
            "album": album,
            "artist": artist,
            "composer": composer,
            "genre": genre,
            "title": track[6],
            "year": year,
            "comment": track[8],
            "track": unicode(track[9]),
            "discnumber": unicode(track[10]),
            "__bitrate": audioinfo.strbitrate(track[11] * 1000),
            "__length": audioinfo.strlength(track[12]),
            "__frequency": audioinfo.strfrequency(track[13]),
            "__size": unicode(track[14]),
            "___filetype": unicode(track[15]),
            "___sampler": unicode(track[16]),
            "bpm": unicode(track[17]),
            "___deviceid": unicode(track[18]),
            "__path": os.path.basename(filename),
            "__ext": os.path.splitext(filename)[1][1:],
            "__library": "amarok",
        }

        return self.applyToDict(self.applyToDict(temp, self.valuetostring), self.latinutf)
示例#2
0
    def convertTrack(self, track, artist=None, album=None, convert=True):
        if artist is None:
            artist = track[-2]
        if album is None:
            album = track[-1]

        if convert:
            if track[4]:
                self.cursor.execute(
                    u"SELECT DISTINCT BINARY name FROM composer WHERE id = BINARY %s",
                    (track[4], ))
                composer = self.cursor.fetchall()[0][0]
            else:
                composer = u""

            if track[5]:
                self.cursor.execute(
                    u"SELECT DISTINCT BINARY name FROM genre WHERE id = BINARY %s",
                    (track[5], ))
                genre = self.cursor.fetchall()[0][0]
            else:
                genre = u""

            if track[7]:
                self.cursor.execute(
                    u"SELECT DISTINCT BINARY name FROM year WHERE id = BINARY %s",
                    (track[7], ))
                year = self.cursor.fetchall()[0][0]
            else:
                year = u""
        else:
            composer = track[4]
            genre = track[5]
            year = track[7]

        filename = track[0][1:]
        temp = {
            '__filename': filename,
            '__folder': dirname(filename),
            '__created': audioinfo.strtime(track[2]),
            '__modified': audioinfo.strtime(track[3]),
            'album': album,
            'artist': artist,
            'composer': composer,
            'genre': genre,
            'title': track[6],
            'year': year,
            'comment': track[8],
            'track': unicode(track[9]),
            'discnumber': unicode(track[10]),
            '__bitrate': audioinfo.strbitrate(track[11] * 1000),
            '__length': audioinfo.strlength(track[12]),
            '__frequency': audioinfo.strfrequency(track[13]),
            '__size': unicode(track[14]),
            '___filetype': unicode(track[15]),
            '___sampler': unicode(track[16]),
            'bpm': unicode(track[17]),
            '___deviceid': unicode(track[18]),
            '__path': os.path.basename(filename),
            '__ext': os.path.splitext(filename)[1][1:],
            '__library': 'amarok'
        }

        return (self.applyToDict(self.applyToDict(temp, self.valuetostring),
                                 self.latinutf))
示例#3
0
    except UnicodeDecodeError:
        print u"UnicodeDecodeError on: ", filename
        pass

    if filename.startswith(u'file://'):
        filename = filename[len(u'file://'):]
        return {
            '__dirpath': path.dirname(filename),
            PATH: filename,
            FILENAME: path.basename(filename),
            "__ext": path.splitext(filename)[1][1:],
            "__dirname": path.basename(path.dirname(filename))
        }


getTime = lambda date: audioinfo.strtime(int(date))
getCreated = lambda created: {u'__created': getTime(created)}
getModified = lambda modified: {u'__modified': getTime(modified)}
getLength = lambda length: {u'__length': audioinfo.strlength(int(length))}
getBitRate = lambda bitrate: {u'__bitrate': bitrate + u' kb/s'}

CONVERSION = {
    u'title': u'title',
    u'genre': u'genre',
    u'artist': u'artist',
    u'album': u'album',
    u'track-number': u'track',
    u'duration': getLength,
    u'file-size': u'__size',
    u'location': getFilename,
    u'first-seen': getCreated,
示例#4
0
    filename = urllib.url2pathname(filename)
    try:
        filename = filename.encode('latin1').decode('utf8')
    except UnicodeDecodeError:
        print u"UnicodeDecodeError on: ", filename
        pass

    if filename.startswith(u'file://'):
        filename = filename[len(u'file://'):]
        return {'__dirpath': path.dirname(filename),
                PATH: filename,
                FILENAME: path.basename(filename),
                "__ext": path.splitext(filename)[1][1:],
                "__dirname": path.basename(path.dirname(filename))}

getTime = lambda date: audioinfo.strtime(int(date))
getCreated = lambda created: {u'__created': getTime(created)}
getModified = lambda modified: {u'__modified': getTime(modified)}
getLength = lambda length: {u'__length': audioinfo.strlength(int(length))}
getBitRate = lambda bitrate: {u'__bitrate': bitrate + u' kb/s'}


CONVERSION = {u'title': u'title',
u'genre': u'genre',
u'artist': u'artist',
u'album': u'album',
u'track-number': u'track',
u'duration': getLength,
u'file-size': u'__size',
u'location': getFilename,
u'first-seen': getCreated,