{"id":22147809,"url":"https://github.com/rudrodip/ytranscript","last_synced_at":"2025-07-26T02:31:57.664Z","repository":{"id":239856029,"uuid":"801164433","full_name":"rudrodip/ytranscript","owner":"rudrodip","description":"rust crate that provides functionality to fetch YouTube video transcripts","archived":false,"fork":false,"pushed_at":"2024-05-15T18:28:36.000Z","size":16,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-28T09:22:40.781Z","etag":null,"topics":["parsing","regex","reqwest","rust","serde","serde-json","thiserror","youtube-transcripts"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/ytranscript","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rudrodip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-15T18:05:12.000Z","updated_at":"2024-10-14T03:54:44.000Z","dependencies_parsed_at":"2024-05-15T20:26:45.061Z","dependency_job_id":null,"html_url":"https://github.com/rudrodip/ytranscript","commit_stats":null,"previous_names":["rudrodip/ytranscript"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudrodip%2Fytranscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudrodip%2Fytranscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudrodip%2Fytranscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudrodip%2Fytranscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rudrodip","download_url":"https://codeload.github.com/rudrodip/ytranscript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227587065,"owners_count":17790145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parsing","regex","reqwest","rust","serde","serde-json","thiserror","youtube-transcripts"],"created_at":"2024-12-01T23:21:32.244Z","updated_at":"2024-12-01T23:21:34.480Z","avatar_url":"https://github.com/rudrodip.png","language":"Rust","readme":"# ytranscript\n\n`ytranscript` is a Rust crate that provides functionality to fetch YouTube video transcripts. It supports fetching transcripts in different languages and handles various error scenarios that might occur while retrieving the transcripts.\n\n## Features\n\n- Extracts YouTube video IDs from URLs or strings.\n- Fetches transcripts for YouTube videos.\n- Supports fetching transcripts in specific languages.\n- Handles common errors such as video unavailability, transcript unavailability, and too many requests.\n\n## Installation\n\nAdd `ytranscript` to your `Cargo.toml`:\n\n## Usage\n\nHere is an example of how to use the `ytranscript` crate in a binary crate:\n\n```rust\nuse ytranscript::YoutubeTranscript;\nuse std::env;\n\n#[tokio::main]\nasync fn main() {\n    // Get the video ID from command line arguments\n    let args: Vec\u003cString\u003e = env::args().collect();\n    if args.len() != 2 {\n        eprintln!(\"Usage: ytranscript_bin \u003cvideo_id\u003e\");\n        return;\n    }\n    let video_id = \u0026args[1];\n\n    // Fetch the transcript\n    match YoutubeTranscript::fetch_transcript(video_id, None).await {\n        Ok(transcript) =\u003e {\n            for entry in transcript {\n                println!(\"{:?}\", entry);\n            }\n        }\n        Err(e) =\u003e {\n            eprintln!(\"Error: {}\", e);\n        }\n    }\n}\n```\n\n### Functionality\n\n#### `YoutubeTranscript::fetch_transcript`\n\nFetches the transcript for a given YouTube video ID or URL.\n\n- **Arguments:**\n  - `video_id`: A string slice representing the YouTube video URL or ID.\n  - `config`: An optional `TranscriptConfig` specifying the desired language for the transcript.\n\n- **Returns:**\n  - `Ok(Vec\u003cTranscriptResponse\u003e)`: A vector of `TranscriptResponse` if the transcript is successfully fetched.\n  - `Err(YoutubeTranscriptError)`: An error if the transcript cannot be fetched.\n\n### Error Handling\n\nThe crate defines a set of errors that might occur while fetching transcripts:\n\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum YoutubeTranscriptError {\n    #[error(\"YouTube is receiving too many requests from this IP and now requires solving a captcha to continue\")]\n    TooManyRequests,\n    #[error(\"The video is no longer available ({0})\")]\n    VideoUnavailable(String),\n    #[error(\"Transcript is disabled on this video ({0})\")]\n    TranscriptDisabled(String),\n    #[error(\"No transcripts are available for this video ({0})\")]\n    TranscriptNotAvailable(String),\n    #[error(\"No transcripts are available in {0} for this video ({2}). Available languages: {1:?}\")]\n    TranscriptNotAvailableLanguage(String, Vec\u003cString\u003e, String),\n    #[error(\"Impossible to retrieve Youtube video ID.\")]\n    InvalidVideoId,\n}\n```\n\n### Regex Patterns\n\nThe crate uses regex patterns to extract YouTube video IDs and parse XML transcripts:\n\n```rust\npub const RE_YOUTUBE: \u0026str =\n    r#\"(?:youtube\\.com\\/(?:[^\\/]+\\/.+\\/|(?:v|e(?:mbed)?)\\/|.*[?\u0026]v=)|youtu\\.be\\/)([^\"\u0026?\\/\\s]{11})\"#;\n\npub const USER_AGENT: \u0026str = \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36,gzip(gfe)\";\n\npub const RE_XML_TRANSCRIPT: \u0026str = r#\"\u003ctext start=\"([^\"]*)\" dur=\"([^\"]*)\"\u003e([^\u003c]*)\u003c\\/text\u003e\"#;\n```\n\n### Types\n\nThe crate defines the following types:\n\n```rust\n#[derive(Debug)]\npub struct TranscriptConfig {\n    pub lang: Option\u003cString\u003e,\n}\n\n#[derive(Debug)]\npub struct TranscriptResponse {\n    pub text: String,\n    pub duration: f64,\n    pub offset: f64,\n    pub lang: String,\n}\n```\n\n### Testing\n\nYou can test the functionality of the `ytranscript` crate by running the following command:\n\n```sh\ncargo test\n```\n\n### License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE.md) file for details\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frudrodip%2Fytranscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frudrodip%2Fytranscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frudrodip%2Fytranscript/lists"}