def parse_recording_data(data, info=None): track = {} if info is None else info.copy() try: track['title'] = data['title'] except KeyError: track['acoustid_id'] = data['id'] return {}, track if 'duration' in data: track['__length'] = audioinfo.strlength(data['duration']) track['acoustid_id'] = data['id'] track['artist'] = data.get('artists', [{'name': u""}])[0]['name'] if track['artist']: track['mbrainz_artist_id'] = data['artists'][0]['id'] if 'releases' in data: album_info = map(parse_release_data, data['releases']) else: album_info = [] track = dict((k,v) for k,v in track.iteritems() if not isempty(v)) if 'artist' in track: for album in album_info: if 'artist' not in album: album['artist'] = track['artist'] return album_info, track
def parse_track_list(node): tracks = [] for i, t in enumerate(parse_node(node, 'track-list', 'track', 'position')): track = t['recording'] rem_keys = set(track).union(TO_REMOVE) track.update((k,v) for k,v in t.iteritems() if k not in rem_keys) if u'puid-list' in track: track['musicip_puid'] = track['puid-list']['id'] del(track['puid-list']) if not isempty(track.get(u'relation-list')): for r in to_list(track['relation-list']): track.update(parse_track_relation(r)) feat = to_list(track.get('artist-credit', {}).get('name-credit')) if feat: names = [(z['artist']['name'], z.get('joinphrase', u'')) for z in feat] track['artist'] = u''.join('%s%s' % a for a in names) for k, v in track.items(): if not isinstance(track[k], (basestring, list)): del(track[k]) elif isinstance(v, list) and not isinstance(v[0], basestring): del(track[k]) if u'length' in track: track['length'] = strlength(int(track[u'length']) / 1000) tracks.append(convert_dict(track, TRACK_KEYS)) return tracks
def parse_recording_data(data, info=None): track = {} if info is None else info.copy() try: track['title'] = data['title'] except KeyError: track['acoustid_id'] = data['id'] return {}, track if 'duration' in data: track['__length'] = audioinfo.strlength(data['duration']) track['acoustid_id'] = data['id'] track['artist'] = data.get('artists', [{'name': u""}])[0]['name'] if track['artist']: track['mbrainz_artist_id'] = data['artists'][0]['id'] if 'releases' in data: album_info = map(parse_release_data, data['releases']) else: album_info = [] track = dict((k, v) for k, v in track.iteritems() if not isempty(v)) if 'artist' in track: for album in album_info: if 'artist' not in album: album['artist'] = track['artist'] return album_info, track
def parse_track_list(node): tracks = [] for i, t in enumerate(parse_node(node, 'track-list', 'track', 'position')): track = t['recording'] rem_keys = set(track).union(TO_REMOVE) track.update((k, v) for k, v in t.iteritems() if k not in rem_keys) if u'puid-list' in track: track['musicip_puid'] = track['puid-list']['id'] del (track['puid-list']) if not isempty(track.get(u'relation-list')): for r in to_list(track['relation-list']): track.update(parse_track_relation(r)) feat = to_list(track.get('artist-credit', {}).get('name-credit')) if feat: names = [(z['artist']['name'], z.get('joinphrase', u'')) for z in feat] track['artist'] = u''.join('%s%s' % a for a in names) for k, v in track.items(): if not isinstance(track[k], (basestring, list)): del (track[k]) elif isinstance(v, list) and not isinstance(v[0], basestring): del (track[k]) if u'length' in track: track['length'] = strlength(int(track[u'length']) / 1000) tracks.append(convert_dict(track, TRACK_KEYS)) return tracks
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)
def convertTrack(self, track, artist=None, album=None): join = os.path.join if artist is None: #print len(track), track try: artist = track[21] except: print track.tags raise if album is None: album = track[22] try: genre = GENRES[track[8]] except (IndexError, TypeError): genre = u'' temp = { '__filename': join(track[0], track[1]), '__path': track[1], '__ext': os.path.splitext( track[1])[1][1:], #Don't need(or want) the extra dot '__bitrate': audioinfo.strbitrate(track[2] * 1000), '__frequency': audioinfo.strfrequency(track[3]), '__length': audioinfo.strlength(track[4]), '__folder': track[0], 'title': track[5], 'track': track[6], 'year': track[7], 'genre': genre, 'comment': track[9], '__size': track[10], '__modified': track[11], 'artist': artist, 'album': album, '__library': 'prokyon', "___layer": track[12], '___mimetype': track[13], '___version': track[14], '___mode': track[15], '___lyricsid': track[16], '___synclyricsid': track[17], '___notes': track[18], '___rating': track[19], '___medium': track[20] } return self.applyToDict(self.applyToDict(temp, self.valuetostring), self.latinutf)
def convertTrack(self, track, artist = None, album = None): join = os.path.join if artist is None: #print len(track), track try: artist = track[21] except: print track.tags raise if album is None: album = track[22] try: genre = GENRES[track[8]] except (IndexError, TypeError): genre = u'' temp = {'__filename': join(track[0], track[1]), '__path': track[1], '__ext': os.path.splitext(track[1])[1][1:], #Don't need(or want) the extra dot '__bitrate': audioinfo.strbitrate(track[2] * 1000), '__frequency': audioinfo.strfrequency(track[3]), '__length': audioinfo.strlength(track[4]), '__folder': track[0], 'title': track[5], 'track': track[6], 'year': track[7], 'genre': genre, 'comment': track[9], '__size' : track[10], '__modified': track[11], 'artist': artist, 'album': album, '__library': 'prokyon', "___layer": track[12], '___mimetype': track[13], '___version': track[14], '___mode': track[15], '___lyricsid': track[16], '___synclyricsid': track[17], '___notes': track[18], '___rating': track[19], '___medium': track[20]} return self.applyToDict(self.applyToDict(temp, self.valuetostring), self.latinutf)
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, u'mtime': getModified, u'last-seen': '__last_seen', u'bitrate': getBitRate,
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))
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, u'mtime': getModified, u'last-seen': '__last_seen', u'bitrate': getBitRate,