Unable to use 'filething' to open files in mutagen.mp3.MP3

Bug #1629131 reported by Simon Lambourn
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mutagen (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

Hi, I have been trying to 'override' the file open parameters in the MP3 module to improve scan performance of a large music library, using python3-mutagen.

I can't get the supplied example to work: I get the following output:

$ python3 fileobj-gio.py
Traceback (most recent call last):
  File "fileobj-gio.py", line 130, in <module>
    print(mutagen.File(mutagen_file).pprint())
  File "/usr/lib/python3/dist-packages/mutagen/_file.py", line 239, in File
    with open(filename, "rb") as fileobj:
TypeError: invalid file: <__main__.GioMutagenFile object at 0x7f204fba4be0>

Looking through the code I can't see how it would treat a 'file-like object' any differently: it seems that open(filename,"rb") will always be called.

What I want to achieve is to understand if different buffering would improve elapsed time to scan large numbers of files. I was hoping to open the file first using different buffering parameter and pass a file-object to MP3, but the only documented way of doing this using open() is by passing the fileno() attribute of an already open file, which also fails on the open statement:

m=MP3(f.fileno())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/mutagen/_file.py", line 42, in __init__
    self.load(filename, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/mutagen/id3/__init__.py", line 1092, in load
    with open(filename, "rb") as fileobj:
OSError: [Errno 9] Bad file descriptor

Any advice would be most welcome on either how to fix the bug or other ways to improve scan performance. Thanks for your help.

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: python3-mutagen 1.31-1ubuntu1
ProcVersionSignature: Ubuntu 4.4.0-38.57-generic 4.4.19
Uname: Linux 4.4.0-38-generic x86_64
ApportVersion: 2.20.1-0ubuntu2.1
Architecture: amd64
CurrentDesktop: Unity
Date: Fri Sep 30 00:03:20 2016
Dependencies:

PackageArchitecture: all
SourcePackage: mutagen
UpgradeStatus: Upgraded to xenial on 2016-04-22 (160 days ago)

Revision history for this message
Simon Lambourn (simon-lambourn-o) wrote :
Revision history for this message
Christoph Reiter (lazka) wrote :

File like object support was added in 1.33.

You can get the newest version in my PPA if needed: https://launchpad.net/~lazka/+archive/ubuntu/ppa

If you find anything else please report it upstream: https://github.com/quodlibet/mutagen/issues

Changed in mutagen (Ubuntu):
status: New → Invalid
Revision history for this message
Simon Lambourn (simon-lambourn-o) wrote : Re: [Bug 1629131] Re: Unable to use 'filething' to open files in mutagen.mp3.MP3
Download full text (3.2 KiB)

Aaah! So much time spent trying different ways of getting this to work
and such a simple mistake!
Thank you for the quick reply, and I'm sorry to have bothered you with this.

Great package...
Simon

On Fri, 30 Sep 2016 at 08:35 Christoph Reiter <email address hidden>
wrote:

> File like object support was added in 1.33.
>
> You can get the newest version in my PPA if needed:
> https://launchpad.net/~lazka/+archive/ubuntu/ppa
>
> If you find anything else please report it upstream:
> https://github.com/quodlibet/mutagen/issues
>
> ** Changed in: mutagen (Ubuntu)
> Status: New => Invalid
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1629131
>
> Title:
> Unable to use 'filething' to open files in mutagen.mp3.MP3
>
> Status in mutagen package in Ubuntu:
> Invalid
>
> Bug description:
> Hi, I have been trying to 'override' the file open parameters in the
> MP3 module to improve scan performance of a large music library, using
> python3-mutagen.
>
> I can't get the supplied example to work: I get the following output:
>
> $ python3 fileobj-gio.py
> Traceback (most recent call last):
> File "fileobj-gio.py", line 130, in <module>
> print(mutagen.File(mutagen_file).pprint())
> File "/usr/lib/python3/dist-packages/mutagen/_file.py", line 239, in
> File
> with open(filename, "rb") as fileobj:
> TypeError: invalid file: <__main__.GioMutagenFile object at
> 0x7f204fba4be0>
>
> Looking through the code I can't see how it would treat a 'file-like
> object' any differently: it seems that open(filename,"rb") will always
> be called.
>
> What I want to achieve is to understand if different buffering would
> improve elapsed time to scan large numbers of files. I was hoping to
> open the file first using different buffering parameter and pass a
> file-object to MP3, but the only documented way of doing this using
> open() is by passing the fileno() attribute of an already open file,
> which also fails on the open statement:
>
> m=MP3(f.fileno())
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/python3/dist-packages/mutagen/_file.py", line 42, in
> __init__
> self.load(filename, *args, **kwargs)
> File "/usr/lib/python3/dist-packages/mutagen/id3/__init__.py", line
> 1092, in load
> with open(filename, "rb") as fileobj:
> OSError: [Errno 9] Bad file descriptor
>
> Any advice would be most welcome on either how to fix the bug or other
> ways to improve scan performance. Thanks for your help.
>
> ProblemType: Bug
> DistroRelease: Ubuntu 16.04
> Package: python3-mutagen 1.31-1ubuntu1
> ProcVersionSignature: Ubuntu 4.4.0-38.57-generic 4.4.19
> Uname: Linux 4.4.0-38-generic x86_64
> ApportVersion: 2.20.1-0ubuntu2.1
> Architecture: amd64
> CurrentDesktop: Unity
> Date: Fri Sep 30 00:03:20 2016
> Dependencies:
>
> PackageArchitecture: all
> SourcePackage: mutagen
> UpgradeStatus: Upgraded to xenial on 2016-04-22 (160 days ago)
>
> To manage notifications about this bug go to:
>
> https://bugs.launchpad.net/ubuntu/+s...

Read more...

Revision history for this message
Christoph Reiter (lazka) wrote :

No problem. The docs should have a note mentioning when it was introduced I guess.

Revision history for this message
Simon Lambourn (simon-lambourn-o) wrote :

Christoph,
Don't worry - it was an interesting exercise. I've upgraded from your
PPA, and I look forward to trying it out.
Simon

On Fri, 30 Sep 2016 at 10:01 Christoph Reiter <email address hidden>
wrote:

> No problem. The docs should have a note mentioning when it was
> introduced I guess.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1629131
>
> Title:
> Unable to use 'filething' to open files in mutagen.mp3.MP3
>
> Status in mutagen package in Ubuntu:
> Invalid
>
> Bug description:
> Hi, I have been trying to 'override' the file open parameters in the
> MP3 module to improve scan performance of a large music library, using
> python3-mutagen.
>
> I can't get the supplied example to work: I get the following output:
>
> $ python3 fileobj-gio.py
> Traceback (most recent call last):
> File "fileobj-gio.py", line 130, in <module>
> print(mutagen.File(mutagen_file).pprint())
> File "/usr/lib/python3/dist-packages/mutagen/_file.py", line 239, in
> File
> with open(filename, "rb") as fileobj:
> TypeError: invalid file: <__main__.GioMutagenFile object at
> 0x7f204fba4be0>
>
> Looking through the code I can't see how it would treat a 'file-like
> object' any differently: it seems that open(filename,"rb") will always
> be called.
>
> What I want to achieve is to understand if different buffering would
> improve elapsed time to scan large numbers of files. I was hoping to
> open the file first using different buffering parameter and pass a
> file-object to MP3, but the only documented way of doing this using
> open() is by passing the fileno() attribute of an already open file,
> which also fails on the open statement:
>
> m=MP3(f.fileno())
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/python3/dist-packages/mutagen/_file.py", line 42, in
> __init__
> self.load(filename, *args, **kwargs)
> File "/usr/lib/python3/dist-packages/mutagen/id3/__init__.py", line
> 1092, in load
> with open(filename, "rb") as fileobj:
> OSError: [Errno 9] Bad file descriptor
>
> Any advice would be most welcome on either how to fix the bug or other
> ways to improve scan performance. Thanks for your help.
>
> ProblemType: Bug
> DistroRelease: Ubuntu 16.04
> Package: python3-mutagen 1.31-1ubuntu1
> ProcVersionSignature: Ubuntu 4.4.0-38.57-generic 4.4.19
> Uname: Linux 4.4.0-38-generic x86_64
> ApportVersion: 2.20.1-0ubuntu2.1
> Architecture: amd64
> CurrentDesktop: Unity
> Date: Fri Sep 30 00:03:20 2016
> Dependencies:
>
> PackageArchitecture: all
> SourcePackage: mutagen
> UpgradeStatus: Upgraded to xenial on 2016-04-22 (160 days ago)
>
> To manage notifications about this bug go to:
>
> https://bugs.launchpad.net/ubuntu/+source/mutagen/+bug/1629131/+subscriptions
>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.