Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def doReadDirectory(self, args):
root = args[1]
# Show status bar message
message = QtCore.QString(_(u"Reading directory %s ...") % root)
self.emit(QtCore.SIGNAL("statusBarMessage(const QString &)"), message)
# Read the directory listing
files = QtCore.QStringList()
for name in os.listdir(util.encode_filename(root)):
name = os.path.join(root, name)
if os.path.isdir(name):
self.readDirectory(name)
else:
files.append(QtCore.QString(util.decode_filename(name)))
if files:
self.emit(QtCore.SIGNAL("addFiles(const QStringList &)"), files)
def generate_moodbar_for_files(files, format, tagger):
"""Generate the moodfiles for a list of files in album mode."""
file_list = ['%s' % encode_filename(f.filename) for f in files]
for mood_file in file_list:
new_filename = os.path.join(os.path.dirname(
mood_file), '.' + os.path.splitext(os.path.basename(mood_file))[0] + '.mood')
# file format to make it compaitble with Amarok and hidden in linux
file_list_mood = ['%s' % new_filename]
if format in MOODBAR_COMMANDS \
and tagger.config.setting[MOODBAR_COMMANDS[format][0]]:
command = tagger.config.setting[MOODBAR_COMMANDS[format][0]]
options = tagger.config.setting[
MOODBAR_COMMANDS[format][1]].split(' ')
# tagger.log.debug('My debug >>> %s' % (file_list_mood))
tagger.log.debug(
'%s %s %s %s' % (command, decode_filename(' '.join(file_list)), ' '.join(options), decode_filename(' '.join(file_list_mood))))
check_call([command] + file_list + options + file_list_mood)
else:
def _save(self, filename, metadata):
log.debug("Saving file %r", filename)
file = MP4(encode_filename(self.filename))
tags = file.tags
if tags is None:
file.add_tags()
if config.setting["clear_existing_tags"]:
tags.clear()
for name, values in metadata.rawitems():
if name.startswith('lyrics:'):
name = 'lyrics'
if name in self.__r_text_tags:
tags[self.__r_text_tags[name]] = values
elif name in self.__r_bool_tags:
tags[self.__r_bool_tags[name]] = (values[0] == '1')
elif name in self.__r_int_tags:
try:
def drop_urls(urls, target):
files = []
new_files = []
for url in urls:
log.debug("Dropped the URL: %r", url.toString(QtCore.QUrl.RemoveUserInfo))
if url.scheme() == "file" or not url.scheme():
filename = os.path.normpath(os.path.realpath(url.toLocalFile().rstrip("\0")))
file = BaseTreeView.tagger.files.get(filename)
if file:
files.append(file)
elif os.path.isdir(encode_filename(filename)):
BaseTreeView.tagger.add_directory(filename)
else:
new_files.append(filename)
elif url.scheme() in ("http", "https"):
path = url.path()
match = re.search(r"/(release|recording)/([0-9a-z\-]{36})", path)
if match:
entity = match.group(1)
mbid = match.group(2)
if entity == "release":
BaseTreeView.tagger.load_album(mbid)
elif entity == "recording":
BaseTreeView.tagger.load_nat(mbid)
if files:
BaseTreeView.tagger.move_files(files, target)
if new_files:
def write(self):
lines = []
for track in self.tracks:
num = track.index
for line in track:
indent = 0
if num > 0:
if line[0] == "TRACK":
indent = 2
elif line[0] != "FILE":
indent = 4
line2 = u" ".join([self.quote(s) for s in line])
lines.append(" " * indent + line2.encode("UTF-8") + "\n")
with open(encode_filename(self.filename), "wt") as f:
f.writelines(lines)
def _save(self, filename, metadata):
if config.setting['aac_save_ape']:
super()._save(filename, metadata)
elif config.setting['remove_ape_from_aac']:
try:
mutagen.apev2.delete(encode_filename(filename))
except BaseException:
log.exception('Error removing APEv2 tags from %s', filename)
def _save(self, filename, metadata):
if config.setting['ac3_save_ape']:
super()._save(filename, metadata)
elif config.setting['remove_ape_from_ac3']:
try:
mutagen.apev2.delete(encode_filename(filename))
except BaseException:
log.exception('Error removing APEv2 tags from %s', filename)
def _next_filename(self, filename, counters):
if counters[filename]:
new_filename = "%s (%d)" % (decode_filename(filename), counters[filename])
else:
new_filename = filename
counters[filename] += 1
return encode_filename(new_filename)
def _load(self, filename):
self.log.debug("Loading file %r", filename)
file = self._File(encode_filename(filename), ID3=compatid3_dsf.CompatID3)
tags = file.tags or {}
# upgrade custom 2.3 frames to 2.4
for old, new in self.__upgrade.items():
if old in tags and new not in tags:
f = tags.pop(old)
tags.add(getattr(id3, new)(encoding=f.encoding, text=f.text))
metadata = Metadata()
for frame in tags.values():
frameid = frame.FrameID
if frameid in self.__translate:
name = self.__translate[frameid]
if frameid.startswith('T'):
for text in frame.text:
if text:
metadata.add(name, unicode(text))
elif frameid == 'COMM':
def load_info(self):
total = len(self.files)
if total == 1:
file = self.files[0]
info = []
info.append((_('Filename:'), file.filename))
if '~format' in file.orig_metadata:
info.append((_('Format:'), file.orig_metadata['~format']))
try:
size = os.path.getsize(encode_filename(file.filename))
if size < 1024:
size = '%d B' % size
elif size < 1024 * 1024:
size = '%0.1f kB' % (size / 1024.0)
else:
size = '%0.1f MB' % (size / 1024.0 / 1024.0)
info.append((_('Size:'), size))
except:
pass
if file.orig_metadata.length:
info.append((_('Length:'), format_time(file.orig_metadata.length)))
if '~#bitrate' in file.orig_metadata:
info.append((_('Bitrate:'), '%d kbps' % file.orig_metadata['~#bitrate']))
if '~#sample_rate' in file.orig_metadata:
info.append((_('Sample rate:'), '%d Hz' % file.orig_metadata['~#sample_rate']))
if '~#bits_per_sample' in file.orig_metadata: