Пример #1
0
    def _on_lookup_finished(self, next, file, document, http, error):
        def make_artist_credit_node(parent, artists):
            artist_credit_el = parent.append_child("artist_credit")
            for i, artist in enumerate(artists):
                name_credit_el = artist_credit_el.append_child("name_credit")
                artist_el = name_credit_el.append_child("artist")
                artist_el.append_child("id").text = artist.id[0].text
                artist_el.append_child("name").text = artist.name[0].text
                artist_el.append_child("sort_name").text = artist.name[0].text
                if i > 0:
                    name_credit_el.attribs["joinphrase"] = "; "
            return artist_credit_el

        doc = XmlNode()
        metadata_el = doc.append_child("metadata")
        puid_el = metadata_el.append_child("puid")
        recording_list_el = puid_el.append_child("recording_list")
        seen = set()
        acoustid_id = None
        for result in document.response[0].results[0].children.get("result", []):
            if acoustid_id is None:
                acoustid_id = result.id[0].text
            if "recordings" not in result.children:
                continue
            for recording in result.recordings[0].recording:
                recording_id = recording.id[0].text
                if "title" not in recording.children:  # we have no metadata for this recording
                    continue
                if recording_id in seen:
                    continue
                seen.add(recording_id)
                recording_el = recording_list_el.append_child("recording")
                recording_el.attribs["id"] = recording_id
                recording_el.append_child("title").text = recording.title[0].text
                if "duration" in recording.children:
                    recording_el.append_child("length").text = str(int(recording.duration[0].text) * 1000)
                make_artist_credit_node(recording_el, recording.artists[0].artist)
                release_list_el = recording_el.append_child("release_list")
                for release_group in recording.releasegroups[0].releasegroup:
                    for release in release_group.releases[0].release:
                        release_el = release_list_el.append_child("release")
                        release_el.attribs["id"] = release.id[0].text
                        if "title" in release.children:
                            release_el.append_child("title").text = release.title[0].text
                        else:
                            release_el.append_child("title").text = release_group.title[0].text
                        if "country" in release.children:
                            release_el.append_child("country").text = release.country[0].text
                        medium_list_el = release_el.append_child("medium_list")
                        medium_list_el.attribs["count"] = release.medium_count[0].text
                        for medium in release.mediums[0].medium:
                            medium_el = medium_list_el.append_child("medium")
                            track_list_el = medium_el.append_child("track_list")
                            track_list_el.attribs["count"] = medium.track_count[0].text
                            for track in medium.tracks[0].track:
                                track_el = track_list_el.append_child("track")
                                track_el.append_child("position").text = track.position[0].text
        if acoustid_id is not None:
            file.metadata["acoustid_id"] = acoustid_id
        next(doc, http, error)
Пример #2
0
    def _on_lookup_finished(self, next, file, document, http, error):

        def make_artist_credit_node(parent, artists):
            artist_credit_el = parent.append_child('artist_credit')
            for i, artist in enumerate(artists):
                name_credit_el = artist_credit_el.append_child('name_credit')
                artist_el = name_credit_el.append_child('artist')
                artist_el.append_child('id').text = artist.id[0].text
                artist_el.append_child('name').text = artist.name[0].text
                artist_el.append_child('sort_name').text = artist.name[0].text
                if i > 0:
                    name_credit_el.attribs['joinphrase'] = '; '
            return artist_credit_el

        def parse_recording(recording):
            if 'title' not in recording.children: # we have no metadata for this recording
                return
            recording_id = recording.id[0].text
            recording_el = recording_list_el.append_child('recording')
            recording_el.attribs['id'] = recording_id
            recording_el.append_child('title').text = recording.title[0].text
            if 'duration' in recording.children:
                recording_el.append_child('length').text = str(int(recording.duration[0].text) * 1000)
            make_artist_credit_node(recording_el, recording.artists[0].artist)
            release_list_el = recording_el.append_child('release_list')
            for release_group in recording.releasegroups[0].releasegroup:
                for release in release_group.releases[0].release:
                    release_el = release_list_el.append_child('release')
                    release_el.attribs['id'] = release.id[0].text
                    release_group_el = release_el.append_child('release_group')
                    release_group_el.attribs['id'] = release_group.id[0].text
                    if 'title' in release.children:
                        release_el.append_child('title').text = release.title[0].text
                    else:
                        release_el.append_child('title').text = release_group.title[0].text
                    if 'country' in release.children:
                        release_el.append_child('country').text = release.country[0].text
                    medium_list_el = release_el.append_child('medium_list')
                    medium_list_el.attribs['count'] = release.medium_count[0].text
                    for medium in release.mediums[0].medium:
                        medium_el = medium_list_el.append_child('medium')
                        track_list_el = medium_el.append_child('track_list')
                        track_list_el.attribs['count'] = medium.track_count[0].text
                        for track in medium.tracks[0].track:
                            track_el = track_list_el.append_child('track')
                            track_el.append_child('position').text = track.position[0].text

        doc = XmlNode()
        metadata_el = doc.append_child('metadata')
        acoustid_el = metadata_el.append_child('acoustid')
        recording_list_el = acoustid_el.append_child('recording_list')
        acoustid_id = None

        results = document.response[0].results[0].children.get('result')
        if results:
            result = results[0]
            acoustid_id = result.id[0].text
            if 'recordings' in result.children:
                for recording in result.recordings[0].recording:
                    parse_recording(recording)

        if acoustid_id is not None:
            file.metadata['acoustid_id'] = acoustid_id
        next(doc, http, error)
Пример #3
0
 def test_1(self):
     release = XmlNode(attribs={'id': '123'}, children={
         'title': [XmlNode(text='Foo')],
         'status': [XmlNode(text='Official')],
         'text_representation': [XmlNode(children={
             'language': [XmlNode(text='eng')],
             'script': [XmlNode(text='Latn')]
         })],
         'artist_credit': [XmlNode(children={
             'name_credit': [XmlNode(attribs={'joinphrase': ' & '}, children={
                 'artist': [XmlNode(attribs={'id': '456'}, children={
                     'name': [XmlNode(text='Foo Bar')],
                     'sort_name': [XmlNode(text='Bar, Foo')]
                 })]
             }), XmlNode(children={
                 'artist': [XmlNode(attribs={'id': '789'}, children={
                     'name': [XmlNode(text='Baz')],
                     'sort_name': [XmlNode(text='Baz')]
                 })]
             })]
         })],
         'date': [XmlNode(text='2009-08-07')],
         'country': [XmlNode(text='GB')],
         'barcode': [XmlNode(text='012345678929')],
         'asin': [XmlNode(text='B123456789')],
         'label_info_list': [XmlNode(attribs={'count': '1'}, children={
             'label_info': [XmlNode(children={
                 'catalog_number': [XmlNode(text='ABC 123')],
                 'label': [XmlNode(children={
                     'name': [XmlNode(text='ABC')]
                 })]
             })]
         })]
     })
     m = Metadata()
     release_to_metadata(release, m, config)
     self.failUnlessEqual('123', m['musicbrainz_albumid'])
     self.failUnlessEqual('456; 789', m['musicbrainz_albumartistid'])
     self.failUnlessEqual('Foo', m['album'])
     self.failUnlessEqual('official', m['releasestatus'])
     self.failUnlessEqual('eng', m['language'])
     self.failUnlessEqual('Latn', m['script'])
     self.failUnlessEqual('Foo Bar & Baz', m['albumartist'])
     self.failUnlessEqual('Bar, Foo & Baz', m['albumartistsort'])
     self.failUnlessEqual('2009-08-07', m['date'])
     self.failUnlessEqual('GB', m['releasecountry'])
     self.failUnlessEqual('012345678929', m['barcode'])
     self.failUnlessEqual('B123456789', m['asin'])
     self.failUnlessEqual('ABC', m['label'])
     self.failUnlessEqual('ABC 123', m['catalognumber'])
Пример #4
0
 def test_1(self):
     class Track:
         pass
     node = XmlNode(children={
         'title': [XmlNode(text='Foo')],
         'length': [XmlNode(text='180000')],
         'position': [XmlNode(text='1')],
         'recording': [XmlNode(attribs={'id': '123'})],
         'artist_credit': [XmlNode(children={
             'name_credit': [XmlNode(attribs={'joinphrase': ' & '}, children={
                 'artist': [XmlNode(attribs={'id': '456'}, children={
                     'name': [XmlNode(text='Foo Bar')],
                     'sort_name': [XmlNode(text='Bar, Foo')]
                 })]
             }), XmlNode(children={
                 'artist': [XmlNode(attribs={'id': '789'}, children={
                     'name': [XmlNode(text='Baz')],
                     'sort_name': [XmlNode(text='Baz')]
                 })]
             })]
         })]
     })
     track = Track()
     m = track.metadata = Metadata()
     track_to_metadata(node, track, config)
     self.failUnlessEqual('123', m['musicbrainz_trackid'])
     self.failUnlessEqual('456; 789', m['musicbrainz_artistid'])
     self.failUnlessEqual('Foo', m['title'])
     self.failUnlessEqual('Foo Bar & Baz', m['artist'])
     self.failUnlessEqual('Bar, Foo & Baz', m['artistsort'])
Пример #5
0
    def _on_lookup_finished(self, next_func, file, document, http, error):
        def make_artist_credit_node(parent, artists):
            artist_credit_el = parent.append_child('artist_credit')
            for i, artist in enumerate(artists):
                name_credit_el = artist_credit_el.append_child('name_credit')
                artist_el = name_credit_el.append_child('artist')
                artist_el.append_child('id').text = artist.id[0].text
                artist_el.append_child('name').text = artist.name[0].text
                artist_el.append_child('sort_name').text = artist.name[0].text
                if i > 0:
                    name_credit_el.attribs['joinphrase'] = '; '
            return artist_credit_el

        def parse_recording(recording):
            if 'title' not in recording.children:  # we have no metadata for this recording
                return
            recording_id = recording.id[0].text
            recording_el = recording_list_el.append_child('recording')
            recording_el.attribs['id'] = recording_id
            recording_el.append_child('title').text = recording.title[0].text
            if 'duration' in recording.children:
                recording_el.append_child('length').text = string_(
                    int(recording.duration[0].text) * 1000)
            make_artist_credit_node(recording_el, recording.artists[0].artist)
            release_list_el = recording_el.append_child('release_list')
            for release_group in recording.releasegroups[0].releasegroup:
                for release in release_group.releases[0].release:
                    release_el = release_list_el.append_child('release')
                    release_el.attribs['id'] = release.id[0].text
                    release_group_el = release_el.append_child('release_group')
                    release_group_el.attribs['id'] = release_group.id[0].text
                    if 'title' in release.children:
                        release_el.append_child(
                            'title').text = release.title[0].text
                    else:
                        release_el.append_child(
                            'title').text = release_group.title[0].text
                    if 'country' in release.children:
                        release_el.append_child(
                            'country').text = release.country[0].text
                    medium_list_el = release_el.append_child('medium_list')
                    medium_list_el.attribs['count'] = release.medium_count[
                        0].text
                    for medium in release.mediums[0].medium:
                        medium_el = medium_list_el.append_child('medium')
                        if 'format' in medium.children:
                            medium_el.append_child(
                                'format').text = medium.format[0].text
                        track_list_el = medium_el.append_child('track_list')
                        track_list_el.attribs['count'] = medium.track_count[
                            0].text
                        for track in medium.tracks[0].track:
                            track_el = track_list_el.append_child('track')
                            track_el.append_child(
                                'position').text = track.position[0].text

        doc = XmlNode()
        metadata_el = doc.append_child('metadata')
        acoustid_el = metadata_el.append_child('acoustid')
        recording_list_el = acoustid_el.append_child('recording_list')

        if error:
            mparms = {
                'error': http.errorString(),
                'filename': file.filename,
            }
            log.error(
                "AcoustID: Lookup network error for '%(filename)s': %(error)r"
                % mparms)
            self.tagger.window.set_statusbar_message(
                N_("AcoustID lookup network error for '%(filename)s'!"),
                mparms,
                echo=None)
        else:
            status = document.response[0].status[0].text
            if status == 'ok':
                results = document.response[0].results[0].children.get(
                    'result')
                if results:
                    result = results[0]
                    file.metadata['acoustid_id'] = result.id[0].text
                    if 'recordings' in result.children:
                        for recording in result.recordings[0].recording:
                            parse_recording(recording)
                        log.debug("AcoustID: Lookup successful for '%s'",
                                  file.filename)
            else:
                mparms = {
                    'error': document.response[0].error[0].message[0].text,
                    'filename': file.filename
                }
                log.error(
                    "AcoustID: Lookup error for '%(filename)s': %(error)r" %
                    mparms)
                self.tagger.window.set_statusbar_message(
                    N_("AcoustID lookup failed for '%(filename)s'!"),
                    mparms,
                    echo=None)

        next_func(doc, http, error)
Пример #6
0
    def _on_lookup_finished(self, next, file, document, http, error):

        def make_artist_credit_node(parent, artists):
            artist_credit_el = parent.append_child('artist_credit')
            for i, artist in enumerate(artists):
                name_credit_el = artist_credit_el.append_child('name_credit')
                artist_el = name_credit_el.append_child('artist')
                artist_el.append_child('id').text = artist.id[0].text
                artist_el.append_child('name').text = artist.name[0].text
                artist_el.append_child('sort_name').text = artist.name[0].text
                if i > 0:
                    name_credit_el.attribs['joinphrase'] = '; '
            return artist_credit_el

        def parse_recording(recording):
            if 'title' not in recording.children:  # we have no metadata for this recording
                return
            recording_id = recording.id[0].text
            recording_el = recording_list_el.append_child('recording')
            recording_el.attribs['id'] = recording_id
            recording_el.append_child('title').text = recording.title[0].text
            if 'duration' in recording.children:
                recording_el.append_child('length').text = str(int(recording.duration[0].text) * 1000)
            make_artist_credit_node(recording_el, recording.artists[0].artist)
            release_list_el = recording_el.append_child('release_list')
            for release_group in recording.releasegroups[0].releasegroup:
                for release in release_group.releases[0].release:
                    release_el = release_list_el.append_child('release')
                    release_el.attribs['id'] = release.id[0].text
                    release_group_el = release_el.append_child('release_group')
                    release_group_el.attribs['id'] = release_group.id[0].text
                    if 'title' in release.children:
                        release_el.append_child('title').text = release.title[0].text
                    else:
                        release_el.append_child('title').text = release_group.title[0].text
                    if 'country' in release.children:
                        release_el.append_child('country').text = release.country[0].text
                    medium_list_el = release_el.append_child('medium_list')
                    medium_list_el.attribs['count'] = release.medium_count[0].text
                    for medium in release.mediums[0].medium:
                        medium_el = medium_list_el.append_child('medium')
                        if 'format' in medium.children:
                            medium_el.append_child('format').text = medium.format[0].text
                        track_list_el = medium_el.append_child('track_list')
                        track_list_el.attribs['count'] = medium.track_count[0].text
                        for track in medium.tracks[0].track:
                            track_el = track_list_el.append_child('track')
                            track_el.append_child('position').text = track.position[0].text

        doc = XmlNode()
        metadata_el = doc.append_child('metadata')
        acoustid_el = metadata_el.append_child('acoustid')
        recording_list_el = acoustid_el.append_child('recording_list')

        if error:
            mparms = {
                'error': unicode(http.errorString()),
                'filename': file.filename,
            }
            log.error(
                "AcoustID: Lookup network error for '%(filename)s': %(error)r" %
                mparms)
            self.tagger.window.set_statusbar_message(
                N_("AcoustID lookup network error for '%(filename)s'!"),
                mparms,
                echo=None
            )
        else:
            status = document.response[0].status[0].text
            if status == 'ok':
                results = document.response[0].results[0].children.get('result')
                if results:
                    result = results[0]
                    file.metadata['acoustid_id'] = result.id[0].text
                    if 'recordings' in result.children:
                        for recording in result.recordings[0].recording:
                            parse_recording(recording)
                        log.debug("AcoustID: Lookup successful for '%s'", file.filename)
            else:
                mparms = {
                    'error': document.response[0].error[0].message[0].text,
                    'filename': file.filename
                }
                log.error(
                    "AcoustID: Lookup error for '%(filename)s': %(error)r" %
                    mparms)
                self.tagger.window.set_statusbar_message(
                    N_("AcoustID lookup failed for '%(filename)s'!"),
                    mparms,
                    echo=None
                )

        next(doc, http, error)
Пример #7
0
    def _on_lookup_finished(self, next, file, document, http, error):
        def make_artist_credit_node(parent, artists):
            artist_credit_el = parent.append_child('artist_credit')
            for i, artist in enumerate(artists):
                name_credit_el = artist_credit_el.append_child('name_credit')
                artist_el = name_credit_el.append_child('artist')
                artist_el.append_child('id').text = artist.id[0].text
                artist_el.append_child('name').text = artist.name[0].text
                artist_el.append_child('sort_name').text = artist.name[0].text
                if i > 0:
                    name_credit_el.attribs['joinphrase'] = '; '
            return artist_credit_el

        def parse_recording(recording):
            if 'title' not in recording.children:  # we have no metadata for this recording
                return
            recording_id = recording.id[0].text
            recording_el = recording_list_el.append_child('recording')
            recording_el.attribs['id'] = recording_id
            recording_el.append_child('title').text = recording.title[0].text
            if 'duration' in recording.children:
                recording_el.append_child('length').text = str(
                    int(recording.duration[0].text) * 1000)
            make_artist_credit_node(recording_el, recording.artists[0].artist)
            release_list_el = recording_el.append_child('release_list')
            for release_group in recording.releasegroups[0].releasegroup:
                for release in release_group.releases[0].release:
                    release_el = release_list_el.append_child('release')
                    release_el.attribs['id'] = release.id[0].text
                    release_group_el = release_el.append_child('release_group')
                    release_group_el.attribs['id'] = release_group.id[0].text
                    if 'title' in release.children:
                        release_el.append_child(
                            'title').text = release.title[0].text
                    else:
                        release_el.append_child(
                            'title').text = release_group.title[0].text
                    if 'country' in release.children:
                        release_el.append_child(
                            'country').text = release.country[0].text
                    medium_list_el = release_el.append_child('medium_list')
                    medium_list_el.attribs['count'] = release.medium_count[
                        0].text
                    for medium in release.mediums[0].medium:
                        medium_el = medium_list_el.append_child('medium')
                        track_list_el = medium_el.append_child('track_list')
                        track_list_el.attribs['count'] = medium.track_count[
                            0].text
                        for track in medium.tracks[0].track:
                            track_el = track_list_el.append_child('track')
                            track_el.append_child(
                                'position').text = track.position[0].text

        doc = XmlNode()
        metadata_el = doc.append_child('metadata')
        acoustid_el = metadata_el.append_child('acoustid')
        recording_list_el = acoustid_el.append_child('recording_list')

        status = document.response[0].status[0].text
        if status == 'ok':
            results = document.response[0].results[0].children.get('result')
            if results:
                result = results[0]
                file.metadata['acoustid_id'] = result.id[0].text
                if 'recordings' in result.children:
                    for recording in result.recordings[0].recording:
                        parse_recording(recording)
        else:
            error_message = document.response[0].error[0].message[0].text
            log.error("Fingerprint lookup failed: %r", error_message)

        next(doc, http, error)
Пример #8
0
    def _on_lookup_finished(self, next, file, document, http, error):
        def make_artist_credit_node(parent, artists):
            artist_credit_el = parent.append_child('artist_credit')
            for i, artist in enumerate(artists):
                name_credit_el = artist_credit_el.append_child('name_credit')
                artist_el = name_credit_el.append_child('artist')
                artist_el.append_child('id').text = artist.id[0].text
                artist_el.append_child('name').text = artist.name[0].text
                artist_el.append_child('sort_name').text = artist.name[0].text
                if i > 0:
                    name_credit_el.attribs['joinphrase'] = '; '
            return artist_credit_el

        doc = XmlNode()
        metadata_el = doc.append_child('metadata')
        puid_el = metadata_el.append_child('puid')
        recording_list_el = puid_el.append_child('recording_list')
        seen = set()
        acoustid_id = None
        for result in document.response[0].results[0].children.get(
                'result', []):
            if acoustid_id is None:
                acoustid_id = result.id[0].text
            if 'recordings' not in result.children:
                continue
            for recording in result.recordings[0].recording:
                recording_id = recording.id[0].text
                if 'title' not in recording.children:  # we have no metadata for this recording
                    continue
                if recording_id in seen:
                    continue
                seen.add(recording_id)
                recording_el = recording_list_el.append_child('recording')
                recording_el.attribs['id'] = recording_id
                recording_el.append_child(
                    'title').text = recording.title[0].text
                if 'duration' in recording.children:
                    recording_el.append_child('length').text = str(
                        int(recording.duration[0].text) * 1000)
                make_artist_credit_node(recording_el,
                                        recording.artists[0].artist)
                release_list_el = recording_el.append_child('release_list')
                for release_group in recording.releasegroups[0].releasegroup:
                    for release in release_group.releases[0].release:
                        release_el = release_list_el.append_child('release')
                        release_el.attribs['id'] = release.id[0].text
                        if 'title' in release.children:
                            release_el.append_child(
                                'title').text = release.title[0].text
                        else:
                            release_el.append_child(
                                'title').text = release_group.title[0].text
                        if 'country' in release.children:
                            release_el.append_child(
                                'country').text = release.country[0].text
                        medium_list_el = release_el.append_child('medium_list')
                        medium_list_el.attribs['count'] = release.medium_count[
                            0].text
                        for medium in release.mediums[0].medium:
                            medium_el = medium_list_el.append_child('medium')
                            track_list_el = medium_el.append_child(
                                'track_list')
                            track_list_el.attribs[
                                'count'] = medium.track_count[0].text
                            for track in medium.tracks[0].track:
                                track_el = track_list_el.append_child('track')
                                track_el.append_child(
                                    'position').text = track.position[0].text
        if acoustid_id is not None:
            file.metadata['acoustid_id'] = acoustid_id
        next(doc, http, error)