Open Sophira opened 8 years ago
Thanks for diving into this. As a tl;dr - a workaround is to change line 78 in livestreamer/src/livestreamer/stream/hls_playlist.py from
bandwidth = int(bandwidth)
to
bandwidth = 0 if bandwitdh == 'None' else int(bandwidth)
Edit: Corrected typo.
That's correct (although you have a small typo in your fix: bandwith
should be bandwidth
), but this isn't really livestreamer's fault as such, so I'm dubious about whether an official patch in livestreamer is warranted. I was actually thinking of reporting this upstream myself since there hadn't been a reply here before yours.
(And for anybody coming here for @ldoddema's tl;dr: Note that even after making that change, you may get a "Unable to open URL
" error for some quality settings, as explained in my initial post. If that happens to you, try using a different quality.)
Okay, I've reported this upstream. For any Twitch staff reading this, the bug report is http://www.twitch.tv/bug_reports/61249 . (Note that nobody except Twitch staff and me will be able to view the report at that link.)
I gave full technical details, so hopefully it'll be fixed upstream soon!
(And apologies to Twitch staff; I didn't realise that the bug report would be submitted in Markdown, so there's some really big text in the middle of the bug report and the report is on the whole rather haphazardly laid out. Sorry! I'll know for next time.)
The code I posted should only be used as a momentary workaround, if at all ;)
A better patch would be to ignore malformed streams in the playlist and move ahead with the valid ones. Maybe issue a warning.
This seems to be more of a problem with Twitch than livestreamer, but I figure that you guys will probably be able to report this upstream more accurately (and with more authority) than me, and it's possible that you might be able to work around it.
The problem can be observed by taking a look at, for example, http://www.twitch.tv/mike89sda/v/29976577 in livestreamer. On an unpatched livestreamer 1.12.2 (on Windows 7 via Cygwin), this is the result:
The problem turns out that livestreamer can't parse the HLS playlist Twitch returns for this URL. In some cases Twitch is returning the string "None" for the
bandwidth
value rather than an integer, which causes an error ("Failed to parse playlist: invalid literal for int() with base 10: 'None'") to be thrown. (And then caught by_get_hls_streams
inplugins/twitch.py
; I think this error should probably show up to the user somewhere, but that's a different issue.)On Twitch's end, the problem appears to be that the streams aren't generated properly and don't exist, even though they show up in the playlist. Trying to play the streams in question with livestreamer (after patching
stream/hls_playlist.py
so that a value of "None" for the bandwidth is regarded as 0) reveals the problem:Twitch's Web interface is also unable to load these invalid streams.
Streams that have valid entries in the playlist are able to be streamed without issue after patching (though not before then):
Is it worth putting the patch for this into livestreamer? If so, I can submit a pull request. OTOH, this is definitely a Twitch bug and not really livestreamer's fault, so...