Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICARD-1685 : Add ~filesize variable #2361

Merged
merged 10 commits into from
Jan 18, 2024
8 changes: 7 additions & 1 deletion picard/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
normpath,
thread,
tracknum_and_title_from_filename,
encode_filename,
)
from picard.util.filenaming import (
get_available_filename,
Expand Down Expand Up @@ -132,7 +133,7 @@ class File(QtCore.QObject, Item):

EXTENSIONS = []

FILE_INFO_TAGS = ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format')
FILE_INFO_TAGS = ('~bitrate', '~sample_rate', '~channels', '~bits_per_sample', '~format', '~filesize')

comparison_weights = {
'title': 13,
Expand Down Expand Up @@ -760,6 +761,11 @@ def can_view_info(self):
return True

def _info(self, metadata, file):
try:
size = os.path.getsize(encode_filename(self.filename))
metadata['~filesize'] = size
nullHawk marked this conversation as resolved.
Show resolved Hide resolved
except BaseException:
nullHawk marked this conversation as resolved.
Show resolved Hide resolved
pass
if hasattr(file.info, 'length'):
metadata.length = int(file.info.length * 1000)
if hasattr(file.info, 'bitrate') and file.info.bitrate:
Expand Down
6 changes: 2 additions & 4 deletions picard/ui/infodialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,10 @@ def format_file_info(file_):
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 '~filesize' in file_.orig_metadata:
size = file_.orig_metadata['~filesize']
nullHawk marked this conversation as resolved.
Show resolved Hide resolved
nullHawk marked this conversation as resolved.
Show resolved Hide resolved
sizestr = "%s (%s)" % (bytes2human.decimal(size), bytes2human.binary(size))
info.append((_("Size:"), sizestr))
except BaseException:
pass
if file_.orig_metadata.length:
info.append((_("Length:"), format_time(file_.orig_metadata.length)))
if '~bitrate' in file_.orig_metadata:
Expand Down
1 change: 1 addition & 0 deletions picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class MainPanel(QtWidgets.QSplitter):
(N_("Catalog No."), 'catalognumber'),
(N_("Barcode"), 'barcode'),
(N_("Media"), 'media'),
(N_("Size"), '~filesize'),
(N_("Genre"), 'genre'),
(N_("Fingerprint status"), '~fingerprint'),
(N_("Date"), 'date'),
Expand Down
1 change: 1 addition & 0 deletions test/formats/test_vorbis.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class FLACTest(CommonVorbisTests.VorbisTestCase):
'~channels': '2',
'~sample_rate': '44100',
'~format': 'FLAC',
'~filesize':'6546'
nullHawk marked this conversation as resolved.
Show resolved Hide resolved
}
unexpected_info = ['~video']

Expand Down
Loading