Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
assert path or plugin_name, "path is required if plugin_name is empty"
if not plugin_name:
plugin_name = _plugin_name_from_path(path)
if plugin_name:
try:
if plugin_data:
self._install_plugin_zip(plugin_name, plugin_data, update=update)
elif os.path.isfile(path):
self._install_plugin_file(path, update=update)
elif os.path.isdir(path):
self._install_plugin_dir(plugin_name, path, update=update)
except (OSError, IOError) as why:
log.error("Unable to copy plugin '%s' to %r: %s" % (plugin_name, self.plugins_directory, why))
return
if not update:
try:
installed_plugin = self._load_plugin_from_directory(plugin_name, self.plugins_directory)
if not installed_plugin:
raise RuntimeError("Failed loading newly installed plugin %s" % plugin_name)
except Exception as e:
log.error("Unable to load plugin '%s': %s", plugin_name, e)
self._remove_plugin(plugin_name)
else:
self.plugin_installed.emit(installed_plugin, False)
else:
self.plugin_updated.emit(plugin_name, False)
def on_refresh_access_token_finished(self, callback, data, http, error):
access_token = None
try:
if error:
log.error("OAuth: access_token refresh failed: %s", data)
if http.attribute(QNetworkRequest.HttpStatusCodeAttribute) == 400:
response = load_json(data)
if response["error"] == "invalid_grant":
self.forget_refresh_token()
else:
self.set_access_token(data["access_token"], data["expires_in"])
access_token = data["access_token"]
except Exception as e:
log.error('OAuth: Unexpected error handling access token response: %r', e)
finally:
callback(access_token)
def _releases_json_loaded(self, response, reply, error, callback=None):
"""Processes response from specified website api query."""
if error:
log.error(_("Error loading Picard releases list: {error_message}").format(error_message=reply.errorString(),))
if self._show_always:
QMessageBox.information(
self._parent,
_("Picard Update"),
_("Unable to retrieve the latest version information from the website.\n(https://{url}{endpoint})").format(
url=PLUGINS_API['host'],
endpoint=PLUGINS_API['endpoint']['releases'],
),
QMessageBox.Ok, QMessageBox.Ok)
else:
if response and 'versions' in response:
self._available_versions = response['versions']
else:
self._available_versions = {}
for key in self._available_versions:
log.debug("Version key '{version_key}' --> {version_information}".format(
def _load(self, filename):
log.debug("Loading file %r", filename)
file = MP4(encode_filename(filename))
tags = file.tags
if tags is None:
file.add_tags()
metadata = Metadata()
if not tags:
# MPEG-4 file in an mov container is unsupported and is one of
# the formats which returns a positive score in guess_format method
# If we are unable to add tags, it is not a supported mp4 file
# remove it and log an error
log.error("Unable to load tags for file {}".format(self))
self.remove()
return metadata
for name, values in tags.items():
if name in self.__text_tags:
for value in values:
metadata.add(self.__text_tags[name], value)
elif name in self.__bool_tags:
metadata.add(self.__bool_tags[name], values and '1' or '0')
elif name in self.__int_tags:
for value in values:
metadata.add(self.__int_tags[name], unicode(value))
elif name in self.__freeform_tags:
for value in values:
value = value.strip("\x00").decode("utf-8", "replace")
metadata.add(self.__freeform_tags[name], value)
def metadata_error(album_id, metadata_element):
log.error("%s: %r: Missing '%s' in release metadata.",
PLUGIN_NAME, album_id, metadata_element)
moves.add((entry.path, new_file_path))
break # we are done with this file
except OSError as why:
log.error("Failed to scan %r: %s", old_path, why)
return
for old_file_path, new_file_path in moves:
# FIXME we shouldn't do this from a thread!
if self.tagger.files.get(decode_filename(old_file_path)):
log.debug("File loaded in the tagger, not moving %r", old_file_path)
continue
log.debug("Moving %r to %r", old_file_path, new_file_path)
try:
shutil.move(old_file_path, new_file_path)
except OSError as why:
log.error("Failed to move %r to %r: %s", old_file_path,
new_file_path, why)
def _request_finished(self, callback, document, http, error):
try:
if error:
log.error("%r", http.errorString())
else:
try:
self._parse_versions(document)
except BaseException:
error = True
log.error(traceback.format_exc())
finally:
self.loaded = True
callback()
if "totaldiscs" in file.tags:
continue
name = "totaldiscs"
elif name == "metadata_block_picture":
try:
image = mutagen.flac.Picture(base64.standard_b64decode(value))
coverartimage = TagCoverArtImage(
file=filename,
tag=name,
types=types_from_id3(image.type),
comment=image.desc,
support_types=True,
data=image.data,
)
except (CoverArtImageError, TypeError, ValueError, mutagen.flac.error) as e:
log.error('Cannot load image from %r: %s' % (filename, e))
else:
metadata.images.append(coverartimage)
continue
elif name in self.__translate:
name = self.__translate[name]
metadata.add(name, value)
if self._File == mutagen.flac.FLAC:
for image in file.pictures:
try:
coverartimage = TagCoverArtImage(
file=filename,
tag='FLAC/PICTURE',
types=types_from_id3(image.type),
comment=image.desc,
support_types=True,
data=image.data,