Exemplo n.º 1
0
    def process_search_response(self, album, metadata, response, reply, error):
        if self._handle_error(album, error, response):
            log.warning('{}: lyrics NOT found for track "{}" by {}'.format(
                PLUGIN_NAME, metadata['title'], metadata['artist']))
            return

        try:
            lyrics_url = response['result'][0]['api_lyrics']
            log.debug('{}: lyrics found for track "{}" by {} at {}'.format(
                PLUGIN_NAME, metadata['title'], metadata['artist'],
                lyrics_url))
            path = urlparse(lyrics_url).path

        except (TypeError, KeyError, ValueError):
            log.warn(
                '{}: failed parsing search response for "{}" by {}'.format(
                    PLUGIN_NAME, metadata['title'], metadata['artist']),
                exc_info=True)
            album._requests -= 1
            album._finalize_loading(None)
            return

        self._request(album.tagger.webservice,
                      path,
                      partial(self.process_lyrics_response, album, metadata),
                      important=True)
Exemplo n.º 2
0
def get_music_rename_filename(new_path, old_path):
    # We only allow moving if the file doesn't already exist
    if os.path.exists(new_path):
        if old_path and not samefile(old_path, new_path):
            raise Exception(f"File '{new_path}' already exists.")

    # If another file matches with a different extension, try to rename it
    old_dirname = os.dirname(old_path)

    dirname = os.dirname(new_path)
    basename = os.path.basename(new_path)
    filename, ext = os.path.splitext(basename)
    ext_lower = ext.lower()

    for list_basename in os.listdir(dirname):
        list_path = os.path.join(dirname, list_basename)
        list_filename, list_ext = os.path.splitext(list_basename)
        list_ext_lower = list_ext.lower()

        # We only care about audio extensions
        if list_ext_lower not in ('mp3', 'flac', 'm4a', 'wav'):
            continue

        # We only care about different extensions
        if ext_lower == list_ext_lower:
            continue

        # Warn if different extension and different filename
        if list_filename != filename:
            log.warn(f"Found file with different extension '{list_path}'.")
            continue

        # Fail if different extension and same name, and we aren't upgrading to FLAC
        if ext_lower != ".flac" or list_ext_lower == ".flac":
            raise Exception(
                f"File with different extension '{list_path}' already exists.")

        # Otherwise backup the old file, and proceed
        backup_path = os.path.join(old_dirname, list_basename + '.bak')
        log.warn("Backing up different extension %r => %r", list_path,
                 backup_path)
        os.rename(list_path, backup_path)

    return new_path
Exemplo n.º 3
0
    def process_lyrics_response(self, album, metadata, response, reply, error):
        if self._handle_error(album, error, response):
            log.warning('{}: lyrics NOT loaded for track "{}" by {}'.format(
                PLUGIN_NAME, metadata['title'], metadata['artist']))
            return

        try:
            lyrics = response['result']['lyrics']
            metadata['lyrics'] = lyrics
            log.debug('{}: lyrics loaded for track "{}" by {}'.format(
                PLUGIN_NAME, metadata['title'], metadata['artist']))

        except (TypeError, KeyError):
            log.warn(
                '{}: failed parsing search response for "{}" by {}'.format(
                    PLUGIN_NAME, metadata['title'], metadata['artist']),
                exc_info=True)

        finally:
            album._requests -= 1
            album._finalize_loading(None)
Exemplo n.º 4
0
    def _batch_submit_finished(self, submissions, batch, previous_errors,
                               document, http, error):
        if error:
            # re-add batched items to remaining list
            submissions.extend(batch)

            response_code = self._acoustid_api.webservice.http_response_code(
                http)
            if response_code == 413:
                self.max_batch_size = int(self.max_batch_size *
                                          self.BATCH_SIZE_REDUCTION_FACTOR)
                log.warn(
                    "AcoustID: payload too large, batch size reduced to %d",
                    self.max_batch_size)
            else:
                try:
                    errordoc = load_json(document)
                    message = errordoc["error"]["message"]
                except BaseException:
                    message = ""
                mparms = {'error': http.errorString(), 'message': message}
                previous_errors.append(mparms)
                log_msg = N_(
                    "AcoustID submission failed with error '%(error)s': %(message)s"
                )
                log.error(log_msg, mparms)
                self.tagger.window.set_statusbar_message(log_msg,
                                                         mparms,
                                                         echo=None,
                                                         timeout=3000)
        else:
            log.debug('AcoustID: %d fingerprints successfully submitted',
                      len(batch))
            for file, submission in batch:
                submission.orig_recordingid = submission.recordingid
                file.update()
            self._check_unsubmitted()
        self._batch_submit(submissions, previous_errors)