2023-02-08 08:35:33 +00:00
{
"cells": [
{
2023-06-05 23:38:07 +00:00
"attachments": {},
2023-02-08 08:35:33 +00:00
"cell_type": "markdown",
"id": "df770c72",
"metadata": {},
"source": [
2023-05-06 00:44:54 +00:00
"# YouTube transcripts\n",
2023-02-08 08:35:33 +00:00
"\n",
2023-05-06 00:44:54 +00:00
">[YouTube](https://www.youtube.com/) is an online video sharing and social media platform created by Google.\n",
"\n",
"This notebook covers how to load documents from `YouTube transcripts`."
2023-02-08 08:35:33 +00:00
]
},
2023-03-09 04:53:27 +00:00
{
"cell_type": "code",
"execution_count": null,
"id": "427d5745",
"metadata": {},
"outputs": [],
"source": [
"from langchain.document_loaders import YoutubeLoader\n"
2023-02-08 08:35:33 +00:00
]
},
{
"cell_type": "code",
2023-03-09 04:53:27 +00:00
"execution_count": null,
2023-02-08 08:35:33 +00:00
"id": "34a25b57",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# !pip install youtube-transcript-api"
]
},
{
"cell_type": "code",
2023-03-09 04:53:27 +00:00
"execution_count": null,
2023-02-08 08:35:33 +00:00
"id": "bc8b308a",
"metadata": {},
"outputs": [],
"source": [
2023-02-09 16:12:22 +00:00
"loader = YoutubeLoader.from_youtube_url(\"https://www.youtube.com/watch?v=QsYGlZkevEg\", add_video_info=True)"
2023-02-08 08:35:33 +00:00
]
},
{
"cell_type": "code",
2023-03-09 04:53:27 +00:00
"execution_count": null,
2023-02-08 08:35:33 +00:00
"id": "d073dd36",
"metadata": {},
2023-03-09 04:53:27 +00:00
"outputs": [],
2023-02-08 08:35:33 +00:00
"source": [
"loader.load()"
]
2023-02-09 16:12:22 +00:00
},
{
2023-06-05 23:38:07 +00:00
"attachments": {},
2023-02-09 16:12:22 +00:00
"cell_type": "markdown",
"id": "6b278a1b",
"metadata": {},
"source": [
2023-06-05 23:38:07 +00:00
"### Add video info"
2023-02-09 16:12:22 +00:00
]
},
{
"cell_type": "code",
2023-03-09 04:53:27 +00:00
"execution_count": null,
2023-02-09 16:12:22 +00:00
"id": "ba28af69",
"metadata": {},
"outputs": [],
"source": [
"# ! pip install pytube"
]
},
{
"cell_type": "code",
2023-03-09 04:53:27 +00:00
"execution_count": null,
2023-02-09 16:12:22 +00:00
"id": "9b8ea390",
"metadata": {},
"outputs": [],
"source": [
2023-06-05 23:38:07 +00:00
"loader = YoutubeLoader.from_youtube_url(\"https://www.youtube.com/watch?v=QsYGlZkevEg\", add_video_info=True)\n",
"loader.load()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "fc417e31",
"metadata": {},
"source": [
"### Add language preferences\n",
"\n",
"Language param : It's a list of language codes in a descending priority, `en` by default.\n",
"\n",
"translation param : It's a translate preference when the youtube does'nt have your select language, `en` by default."
2023-02-09 16:12:22 +00:00
]
},
{
"cell_type": "code",
2023-03-09 04:53:27 +00:00
"execution_count": null,
2023-06-05 23:38:07 +00:00
"id": "08510625",
2023-02-09 16:12:22 +00:00
"metadata": {},
2023-03-09 04:53:27 +00:00
"outputs": [],
2023-02-09 16:12:22 +00:00
"source": [
2023-06-05 23:38:07 +00:00
"loader = YoutubeLoader.from_youtube_url(\"https://www.youtube.com/watch?v=QsYGlZkevEg\", add_video_info=True, language=['en','id'], translation='en')\n",
2023-02-09 16:12:22 +00:00
"loader.load()"
]
2023-03-09 18:20:54 +00:00
},
{
2023-06-05 23:38:07 +00:00
"attachments": {},
2023-03-09 18:20:54 +00:00
"cell_type": "markdown",
"id": "65796cc5",
"metadata": {},
"source": [
"## YouTube loader from Google Cloud\n",
"\n",
"### Prerequisites\n",
"\n",
"1. Create a Google Cloud project or use an existing project\n",
"1. Enable the [Youtube Api](https://console.cloud.google.com/apis/enableflow?apiid=youtube.googleapis.com&project=sixth-grammar-344520)\n",
"1. [Authorize credentials for desktop app](https://developers.google.com/drive/api/quickstart/python#authorize_credentials_for_a_desktop_application)\n",
"1. `pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib youtube-transcript-api`\n",
"\n",
"### 🧑 Instructions for ingesting your Google Docs data\n",
"By default, the `GoogleDriveLoader` expects the `credentials.json` file to be `~/.credentials/credentials.json`, but this is configurable using the `credentials_file` keyword argument. Same thing with `token.json`. Note that `token.json` will be created automatically the first time you use the loader.\n",
"\n",
"`GoogleApiYoutubeLoader` can load from a list of Google Docs document ids or a folder id. You can obtain your folder and document id from the URL:\n",
"Note depending on your set up, the `service_account_path` needs to be set up. See [here](https://developers.google.com/drive/api/v3/quickstart/python) for more details."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c345bc43",
"metadata": {},
"outputs": [],
"source": [
"from langchain.document_loaders import GoogleApiClient, GoogleApiYoutubeLoader\n",
"\n",
"# Init the GoogleApiClient \n",
"from pathlib import Path\n",
"\n",
"\n",
"google_api_client = GoogleApiClient(credentials_path=Path(\"your_path_creds.json\"))\n",
"\n",
"\n",
"# Use a Channel\n",
"youtube_loader_channel = GoogleApiYoutubeLoader(google_api_client=google_api_client, channel_name=\"Reducible\",captions_language=\"en\")\n",
"\n",
"# Use Youtube Ids\n",
"\n",
"youtube_loader_ids = GoogleApiYoutubeLoader(google_api_client=google_api_client, video_ids=[\"TrdevFK_am4\"], add_video_info=True)\n",
"\n",
"# returns a list of Documents\n",
"youtube_loader_channel.load()"
]
2023-02-08 08:35:33 +00:00
}
],
"metadata": {
"kernelspec": {
2023-03-09 18:20:54 +00:00
"display_name": "Python 3 (ipykernel)",
2023-02-08 08:35:33 +00:00
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2023-05-06 00:44:54 +00:00
"version": "3.10.6"
2023-03-09 04:53:27 +00:00
},
"vscode": {
"interpreter": {
"hash": "604c1013f65d31a2eb1fca07aae054bedd5a5a0d272dbb31e502c81f0b254b99"
}
2023-02-08 08:35:33 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 5
}