示例#1
0
    def getMusicBrainz(self, ittoc, mbdiscid, release=None, country=None,
                       prompt=False):
        """
        @type  ittoc: L{whipper.image.table.Table}
        """
        # look up disc on MusicBrainz
        self._stdout.write('Disc duration: %s, %d audio tracks\n' % (
            common.formatTime(ittoc.duration() / 1000.0),
            ittoc.getAudioTracks()))
        logger.debug('MusicBrainz submit url: %r',
                     ittoc.getMusicBrainzSubmitURL())
        ret = None

        metadatas = None
        e = None

        for _ in range(0, 4):
            try:
                metadatas = mbngs.musicbrainz(mbdiscid,
                                              country=country,
                                              record=self._record)
                break
            except mbngs.NotFoundException, e:
                logger.warning("release not found: %r" % (e, ))
                break
            except musicbrainzngs.NetworkError, e:
                logger.warning("network error: %r" % (e, ))
                break
示例#2
0
    def getMusicBrainz(self,
                       ittoc,
                       mbdiscid,
                       release=None,
                       country=None,
                       prompt=False):
        """
        @type  ittoc: L{whipper.image.table.Table}
        """
        # look up disc on musicbrainz
        self._stdout.write(
            'Disc duration: %s, %d audio tracks\n' % (common.formatTime(
                ittoc.duration() / 1000.0), ittoc.getAudioTracks()))
        logger.debug('MusicBrainz submit url: %r',
                     ittoc.getMusicBrainzSubmitURL())
        ret = None

        metadatas = None
        e = None

        for _ in range(0, 4):
            try:
                metadatas = mbngs.musicbrainz(mbdiscid,
                                              country=country,
                                              record=self._record)
                break
            except mbngs.NotFoundException, e:
                break
            except musicbrainzngs.NetworkError, e:
                self._stdout.write("Warning: network error: %r\n" % (e, ))
                break
示例#3
0
 def testFormatTime(self):
     self.assertEquals(common.formatTime(7202), '02:00:02.000')
示例#4
0
    def getMusicBrainz(self, ittoc, mbdiscid, release=None, country=None,
                       prompt=False):
        """Look up disc on MusicBrainz and get the relevant metadata.

        :param ittoc:
        :type ittoc: L{whipper.image.table.Table}
        :param mbdiscid:
        :type mbdiscid:
        :param release:  (Default value = None)
        :type release:
        :param country:  (Default value = None)
        :type country:
        :param prompt:  (Default value = False)
        :type prompt:
        """
        # look up disc on MusicBrainz
        self._stdout.write('Disc duration: %s, %d audio tracks\n' % (
            common.formatTime(ittoc.duration() / 1000.0),
            ittoc.getAudioTracks()))
        logger.debug('MusicBrainz submit url: %r',
                     ittoc.getMusicBrainzSubmitURL())
        ret = None

        metadatas = None
        e = None

        for _ in range(0, 4):
            try:
                metadatas = mbngs.musicbrainz(mbdiscid,
                                              country=country,
                                              record=self._record)
                break
            except mbngs.NotFoundException as e:
                logger.warning("release not found: %r" % (e, ))
                break
            except musicbrainzngs.NetworkError as e:
                logger.warning("network error: %r" % (e, ))
                break
            except mbngs.MusicBrainzException as e:
                logger.warning("musicbrainz exception: %r" % (e, ))
                time.sleep(5)
                continue

        if not metadatas:
            self._stdout.write('Continuing without metadata\n')

        if metadatas:
            deltas = {}

            self._stdout.write('\nMatching releases:\n')

            for metadata in metadatas:
                self._stdout.write('\n')
                self._stdout.write('Artist  : %s\n' %
                                   metadata.artist.encode('utf-8'))
                self._stdout.write('Title   : %s\n' %
                                   metadata.title.encode('utf-8'))
                self._stdout.write('Duration: %s\n' %
                                   common.formatTime(metadata.duration /
                                                     1000.0))
                self._stdout.write('URL     : %s\n' % metadata.url)
                self._stdout.write('Release : %s\n' % metadata.mbid)
                self._stdout.write('Type    : %s\n' % metadata.releaseType)
                if metadata.barcode:
                    self._stdout.write("Barcode : %s\n" % metadata.barcode)
                if metadata.catalogNumber:
                    self._stdout.write("Cat no  : %s\n" %
                                       metadata.catalogNumber)

                delta = abs(metadata.duration - ittoc.duration())
                if delta not in deltas:
                    deltas[delta] = []
                deltas[delta].append(metadata)

            lowest = None

            if not release and len(metadatas) > 1:
                # Select the release that most closely matches the duration.
                lowest = min(deltas.keys())

                if prompt:
                    guess = (deltas[lowest])[0].mbid
                    release = raw_input(
                        "\nPlease select a release [%s]: " % guess)

                    if not release:
                        release = guess

            if release:
                metadatas = [m for m in metadatas if m.url.endswith(release)]
                logger.debug('Asked for release %r, only kept %r',
                             release, metadatas)
                if len(metadatas) == 1:
                    self._stdout.write('\n')
                    self._stdout.write('Picked requested release id %s\n' %
                                       release)
                    self._stdout.write('Artist : %s\n' %
                                       metadatas[0].artist.encode('utf-8'))
                    self._stdout.write('Title :  %s\n' %
                                       metadatas[0].title.encode('utf-8'))
                elif not metadatas:
                    self._stdout.write(
                        "Requested release id '%s', "
                        "but none of the found releases match\n" % release)
                    return
            else:
                if lowest:
                    metadatas = deltas[lowest]

            # If we have multiple, make sure they match
            if len(metadatas) > 1:
                artist = metadatas[0].artist
                releaseTitle = metadatas[0].releaseTitle
                for i, metadata in enumerate(metadatas):
                    if not artist == metadata.artist:
                        logger.warning("artist 0: %r and artist %d: %r "
                                       "are not the same" % (
                                           artist, i, metadata.artist))
                    if not releaseTitle == metadata.releaseTitle:
                        logger.warning("title 0: %r and title %d: %r "
                                       "are not the same" % (
                                           releaseTitle, i,
                                           metadata.releaseTitle))

                if (not release and len(deltas.keys()) > 1):
                    self._stdout.write('\n')
                    self._stdout.write('Picked closest match in duration.\n')
                    self._stdout.write('Others may be wrong in MusicBrainz, '
                                       'please correct.\n')
                    self._stdout.write('Artist : %s\n' %
                                       artist.encode('utf-8'))
                    self._stdout.write('Title :  %s\n' %
                                       metadatas[0].title.encode('utf-8'))

            # Select one of the returned releases. We just pick the first one.
            ret = metadatas[0]
        else:
            self._stdout.write(
                'Submit this disc to MusicBrainz at the above URL.\n')
            ret = None

        self._stdout.write('\n')
        return ret
示例#5
0
    def getMusicBrainz(self,
                       ittoc,
                       mbdiscid,
                       release=None,
                       country=None,
                       prompt=False):
        """
        :type  ittoc: whipper.image.table.Table
        """
        # look up disc on MusicBrainz
        print('Disc duration: %s, %d audio tracks' % (common.formatTime(
            ittoc.duration() / 1000.0), ittoc.getAudioTracks()))
        logger.debug('MusicBrainz submit url: %r',
                     ittoc.getMusicBrainzSubmitURL())

        metadatas = None

        for _ in range(0, 4):
            try:
                metadatas = mbngs.musicbrainz(mbdiscid,
                                              country=country,
                                              record=self._record)
                break
            except mbngs.NotFoundException as e:
                logger.warning("release not found: %r", (e, ))
                break
            except musicbrainzngs.NetworkError as e:
                logger.warning("network error: %r", (e, ))
                break
            except mbngs.MusicBrainzException as e:
                logger.warning("musicbrainz exception: %r", (e, ))
                time.sleep(5)
                continue

        if not metadatas:
            logger.warning('continuing without metadata')

        if metadatas:
            deltas = {}

            print('\nMatching releases:')

            for metadata in metadatas:
                print('\nArtist  : %s' % metadata.artist)
                print('Title   : %s' % metadata.title)
                print('Duration: %s' %
                      common.formatTime(metadata.duration / 1000.0))
                print('URL     : %s' % metadata.url)
                print('Release : %s' % metadata.mbid)
                print('Type    : %s' % metadata.releaseType)
                if metadata.barcode:
                    print("Barcode : %s" % metadata.barcode)
                # TODO: Add test for non ASCII catalog numbers: see issue #215
                if metadata.catalogNumber:
                    print("Cat no  : %s" % metadata.catalogNumber)

                delta = abs(metadata.duration - ittoc.duration())
                if delta not in deltas:
                    deltas[delta] = []
                deltas[delta].append(metadata)

            lowest = None

            if not release and len(metadatas) > 1:
                # Select the release that most closely matches the duration.
                lowest = min(list(deltas))

                if prompt:
                    guess = (deltas[lowest])[0].mbid
                    release = input("\nPlease select a release [%s]: " % guess)

                    if not release:
                        release = guess

            if release:
                metadatas = [m for m in metadatas if m.url.endswith(release)]
                logger.debug('asked for release %r, only kept %r', release,
                             metadatas)
                if len(metadatas) == 1:
                    logger.info('picked requested release id %s', release)
                    print('Artist: %s' % metadatas[0].artist)
                    print('Title : %s' % metadatas[0].title)
                elif not metadatas:
                    logger.warning(
                        "requested release id '%s', but none of "
                        "the found releases match", release)
                    return None
            else:
                if lowest:
                    metadatas = deltas[lowest]

            # If we have multiple, make sure they match
            if len(metadatas) > 1:
                artist = metadatas[0].artist
                releaseTitle = metadatas[0].releaseTitle
                for i, metadata in enumerate(metadatas):
                    if not artist == metadata.artist:
                        logger.warning(
                            "artist 0: %r and artist %d: %r are "
                            "not the same", artist, i, metadata.artist)
                    if not releaseTitle == metadata.releaseTitle:
                        logger.warning(
                            "title 0: %r and title %d: %r are "
                            "not the same", releaseTitle, i,
                            metadata.releaseTitle)

                if not release and len(list(deltas)) > 1:
                    logger.warning('picked closest match in duration. '
                                   'Others may be wrong in MusicBrainz, '
                                   'please correct')
                    print('Artist : %s' % artist)
                    print('Title :  %s' % metadatas[0].title)

            # Select one of the returned releases. We just pick the first one.
            ret = metadatas[0]
        else:
            print('Submit this disc to MusicBrainz at the above URL.')
            ret = None

        print('')
        return ret
示例#6
0
    def getMusicBrainz(self, ittoc, mbdiscid, release=None, country=None,
                       prompt=False):
        """
        @type  ittoc: L{whipper.image.table.Table}
        """
        # look up disc on MusicBrainz
        self._stdout.write('Disc duration: %s, %d audio tracks\n' % (
            common.formatTime(ittoc.duration() / 1000.0),
            ittoc.getAudioTracks()))
        logger.debug('MusicBrainz submit url: %r',
                     ittoc.getMusicBrainzSubmitURL())
        ret = None

        metadatas = None
        e = None

        for _ in range(0, 4):
            try:
                metadatas = mbngs.musicbrainz(mbdiscid,
                                              country=country,
                                              record=self._record)
                break
            except mbngs.NotFoundException as e:
                logger.warning("release not found: %r" % (e, ))
                break
            except musicbrainzngs.NetworkError as e:
                logger.warning("network error: %r" % (e, ))
                break
            except mbngs.MusicBrainzException as e:
                logger.warning("musicbrainz exception: %r" % (e, ))
                time.sleep(5)
                continue

        if not metadatas:
            self._stdout.write('Continuing without metadata\n')

        if metadatas:
            deltas = {}

            self._stdout.write('\nMatching releases:\n')

            for metadata in metadatas:
                self._stdout.write('\n')
                self._stdout.write('Artist  : %s\n' %
                                   metadata.artist.encode('utf-8'))
                self._stdout.write('Title   : %s\n' %
                                   metadata.title.encode('utf-8'))
                self._stdout.write('Duration: %s\n' %
                                   common.formatTime(metadata.duration /
                                                     1000.0))
                self._stdout.write('URL     : %s\n' % metadata.url)
                self._stdout.write('Release : %s\n' % metadata.mbid)
                self._stdout.write('Type    : %s\n' % metadata.releaseType)
                if metadata.barcode:
                    self._stdout.write("Barcode : %s\n" % metadata.barcode)
                if metadata.catalogNumber:
                    self._stdout.write("Cat no  : %s\n" %
                                       metadata.catalogNumber)

                delta = abs(metadata.duration - ittoc.duration())
                if delta not in deltas:
                    deltas[delta] = []
                deltas[delta].append(metadata)

            lowest = None

            if not release and len(metadatas) > 1:
                # Select the release that most closely matches the duration.
                lowest = min(list(deltas))

                if prompt:
                    guess = (deltas[lowest])[0].mbid
                    release = raw_input(
                        "\nPlease select a release [%s]: " % guess)

                    if not release:
                        release = guess

            if release:
                metadatas = [m for m in metadatas if m.url.endswith(release)]
                logger.debug('Asked for release %r, only kept %r',
                             release, metadatas)
                if len(metadatas) == 1:
                    self._stdout.write('\n')
                    self._stdout.write('Picked requested release id %s\n' %
                                       release)
                    self._stdout.write('Artist : %s\n' %
                                       metadatas[0].artist.encode('utf-8'))
                    self._stdout.write('Title :  %s\n' %
                                       metadatas[0].title.encode('utf-8'))
                elif not metadatas:
                    self._stdout.write(
                        "Requested release id '%s', "
                        "but none of the found releases match\n" % release)
                    return
            else:
                if lowest:
                    metadatas = deltas[lowest]

            # If we have multiple, make sure they match
            if len(metadatas) > 1:
                artist = metadatas[0].artist
                releaseTitle = metadatas[0].releaseTitle
                for i, metadata in enumerate(metadatas):
                    if not artist == metadata.artist:
                        logger.warning("artist 0: %r and artist %d: %r "
                                       "are not the same" % (
                                           artist, i, metadata.artist))
                    if not releaseTitle == metadata.releaseTitle:
                        logger.warning("title 0: %r and title %d: %r "
                                       "are not the same" % (
                                           releaseTitle, i,
                                           metadata.releaseTitle))

                if (not release and len(list(deltas)) > 1):
                    self._stdout.write('\n')
                    self._stdout.write('Picked closest match in duration.\n')
                    self._stdout.write('Others may be wrong in MusicBrainz, '
                                       'please correct.\n')
                    self._stdout.write('Artist : %s\n' %
                                       artist.encode('utf-8'))
                    self._stdout.write('Title :  %s\n' %
                                       metadatas[0].title.encode('utf-8'))

            # Select one of the returned releases. We just pick the first one.
            ret = metadatas[0]
        else:
            self._stdout.write(
                'Submit this disc to MusicBrainz at the above URL.\n')
            ret = None

        self._stdout.write('\n')
        return ret
示例#7
0
        if not metadatas:
            self._stdout.write('Continuing without metadata\n')

        if metadatas:
            deltas = {}

            self._stdout.write('\nMatching releases:\n')

            for metadata in metadatas:
                self._stdout.write('\n')
                self._stdout.write('Artist  : %s\n' %
                                   metadata.artist.encode('utf-8'))
                self._stdout.write('Title   : %s\n' %
                                   metadata.title.encode('utf-8'))
                self._stdout.write('Duration: %s\n' %
                                   common.formatTime(metadata.duration /
                                                     1000.0))
                self._stdout.write('URL     : %s\n' % metadata.url)
                self._stdout.write('Release : %s\n' % metadata.mbid)
                self._stdout.write('Type    : %s\n' % metadata.releaseType)
                if metadata.barcode:
                    self._stdout.write("Barcode : %s\n" % metadata.barcode)
                if metadata.catalogNumber:
                    self._stdout.write("Cat no  : %s\n" %
                                       metadata.catalogNumber)

                delta = abs(metadata.duration - ittoc.duration())
                if delta not in deltas:
                    deltas[delta] = []
                deltas[delta].append(metadata)

            lowest = None
示例#8
0
            self._stdout.write('Continuing without metadata\n')

        if metadatas:
            deltas = {}

            self._stdout.write('\nMatching releases:\n')

            for metadata in metadatas:
                self._stdout.write('\n')
                self._stdout.write('Artist  : %s\n' %
                                   metadata.artist.encode('utf-8'))
                self._stdout.write('Title   : %s\n' %
                                   metadata.title.encode('utf-8'))
                self._stdout.write(
                    'Duration: %s\n' %
                    common.formatTime(metadata.duration / 1000.0))
                self._stdout.write('URL     : %s\n' % metadata.url)
                self._stdout.write('Release : %s\n' % metadata.mbid)
                self._stdout.write('Type    : %s\n' % metadata.releaseType)
                if metadata.barcode:
                    self._stdout.write("Barcode : %s\n" % metadata.barcode)
                if metadata.catalogNumber:
                    self._stdout.write("Cat no  : %s\n" %
                                       metadata.catalogNumber)

                delta = abs(metadata.duration - ittoc.duration())
                if not delta in deltas:
                    deltas[delta] = []
                deltas[delta].append(metadata)

            lowest = None
示例#9
0
 def testFormatTime(self):
     self.assertEquals(common.formatTime(7202), '02:00:02.000')