mps-youtube / pafy

Python library to download YouTube content and retrieve metadata
1.38k stars 314 forks source link

IndexError: list index out of range @ pafy/playlist.py", line 145 #164

Closed juanrubio closed 7 years ago

juanrubio commented 7 years ago

Hi!,

I'm getting this (Version 0.5.2)

Traceback (most recent call last):
  File "/home/joni/temp/lib/python2.7/site-packages/tizyoutubeproxy.py", line 284, in enqueue_audio_mix
    playlist = yt_video.mix
  File "/usr/local/lib/python2.7/dist-packages/pafy/backend_shared.py", line 332, in mix
    self._mix_pl = get_playlist2("RD" + self.videoid)
  File "/usr/local/lib/python2.7/dist-packages/pafy/playlist.py", line 228, in get_playlist2
    return Playlist(playlist_url, basic, gdata, size, callback)
  File "/usr/local/lib/python2.7/dist-packages/pafy/playlist.py", line 145, in __init__
    pl = allinfo['items'][0]
IndexError: list index out of range

With this code (arg = hdGwTxPvbU4)

            yt_video = pafy.new(arg)
            playlist = yt_video.mix
ids1024 commented 7 years ago

This probably means there is no such mix (although pafy should probably handle it better). What video was this for?

juanrubio commented 7 years ago

I believe this was for this video:

[Youtube] [Connected] : 'hdGwTxPvbU4'.
   Vevo-DUCK : Sia &  Rihanna ft. David Guetta  - Beautiful People [Lyrics]
     YouTube Id : hdGwTxPvbU4
     Duration : 00:06:00
     File Format : webm
     Bitrate : 160k
     Size : 5 MiB
     View Count : 397010
     Description : Sia &  Rihanna ft. David Guetta  - Beautiful People [Lyrics] || New Song 2016Thanks for Watching: Beautiful People by David Gue
     Published : 2017-01-07 16:50:40
     Opus Stream : 2 Ch, 48000 Hz
     2 Ch, 48 KHz, 16:s:l 

I've tried again now and It appears to work, but it looks like an intermittent condition.

juanrubio commented 7 years ago

By the way, any chances of releasing a new version of pafy with #162's fix?

I'm integrating pafy within tizonia and I would love to have that fix in pypi (i.e. I can't release the new version of tizonia until pafy is updated there).

ids1024 commented 7 years ago

I just released 0.5.3.

juanrubio commented 7 years ago

Thanks!, unfortunately, I'm getting this error while upgrading to 0.5.3

sudo -H pip install pafy --upgrade
Collecting pafy
  Downloading pafy-0.5.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-JXZqSh/pafy/setup.py", line 13, in <module>
        from pafy import __version__
      File "pafy/__init__.py", line 7, in <module>
        from .pafy import new
      File "pafy/pafy.py", line 40, in <module>
        from .util import call_gdata
      File "pafy/util.py", line 18, in <module>
        not_utf8_environment = mswin or "UTF-8" not in sys.stdout.encoding
    TypeError: argument of type 'NoneType' is not iterable

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-JXZqSh/pafy/
ids1024 commented 7 years ago

It's odd for that not to be defined.

I'm not sure exactly how Boost.Python works. Is it using a standard cpython interpreter? What version of Python?

kyrias commented 7 years ago

Hmm, trying to build a package in a chroot I'm getting the same issue. Setting PYTHONIOENCODING manually works though. Weird.

ids1024 commented 7 years ago

Hm, I guess Python must set .encoding to None when the system's locale is not set. It should be possible to work around it; should it default to unicode? I guess ascii is probably a more compatible option...

I really wish UTF-8 could just be assumed. Things would be so much easier.

kyrias commented 7 years ago

In this case I had explicitly set the locale. I think it's just py2 being weird about encodings though.

ids1024 commented 7 years ago

It seems it is a problem (#165). I've pushed a fix and made a bugfix release.

@juanrubio Does it work for you now?

juanrubio commented 7 years ago

Thanks Ian. I does work great now.