Pytube Channel video_urls is does not working

Question:

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:UsersLukasDokumentypython_scriptsBillionare 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:UsersLukasDokumentypython_scriptsBillionare livestyleenvyoutubelibsite-packagespytubehelpers.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:UsersLukasDokumentypython_scriptsBillionare livestylebilionare_life.py", line 198, in <module>
    for url in c.video_urls[:20]:
  File "C:UsersLukasDokumentypython_scriptsBillionare livestyleenvyoutubelibsite-packagespytubehelpers.py", line 60, in __getitem__
    raise IndexError
IndexError
Asked By: ALex Break

||

Answers:

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
Answered By: Benjamin Loison

@HanleySoilsmith: i have not reputation for comment yet, that’s the reason why i give this option to get channels that have @ in us url as a "Answer" instead of a "comment".

this repo fixes that, and has some additional properties for a channel:

pip install git+https://github.com/alebychac/pytube.git
Answered By: alebychac
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.