Skip to content

Commit

Permalink
Quotes consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
zas committed Sep 24, 2023
1 parent 7a2112a commit d47e949
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 99 deletions.
64 changes: 32 additions & 32 deletions picard/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ class File(QtCore.QObject, Item):
FILE_INFO_TAGS = ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format')

comparison_weights = {
"title": 13,
"artist": 4,
"album": 5,
"length": 10,
"totaltracks": 4,
"releasetype": 14,
"releasecountry": 2,
"format": 2,
"isvideo": 2,
"date": 4,
'title': 13,
'artist': 4,
'album': 5,
'length': 10,
'totaltracks': 4,
'releasetype': 14,
'releasecountry': 2,
'format': 2,
'isvideo': 2,
'date': 4,
}

class PreserveTimesStatError(Exception):
Expand Down Expand Up @@ -213,7 +213,7 @@ def _set_error(self, error):
self.state = File.ERROR
if any_exception_isinstance(error, MutagenError):
self.error_type = FileErrorType.PARSER
self.error_append(_('The file failed to parse, either the file is damaged or has an unsupported file format.'))
self.error_append(_("The file failed to parse, either the file is damaged or has an unsupported file format."))
elif any_exception_isinstance(error, FileNotFoundError):
self.error_type = FileErrorType.NOTFOUND
elif any_exception_isinstance(error, PermissionError):
Expand Down Expand Up @@ -261,7 +261,7 @@ def _loading_finished(self, callback, result=None, error=None):
if alternative_file:
# Do not retry reloading exactly the same file format
if type(alternative_file) != type(self): # pylint: disable=unidiomatic-typecheck # noqa: E721
log.debug('Loading %r failed, retrying as %r', self, alternative_file)
log.debug("Loading %r failed, retrying as %r", self, alternative_file)
self.remove()
alternative_file.load(callback)
return
Expand All @@ -270,18 +270,18 @@ def _loading_finished(self, callback, result=None, error=None):
from picard.formats import supported_extensions
file_name, file_extension = os.path.splitext(self.base_filename)
if file_extension not in supported_extensions():
log.error('Unsupported media file %r wrongly loaded. Removing …', self)
log.error("Unsupported media file %r wrongly loaded. Removing …", self)
callback(self, remove_file=True)
return
else:
self.clear_errors()
self.state = self.NORMAL
postprocessors = []
if config.setting["guess_tracknumber_and_title"]:
if config.setting['guess_tracknumber_and_title']:
postprocessors.append(self._guess_tracknumber_and_title)
self._copy_loaded_metadata(result, postprocessors)
# use cached fingerprint from file metadata
if not config.setting["ignore_existing_acoustid_fingerprints"]:
if not config.setting['ignore_existing_acoustid_fingerprints']:
fingerprints = self.metadata.getall('acoustid_fingerprint')
if fingerprints:
self.set_acoustid_fingerprint(fingerprints[0])
Expand Down Expand Up @@ -382,22 +382,22 @@ def _save_and_rename(self, old_filename, metadata):
log.debug("File not saved because %s is stopping: %r", PICARD_APP_NAME, self.filename)
return None
new_filename = old_filename
if not config.setting["dont_write_tags"]:
if not config.setting['dont_write_tags']:
save = partial(self._save, old_filename, metadata)
if config.setting["preserve_timestamps"]:
if config.setting['preserve_timestamps']:
try:
self._preserve_times(old_filename, save)
except self.PreserveTimesUtimeError as why:
log.warning(why)
else:
save()
# Rename files
if config.setting["rename_files"] or config.setting["move_files"]:
if config.setting['rename_files'] or config.setting['move_files']:
new_filename = self._rename(old_filename, metadata, config.setting)
# Move extra files (images, playlists, etc.)
self._move_additional_files(old_filename, new_filename, config)
# Delete empty directories
if config.setting["delete_empty_dirs"]:
if config.setting['delete_empty_dirs']:
dirname = os.path.dirname(old_filename)
try:
emptydir.rm_empty_dir(dirname)
Expand All @@ -412,7 +412,7 @@ def _save_and_rename(self, old_filename, metadata):
except emptydir.SkipRemoveDir as why:
log.debug("Not removing empty directory: %s", why)
# Save cover art images
if config.setting["save_images_to_files"]:
if config.setting['save_images_to_files']:
self._save_images(os.path.dirname(new_filename), metadata)
return new_filename

Expand All @@ -436,7 +436,7 @@ def _saving_finished(self, result=None, error=None):
# conversions (e.g. for ID3v2.3)
config = get_config()
new_metadata = self._format_specific_copy(self.metadata, config.setting)
if config.setting["clear_existing_tags"]:
if config.setting['clear_existing_tags']:
self.orig_metadata = new_metadata
else:
self.orig_metadata.update(new_metadata)
Expand Down Expand Up @@ -474,7 +474,7 @@ def _script_to_filename(self, naming_format, file_metadata, file_extension, sett
config = get_config()
settings = config.setting
metadata = Metadata()
if settings["clear_existing_tags"]:
if settings['clear_existing_tags']:
# script_to_filename_with_metadata guarantees this is not modified
metadata = file_metadata
else:
Expand Down Expand Up @@ -538,15 +538,15 @@ def make_filename(self, filename, metadata, settings=None, naming_format=None):
settings = config.setting
if naming_format is None:
naming_format = get_file_naming_script(settings)
if settings["move_files"]:
new_dirname = settings["move_files_to"]
if settings['move_files']:
new_dirname = settings['move_files_to']
if not is_absolute_path(new_dirname):
new_dirname = os.path.join(os.path.dirname(filename), new_dirname)
else:
new_dirname = os.path.dirname(filename)
new_filename = os.path.basename(filename)

if settings["rename_files"] or settings["move_files"]:
if settings['rename_files'] or settings['move_files']:
new_filename = self._format_filename(new_dirname, new_filename, metadata, settings, naming_format)

new_path = os.path.join(new_dirname, new_filename)
Expand All @@ -572,7 +572,7 @@ def _save_images(self, dirname, metadata):
counters = Counter()
images = []
config = get_config()
if config.setting["save_only_one_front_image"]:
if config.setting['save_only_one_front_image']:
front = metadata.images.get_front_image()
if front:
images.append(front)
Expand All @@ -583,11 +583,11 @@ def _save_images(self, dirname, metadata):

def _move_additional_files(self, old_filename, new_filename, config):
"""Move extra files, like images, playlists…"""
if config.setting["move_files"] and config.setting["move_additional_files"]:
if config.setting['move_files'] and config.setting['move_additional_files']:
new_path = os.path.dirname(new_filename)
old_path = os.path.dirname(old_filename)
if new_path != old_path:
patterns_string = config.setting["move_additional_files_pattern"]
patterns_string = config.setting['move_additional_files_pattern']
patterns = self._compile_move_additional_files_pattern(patterns_string)
try:
moves = self._get_additional_files_moves(old_path, new_path, patterns)
Expand Down Expand Up @@ -705,8 +705,8 @@ def _tags_to_update(self, ignored_tags):
def update(self, signal=True):
if not (self.state == File.ERROR and self.errors):
config = get_config()
clear_existing_tags = config.setting["clear_existing_tags"]
ignored_tags = set(config.setting["compare_ignore_tags"])
clear_existing_tags = config.setting['clear_existing_tags']
ignored_tags = set(config.setting['compare_ignore_tags'])

for name in self._tags_to_update(ignored_tags):
new_values = self.format_specific_metadata(self.metadata, name, config.setting)
Expand Down Expand Up @@ -812,9 +812,9 @@ def state(self, state):

def column(self, column):
m = self.metadata
if column == "title" and not m["title"]:
if column == 'title' and not m['title']:
return self.base_filename
elif column == "covercount":
elif column == 'covercount':
return self.cover_art_description()
return m[column]

Expand Down
46 changes: 23 additions & 23 deletions picard/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ def compare_to_release_parts(self, release, weights):
parts = []

with self._lock.lock_for_read():
if "album" in self and "album" in weights:
if 'album' in self and 'album' in weights:
b = release['title']
parts.append((similarity2(self["album"], b), weights["album"]))
parts.append((similarity2(self['album'], b), weights['album']))

if "albumartist" in self and "albumartist" in weights:
a = self["albumartist"]
if 'albumartist' in self and 'albumartist' in weights:
a = self['albumartist']
b = artist_credit_from_node(release['artist-credit'])[0]
parts.append((similarity2(a, b), weights["albumartist"]))
parts.append((similarity2(a, b), weights['albumartist']))

if "totaltracks" in weights:
if 'totaltracks' in weights:
try:
a = int(self["totaltracks"])
a = int(self['totaltracks'])
if 'media' in release:
score = 0.0
for media in release['media']:
Expand All @@ -275,25 +275,25 @@ def compare_to_release_parts(self, release, weights):
else:
b = release['track-count']
score = trackcount_score(a, b)
parts.append((score, weights["totaltracks"]))
parts.append((score, weights['totaltracks']))
except (ValueError, KeyError):
pass

if "totalalbumtracks" in weights:
if 'totalalbumtracks' in weights:
try:
a = int(self["~totalalbumtracks"] or self["totaltracks"])
a = int(self['~totalalbumtracks'] or self['totaltracks'])
b = release['track-count']
score = trackcount_score(a, b)
parts.append((score, weights["totalalbumtracks"]))
parts.append((score, weights['totalalbumtracks']))
except (ValueError, KeyError):
pass

# Date Logic
date_match_factor = 0.0
if "date" in weights:
if "date" in release and release['date'] != '':
if 'date' in weights:
if 'date' in release and release['date'] != '':
release_date = release['date']
if "date" in self:
if 'date' in self:
metadata_date = self['date']
if release_date == metadata_date:
# release has a date and it matches what our metadata had exactly.
Expand Down Expand Up @@ -326,20 +326,20 @@ def compare_to_release_parts(self, release, weights):
parts.append((date_match_factor, weights['date']))

config = get_config()
if "releasecountry" in weights:
if 'releasecountry' in weights:
weights_from_preferred_countries(parts, release,
config.setting["preferred_release_countries"],
weights["releasecountry"])
config.setting['preferred_release_countries'],
weights['releasecountry'])

if "format" in weights:
if 'format' in weights:
weights_from_preferred_formats(parts, release,
config.setting["preferred_release_formats"],
weights["format"])
config.setting['preferred_release_formats'],
weights['format'])

if "releasetype" in weights:
if 'releasetype' in weights:
weights_from_release_type_scores(parts, release,
config.setting["release_type_scores"],
weights["releasetype"])
config.setting['release_type_scores'],
weights['releasetype'])

rg = QObject.tagger.get_release_group_by_id(release['release-group']['id'])
if release['id'] in rg.loaded_albums:
Expand Down
Loading

0 comments on commit d47e949

Please sign in to comment.