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

Fixed adding stream to playlist #41

Closed

Conversation

andersbll
Copy link

Hi there, great work porting Sonata to Python 3. It seems to be pretty solid by now!

I recently noticed that I was unable to add music streams to the playlist. The problem is caused by urllib returning bytes instead of a string. Here is a quick fix that seems to work for links to binary streams as well as playlist files.

@multani
Copy link
Owner

multani commented Jul 1, 2013

Hi Anders, thanks for the fix!

Actually, there's already a pull request opened to fix this, have a look at #34. It seems you went for the same kind of solution, and I already raised some concerns there, can you have a look? I believe @Mic92 is not working on this at the moment, if you can get something to work, that would be awesome!

@Mic92
Copy link

Mic92 commented Jul 1, 2013

I began to write a playlist parser, but have never actually finish it. Maybe it helps a little. You might want write unittests for the various playlist formats... https://gist.github.com/Mic92/5902534 Good luck!

@andersbll
Copy link
Author

Oops! :)

The fix proposed in PR #34 does not work as intended because urllib.request always returns bytes. Therefore type(f) is bytes will always return true.

@multani: regarding your concerns: I'm a bit skeptical about the MIME type detection approach. Even with MIME type detection we would not be sure to get it right because the servers might return incorrect types. E.g. one of my URL points to a .pls playlist which is detected as application/octet-stream. I have an alternative proposal: Try decoding the response from urllib.response as a string. If the decoding fails, the data is binary and the original URL should be added to the playlist. If the decoding succeeds, search for occurrences of 'http://' and 'ftp://'. If these strings occur, parse the data as a playlist as we currently do.

@Mic92: Thanks for gist! When I first thought I had fixed the problem I did not imagine it being so complex! In fact I was pretty delighted by the b'\0' search hack! :)

@multani
Copy link
Owner

multani commented Jul 2, 2013

Yes, this can be a bit tricky.

  • urllib.request does indeed always return bytes; your`b'\0'`` is a nice hack, although there can be cases where it fails because a text file (a playlist) will contain this character. Maybe it is good enough anyway?
  • can you elaborate how and in which case you get and application/octet-stream? Are you using @Mic92's code to detect this or something else? Where is this MIME type coming from?
  • as for decoding the input stream, for it to work, you will need to have a look at the HTTP header ("Content-Type"?) sent by the server (if it's an HTTP request) to know which encoding to decode the data from.

@Mic92: how do you think your approache in your Gist is going to be?

(On a side note, the current code is currently broken with playlists longer than 4000 bytes I believe... -_- )

On Mon, Jul 01, 2013 at 11:09:34AM -0700, Anders Boesen Lindbo Larsen wrote:

Oops! :)

The fix proposed in PR #34 does not work as intended because urllib.request always returns bytes. Therefore type(f) is bytes will always return true.

@multani: regarding your concerns: I'm a bit skeptical about the MIME type detection approach. Even with MIME type detection we would not be sure to get it right because the servers might return incorrect types. E.g. one of my URL points to a .pls playlist which is detected as application/octet-stream. I have an alternative proposal: Try decoding the response from urllib.response as a string. If the decoding fails, the data is binary and the original URL should be added to the playlist. If the decoding succeeds, search for occurrences of 'http://' and 'ftp://'. If these strings occur, parse the data as a playlist as we currently do.

@Mic92: Thanks for gist! When I first thought I had fixed the problem I did not imagine it being so complex! In fact I was pretty delighted by the b'\0' search hack! :)


Reply to this email directly or view it on GitHub:
#41 (comment)

@andersbll
Copy link
Author

I think the current solution is good enough; it is short and has worked fine for me so far. However, if this is not the case for everyone it should definitely be fixed!

I have looked into the MIME type detection problem I mentioned earlier: The problem is caused by the HTTP server that reports a wrong MIME type in the header. If I use mimetypes.guess_type() it works fine. This does not mean that mimetypes.guess_type() is flawless as it fails for URLs without file extensions. In these cases we would have to fall back to the current solution.

@multani
Copy link
Owner

multani commented Jul 4, 2013

Hum, fair enough.

Let's do something about this fix then. Would you considerate doing something slightly different, as I udnerstood you mentionned above: I think we can probably get rid of misc.is_binary() and try as you said to decode the value received. Then, if it succeed, try to guess the content as a playlist, and if it failed, supposed it is a binary file and add it to MPD. Basically, the code would remove the condition on misc.is_binary() and your decode, and replace this by a try/except around f.decode() on UnicodeDecodeError, with the current "binary" code path in the except block, and the alternative "playlist" code path in the else block. Do you think that would be OK?

Also, I need some information on how to reproduce this issue in the first place. Can you describe me which steps you are doing to face this bug? I tried several things and I'm hitting other bugs in the meanwhile -_- So I can test your fix after.

Thanks!

@andersbll
Copy link
Author

Ok, I will revise the PR over the weekend!

Regarding the bug: I add a new stream in Sonata and enter "http://kcrw.ic.llnwd.net/stream/kcrw_music" as Stream URL. mimetypes.guess_type returns None for this URL.

@Mic92
Copy link

Mic92 commented Jul 10, 2013

Maybe the solution the original authors chosen, wasn't that bad. This mimetype things just seems to breaks to often on the internet. The only thing I have to note, that you shouldn't add all songs, you find in a radio playlist. Radio stations often put multiple formats of the same stream into 1 playlist. Instead you should add the first playable stream to mpd. This behaviour different from what a user expect, if he/she add local playlist.

@multani
Copy link
Owner

multani commented Aug 9, 2013

Hi Anders,

any progress on this? If not and you think it's acceptable, I'll probably just implement what I said in #41 (comment) and propose it as a fix.

multani added a commit that referenced this pull request Aug 11, 2013
@multani multani mentioned this pull request Aug 11, 2013
@multani
Copy link
Owner

multani commented Aug 11, 2013

@andersbll @Mic92 I implemented in 60cd4c3 a fix, inspired by what as been done by @andersbll in this pull request, and what we discussed here. I tested it with a few use cases, and it seems to work.
Can you have a look at the branch fix/41-add-stream to see if it works OK?

(On a side note, I also did after some cleanups of this portion of the code, hopefully it's a bit better now. See branch refactor/stream-parsing)

@multani multani closed this in 60cd4c3 Jan 8, 2014
multani added a commit that referenced this pull request Jan 8, 2014
Merge branch 'refactor/stream-parsing'

Conflicts:
	CHANGELOG

Fix #34
Fix #41
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Sep 14, 2019
1.7b1 (2016-01-31)
------------------

New features
''''''''''''

    * redirect to the localized Wikipedia according to the user's local,
      instead of redirecting to the English one.
      multani/sonata#61
    * add "Shuffle by album"
      multani/sonata#59
    * repeat single song (Corentin Néau)
      multani/sonata#95


Bug fixes
'''''''''

    * fix crashs on Gtk.TextView when updating the lyrics of a song
    * Fix streams parsing:
      multani/sonata#41
      multani/sonata#38
    * fix withdrawn mode by fixing incorrect usage of threads and Gtk
      eco-system
    * choosing a local artwork wasn't working anymore
    * fix artwork caching
    * keep the selected tab when hiding/showing Sonata using the tray icon
    * correctly handle tracks without a definitely reasonable track or disc
      value (Peter Helbing)
      multani/sonata#74
    * fix translation of of Glade dialogs (Peter Helbing)
      multani/sonata#75
    * fix opening the About dialog (based on Rocus van Oosten report).
    * fix refreshing profiles upon connections add/delete (Corentin Néau)
      multani/sonata#92
    * fix update of cover and text in fullscreen mode (Corentin Néau)
      multani/sonata#93

Internal changes
''''''''''''''''

    * slightly better performance when updating the library
    * threading improvements:

      - use GIO instead of a thread to download drag-and-droped covers
      - remove the MPD from a dedicated thread. It works as good (if not
        better) as before since the threaded code was poorly written anyway and
        rendered the additionnal basically useless. This move is not definitive
        but something better will probably come up some day.

    * Looking for covers isn't as filesystem expensive as before, but it
      doesn't check for multiple possible cases in the cover name anymore.


1.7a2 (2013-11-26)
------------------

New features
''''''''''''

    * Download bigger covers from Last.fm
    * Centering the current song using Ctrl+i now also selects the current song
    * Use Transifex as a translation plateform. See
      https://www.transifex.com/projects/p/sonata/
    * Update translations:

        - Russian (thanks Stas!)
        - Ukrainian (thanks Stas!)
        - French (thanks Jon!)

Bug fixes
'''''''''

    * Fix search in library (using a specific filter or the 'everything' filter)
    * Fix scrobbling to Last.fm
    * Scrolling with the mouse wheel on the tray icon correctly changes the volume
    * Some lyrics from LyricsWiki redirects to another page. The plugin now
      follows those redirect to find the actual lyrics.
    * Fix multiple issues related to drag-and-drop of songs in the current playlist
    * Fix error while using Sonata's command line interface
    * Fix filtering songs in the current playlist
    * Fix DND of custom artwork images in the main window
    * Fix breadcrumb icon in the library while browsing an album while in Artist view
    * Fix saving the visibility flag of tabs: multani/sonata#45
    * Fix hiding/showing the main window even if it's not the active widget:
      multani/sonata#43
    * Deleting a track doesn't toggle the filter bar anymore in the current playlist.
    * Better support for MPD 0.18

Internal changes
''''''''''''''''

    * Simplified the `current` module. It should also now use less memory than before.
    * Provide a new GObject signal to notify on artwork change and artwork reset.


1.7a1 (2013-02-08)
------------------

New features
''''''''''''

    * Fetch covers from Last.fm instead of Rhapsody.com
    * Custom plugins are now stored along the configuration file in ~/.config/sonata/plugins/
    * Switch to Python 3 and Gtk 3 (Jörg Thalheim & Adam Dane)
    * More items in the tray menu (Kirill Lashuk)
    * Better fullscreen support (Kirill Lashuk)
    * Toggle fullscreen from the command line (Daniel)
    * Support MPD's "consume" mode (Anton Lashkov)
    * Use more default icons in the context menus (Anton Lashkov)
    * Load only the most recent of plugins with the same names

Bug fixes
'''''''''

    * Fix population of the "Save to playlist" menu (Zhihao Yuan)
    * Prevent multiple entries and improve art search with multi-CD albums (Kirill Lashuk)
    * Fixes weird show up if Sonata is not on the current workspace (Kirill Lashuk)
    * Scrobble after seeking to the beginning (Kirill Lashuk)
    * The lyricswiki plugin should now work again (Jonathan Ballet)
    * Fix UI status after reconnection to MPD (Jonathan Ballet)
    * Fix crash when searching the library (Kirill Lashuk)

Internal changes
''''''''''''''''

    * Simpler API for cover fetching plugins
    * Lot of code cleanup and internal changes
    * Removed Sugar UI support
    * Use Glade files to describe the interface and GtkBuilder to build the interface
    * More systematic configuration file management
    * High-level access to MPD's command results
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Sep 15, 2019
1.7b1 (2016-01-31)
------------------

New features
''''''''''''

    * redirect to the localized Wikipedia according to the user's local,
      instead of redirecting to the English one.
      multani/sonata#61
    * add "Shuffle by album"
      multani/sonata#59
    * repeat single song (Corentin Néau)
      multani/sonata#95


Bug fixes
'''''''''

    * fix crashs on Gtk.TextView when updating the lyrics of a song
    * Fix streams parsing:
      multani/sonata#41
      multani/sonata#38
    * fix withdrawn mode by fixing incorrect usage of threads and Gtk
      eco-system
    * choosing a local artwork wasn't working anymore
    * fix artwork caching
    * keep the selected tab when hiding/showing Sonata using the tray icon
    * correctly handle tracks without a definitely reasonable track or disc
      value (Peter Helbing)
      multani/sonata#74
    * fix translation of of Glade dialogs (Peter Helbing)
      multani/sonata#75
    * fix opening the About dialog (based on Rocus van Oosten report).
    * fix refreshing profiles upon connections add/delete (Corentin Néau)
      multani/sonata#92
    * fix update of cover and text in fullscreen mode (Corentin Néau)
      multani/sonata#93

Internal changes
''''''''''''''''

    * slightly better performance when updating the library
    * threading improvements:

      - use GIO instead of a thread to download drag-and-droped covers
      - remove the MPD from a dedicated thread. It works as good (if not
        better) as before since the threaded code was poorly written anyway and
        rendered the additionnal basically useless. This move is not definitive
        but something better will probably come up some day.

    * Looking for covers isn't as filesystem expensive as before, but it
      doesn't check for multiple possible cases in the cover name anymore.


1.7a2 (2013-11-26)
------------------

New features
''''''''''''

    * Download bigger covers from Last.fm
    * Centering the current song using Ctrl+i now also selects the current song
    * Use Transifex as a translation plateform. See
      https://www.transifex.com/projects/p/sonata/
    * Update translations:

        - Russian (thanks Stas!)
        - Ukrainian (thanks Stas!)
        - French (thanks Jon!)

Bug fixes
'''''''''

    * Fix search in library (using a specific filter or the 'everything' filter)
    * Fix scrobbling to Last.fm
    * Scrolling with the mouse wheel on the tray icon correctly changes the volume
    * Some lyrics from LyricsWiki redirects to another page. The plugin now
      follows those redirect to find the actual lyrics.
    * Fix multiple issues related to drag-and-drop of songs in the current playlist
    * Fix error while using Sonata's command line interface
    * Fix filtering songs in the current playlist
    * Fix DND of custom artwork images in the main window
    * Fix breadcrumb icon in the library while browsing an album while in Artist view
    * Fix saving the visibility flag of tabs: multani/sonata#45
    * Fix hiding/showing the main window even if it's not the active widget:
      multani/sonata#43
    * Deleting a track doesn't toggle the filter bar anymore in the current playlist.
    * Better support for MPD 0.18

Internal changes
''''''''''''''''

    * Simplified the `current` module. It should also now use less memory than before.
    * Provide a new GObject signal to notify on artwork change and artwork reset.


1.7a1 (2013-02-08)
------------------

New features
''''''''''''

    * Fetch covers from Last.fm instead of Rhapsody.com
    * Custom plugins are now stored along the configuration file in ~/.config/sonata/plugins/
    * Switch to Python 3 and Gtk 3 (Jörg Thalheim & Adam Dane)
    * More items in the tray menu (Kirill Lashuk)
    * Better fullscreen support (Kirill Lashuk)
    * Toggle fullscreen from the command line (Daniel)
    * Support MPD's "consume" mode (Anton Lashkov)
    * Use more default icons in the context menus (Anton Lashkov)
    * Load only the most recent of plugins with the same names

Bug fixes
'''''''''

    * Fix population of the "Save to playlist" menu (Zhihao Yuan)
    * Prevent multiple entries and improve art search with multi-CD albums (Kirill Lashuk)
    * Fixes weird show up if Sonata is not on the current workspace (Kirill Lashuk)
    * Scrobble after seeking to the beginning (Kirill Lashuk)
    * The lyricswiki plugin should now work again (Jonathan Ballet)
    * Fix UI status after reconnection to MPD (Jonathan Ballet)
    * Fix crash when searching the library (Kirill Lashuk)

Internal changes
''''''''''''''''

    * Simpler API for cover fetching plugins
    * Lot of code cleanup and internal changes
    * Removed Sugar UI support
    * Use Glade files to describe the interface and GtkBuilder to build the interface
    * More systematic configuration file management
    * High-level access to MPD's command results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants