langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
95.21k stars 15.45k forks source link

Youtube requires login to view videoDetails #27988

Open ymcki opened 2 weeks ago

ymcki commented 2 weeks ago

Checked other resources

Example Code

I was trying to run this jupyter notebook https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_10_and_11.ipynb

Then it crashes at the beginning

from langchain_community.document_loaders import YoutubeLoader

docs = YoutubeLoader.from_youtube_url(
    "https://www.youtube.com/watch?v=pbAd8O1Lvm4", add_video_info=True,
).load()

print(docs[0].metadata)

Error Message and Stack Trace (if applicable)

Traceback (most recent call last): File "/home/user/anaconda3/envs/ai/lib/python3.10/site-packages/pytube/main.py", line 341, in title self._title = self.vid_info['videoDetails']['title'] KeyError: 'videoDetails'

Description

After I dig more into why it crashed, I find that it is due to this video requires login.

By modifying line 322 of langchain_community/document_loaders/youtube.py from yt = YouTube(f"https://www.youtube.com/watch?v={self.video_id}") to yt = YouTube(f"https://www.youtube.com/watch?v={self.video_id}", use_oauth=True, allow_oauth_cache=True)

Then it asks me to login and then it works.

I think this "bug" can be fixed by adding these two arguments to YoutubeLoader.from_youtube_url and pass them to pytube.

System Info

langchain 0.3.4 langchain-community 0.3.3

Harsimran-19 commented 2 weeks ago

Can I work on this issue?

sonalshreya commented 2 weeks ago

I want to work on this issue

Patotricks15 commented 1 week ago

The same problem here trying to develop a langchain project using YoutubeLoader