pythonpytubeyoutube-channels

Pytube Channel video_urls is does not working


I want to scrape a youtube channel with pytube Channel but I get an index error because I got zero URLs. Anything else is working well just video_urls is not working.

my code:

c = Channel("https://www.youtube.com/c/BuildEmpire")
print(f"This is a test number of video urls:  {len(c.video_urls)}")
for url in c.video_urls[:20]:
  video = YouTube(url)
  description2 = video.description
  try:
    videos_credits = slicer(description2,"Video Credits:")
    videos_credits = reversed_slicer(videos_credits,"Thumbnail:")
    urls = re.findall(r'(https?://[^\s]+)', videos_credits)
  except Exception:
    print("Sorry but I choose bad youtube video I will try it again")

error what I get is:

PS C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle> & "c:/Users/Lukas/Dokumenty/python_scripts/Billionare livestyle/env/youtube/Scripts/python.exe" "c:/Users/Lukas/Dokumenty/python_scripts/Billionare livestyle/bilionare_life.py"
[]
0
Traceback (most recent call last):
  File "C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\env\youtube\lib\site-packages\pytube\helpers.py", line 57, in __getitem__
    next_item = next(self.gen)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\bilionare_life.py", line 198, in <module>
    for url in c.video_urls[:20]:
  File "C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\env\youtube\lib\site-packages\pytube\helpers.py", line 60, in __getitem__
    raise IndexError
IndexError

Solution

  • The reason why you don't retrieve any video is that it's just an issue on pytube end, as YouTube modified recently its user-interface (on which pytube relies), and this issue is currently being resolved.

    However as temporary a workaround installing pytube as following solves the problem:

    pip install git+https://github.com/pishiko/pytube.git@42a7d8322dd7749a9e950baf6860d115bbeaedfc