Current File Size?

Tags: #<Tag:0x00007f1c97636c98>

There’s internal variables for _filename, _dirname, _extension…
I’m contemplating a _filesize for viewing in a column.

The file/directory name values appear to be set in file.py… If I were to figure out how to do the same for filesize, would I need to do anything more elsewhere to make that a globally available internal variable so that I can get it, say in album.py or cluster.py, or should it ‘just work’?

1 Like

It should basically just work like e.g. the ~bitrate or other file variables. Only special case would be to also add it to File._saving_finished.

A few considerations:

  • This variable should also be used then in infodialog.py format_file_info
  • I would probably store the actual bytes here. In this case the column functions for file should probably take care of format it to a more readable value using the bytes2human.binary function
  • It would be nice to expose bytes2human functions also as tagger script functions then, so people can get formatted version of the size for display

Actually for feature requests like this best open a ticket on https://tickets.metabrainz.org/projects/PICARD/issues/ . And of course you are welcome to give this a go at implementing this!

2 Likes

I’ve got it here.
43 AM

Now figure out the right way to format the number.
Though I might like to see the actual number to the last digit too but it would be ridiculous with significantly larger files.

    elif column == '~filesize':
        size = len(self.filesize)
        if not size:
            return ''
        return '{:d}'.format(self.metadata.filesize() / (1024 * 1024)) + 'Mb'

Of course that doesn’t work. I’ve not progressed past brute force program like a parrot (copy/paste/edit) with variables completely, and that self thing is still not quite clear to me.

I’m still not getting something here. I can’t figure out the difference between the Cat # and Media, Size Columns. I added them the same way. Or for that matter, I’m not even seeing the difference from Album vs. Cluster viewing. Cluster will at least show the additional data with only the one track listing in the treeview.

It’ll hit me like a ton of bricks at some point. I just hope those bricks have already been dropped and are coming fast.

First, you are not seeing the file size on tracks because the byte size is file data, not track data. I have proposed a change in https://github.com/metabrainz/picard/pull/1409 to allow the file metadata be displayed for tracks.

from picard.util import bytes2human

print(bytes2human.binary(15500))

Will print “15.1 KiB”