### Install Python-YouTube from PyPI Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/installation.md Use this command to install or upgrade the Python-YouTube library using pip. ```shell pip install --upgrade python-youtube ``` -------------------------------- ### Install python-youtube Package Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Install or upgrade the python-youtube library using pip. ```shell pip install --upgrade python-youtube # ✨🍰✨ ``` -------------------------------- ### Get Your Own Activities Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve a list of your own activities after completing the authorization process. ```APIDOC ## GET Your Own Activities ### Description Retrieves a list of activities for the currently authenticated user. ### Method `api_with_token.get_activities_by_me` ### Parameters This method does not require any parameters. ### Response #### Success Response (200) - **ActivityListResponse** - Contains a list of activities for the authenticated user. ### Request Example ```python >>> r = api_with_token.get_activities_by_me() ``` ### Response Example ```json [Activity(kind='youtube#activity', id='MTUxNTc0OTk2MjI3NDE0MjYwMDY1NjAwODA=', snippet=ActivitySnippet(title='华山日出', description='冷冷的山头'))] ``` ``` -------------------------------- ### Get Videos by Chart Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Fetch videos based on popularity charts for a specific region. To get all videos on a chart, set `count=None`. ```python >>> video_by_chart = api.get_videos_by_chart(chart="mostPopular", region_code="US", count=2) >>> video_by_chart.items [Video(kind='youtube#video', id='RwnN2FVaHmw'), Video(kind='youtube#video', id='hDeuSfo_Ys0')] ``` -------------------------------- ### Get Videos by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve detailed information for one or more videos using their unique IDs. This is a direct way to get specific video data. ```python >>> video_by_id = api.get_video_by_id(video_id="CvTApw9X8aA") >>> video_by_id VideoListResponse(kind='youtube#videoListResponse') >>> video_by_id.items [Video(kind='youtube#video', id='CvTApw9X8aA')] ``` -------------------------------- ### Get My Playlists Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieves the playlists created by the authenticated user. Requires authorization. ```APIDOC ## Get My Playlists ### Description Retrieves playlists belonging to the currently authenticated user. This method requires authorization. ### Method `api.get_playlists(mine: bool = True)` ### Parameters - **mine** (bool) - Required - Set to `True` to retrieve the authenticated user's playlists. ### Request Example ```python api.get_playlists(mine=True) ``` ``` -------------------------------- ### Get Your Own Activities Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve a list of your own activities after completing the authorization process. This requires an authenticated API client. ```python >>> r = api_with_token.get_activities_by_me() >>> r.items [Activity(kind='youtube#activity', id='MTUxNTc0OTk2MjI3NDE0MjYwMDY1NjAwODA=', snippet=ActivitySnippet(title='华山日出', description='冷冷的山头')), Activity(kind='youtube#activity', id='MTUxNTc0OTk1OTAyNDE0MjYwMDY1NTc2NDg=', snippet=ActivitySnippet(title='海上日出', description='美美美'))] ``` -------------------------------- ### Get Channel Detail using Client Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Retrieve detailed information about a YouTube channel using the pyyoutube.Client. ```APIDOC ## Get Channel Detail using Client ### Description Retrieve detailed information about a YouTube channel using the pyyoutube.Client. You can specify the channel ID to fetch the details. ### Method ```python # Assuming 'cli' is an initialized pyyoutube.Client instance cli.channels.list(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw") # To get the response as JSON cli.channels.list(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw", return_json=True) ``` ``` -------------------------------- ### Get Video Abuse Report Reasons Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve a list of reasons that can be used to report abusive videos. Requires the 'snippet' part. ```python >>> r = api_with_token.get_video_abuse_report_reason(parts=["snippet"]) >>> r.items [VideoAbuseReportReason(kind='youtube#videoAbuseReportReason'), VideoAbuseReportReason(kind='youtube#videoAbuseReportReason')] ``` -------------------------------- ### Get Channel Info by Username Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve information for a YouTube channel using its custom username. ```APIDOC ## Get Channel Info by Username ### Description Retrieve information for a YouTube channel using its custom username. ### Method ```python channel_by_username = api.get_channel_info(for_username="GoogleDevelopers") print(channel_by_username.items[0]) ``` ``` -------------------------------- ### Get My YouTube Subscriptions Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Fetch your own subscriptions after authorizing and providing an access token. You can specify the number of subscriptions to retrieve. ```python >>> r = api.get_subscription_by_me( ... mine=True, ... parts=["id", "snippet"], ... count=2 ... ) >>> r SubscriptionListResponse(kind='youtube#subscriptionListResponse') >>> r.items [Subscription(kind='youtube#subscription', id='zqShTXi-2-Tx7TtwQqhCBwtJ-Aho6DZeutqZiP4Q79Q', snippet=SubscriptionSnippet(title='Next Day Video', description='')), Subscription(kind='youtube#subscription', id='zqShTXi-2-Tx7TtwQqhCBwViE_j9IEgnmRmPnqJljxo', snippet=SubscriptionSnippet(title='PyCon 2015', description=''))] ``` -------------------------------- ### Get Supported I18n Languages Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve a list of application languages supported by the YouTube website. Requires the 'snippet' part. ```python >>> r = api.get_i18n_languages(parts=["snippet"]) >>> r.items [I18nLanguage(kind='youtube#i18nLanguage', id='af', snippet=I18nLanguageSnippet(hl='af', name='Afrikaans')), I18nLanguage(kind='youtube#i18nLanguage', id='az', snippet=I18nLanguageSnippet(hl='az', name='Azerbaijani')), I18nLanguage(kind='youtube#i18nLanguage', id='id', snippet=I18nLanguageSnippet(hl='id', name='Indonesian')), ...] ``` -------------------------------- ### Get User's Playlists Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve playlists created by the authenticated user. This operation requires user authorization. ```python >>> playlists_by_mine = api.get_playlists(mine=True) ``` -------------------------------- ### Get Channel Info using Api Source: https://github.com/sns-sdks/python-youtube/blob/master/examples/README.md Use the Api entry point for compatibility with older code. Requires an API key and a channel ID. ```python from pyyoutube import Api api = Api(api_key="your key") api.get_channel_info(channel_id="id for channel") # ChannelListResponse(kind='youtube#channelListResponse') ``` -------------------------------- ### Get Supported Languages and Regions with pyyoutube Source: https://context7.com/sns-sdks/python-youtube/llms.txt Retrieves lists of languages and regions supported by the YouTube website. Requires an API key. ```python from pyyoutube import Client client = Client(api_key="YOUR_API_KEY") # Supported languages lans = client.i18nLanguages.list(parts="snippet", hl="en_US") for lang in langs.items: print(lang.id, lang.snippet.name) # af Afrikaans # Supported regions regions = client.i18nRegions.list(parts="snippet", hl="en_US") for region in regions.items: print(region.id, region.snippet.name) # AD Andorra ``` -------------------------------- ### Get YouTube Subscriptions by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve subscription information using subscription IDs. Requires appropriate token permissions for the subscriptions. ```python >>> r = api.get_subscription_by_id( ... subscription_id=[ ... "zqShTXi-2-Tx7TtwQqhCBwViE_j9IEgnmRmPnqJljxo", ... "zqShTXi-2-Rya5uUxEp3ZsPI3fZrFQnSXNQCwvHBGGo"]) >>> r SubscriptionListResponse(kind='youtube#subscriptionListResponse') >>> r.items [Subscription(kind='youtube#subscription', id='zqShTXi-2-Tx7TtwQqhCBwViE_j9IEgnmRmPnqJljxo', snippet=SubscriptionSnippet(title='PyCon 2015', description='')), Subscription(kind='youtube#subscription', id='zqShTXi-2-Rya5uUxEp3ZsPI3fZrFQnSXNQCwvHBGGo', snippet=SubscriptionSnippet(title='ikaros-life', description='This is a test channel.'))] ``` -------------------------------- ### OAuth 2.0 Authorization Flow (Client) Source: https://context7.com/sns-sdks/python-youtube/llms.txt Guides through obtaining an access token using the pyyoutube.Client. This involves generating an authorization URL, exchanging a response URI for a token, refreshing it, and revoking it. ```python from pyyoutube import Client client = Client(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET") SCOPE = [ "https://www.googleapis.com/auth/youtube", "https://www.googleapis.com/auth/youtube.force-ssl", "https://www.googleapis.com/auth/userinfo.profile", ] # Step 1 – get the authorization URL authorize_url, state = client.get_authorize_url(scope=SCOPE) print(f"Visit this URL to authorize: {authorize_url}") # Step 2 – user visits the URL, grants permission, is redirected to: # https://localhost/?state=Python-YouTube&code=AUTH_CODE&scope=... response_uri = input("Paste the redirect URL here: ") # Step 3 – exchange for access token token = client.generate_access_token(authorization_response=response_uri, scope=SCOPE) # token: AccessToken(access_token='ya29.xxx', expires_in=3599, token_type='Bearer') print(f"Access token: {token.access_token}") # Step 4 – refresh when expired new_token = client.refresh_access_token(refresh_token=token.refresh_token) print(f"New access token: {new_token.access_token}") # Step 5 – revoke when done client.revoke_access_token(token=token.access_token) # Returns True on success ``` -------------------------------- ### OAuth 2.0 Authorization Flow (Api) Source: https://context7.com/sns-sdks/python-youtube/llms.txt Demonstrates the OAuth 2.0 authorization flow using the legacy pyyoutube.Api class, including getting the authorization URL, generating an access token, and refreshing it. ```python from pyyoutube import Api api = Api(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET") # Get authorization URL url, state = api.get_authorization_url() print(f"Authorize at: {url}") # After user grants access, paste the redirected URL response_uri = input("Redirect URL: ") token = api.generate_access_token(authorization_response=response_uri) # api._access_token is now set automatically print(f"Token: {token}") # Refresh using the stored refresh token new_token = api.refresh_token() print(f"Refreshed: {new_token}") ``` -------------------------------- ### Get Channel Sections by Channel ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Fetch channel sections for a specified channel ID. This returns a list of sections configured for that channel. ```python >>> r = api.get_channel_sections_by_channel(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw") >>>> r ChannelSectionResponse(kind='youtube#channelSectionListResponse') >>> r.items [ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.e-Fk7vMPqLE'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.B8DTd9ZXJqM'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.MfvRjkWLxgk'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.fEjJOXRoWwg'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.PvTmxDBxtLs'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.pmcIOsL7s98'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.c3r3vYf9uD0'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.ZJpkBl-mXfM'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.9_wU0qhEPR8'), ChannelSection(kind='youtube#channelSection', id='UC_x5XG1OV2P6uZZ5FSM9Ttw.npYvuMz0_es')] ``` -------------------------------- ### Initialize pyyoutube.Client with Timeout and Proxy Source: https://context7.com/sns-sdks/python-youtube/llms.txt Initialize the pyyoutube.Client with custom timeout and proxy settings. ```python import pyyoutube # With optional timeout and proxy client = pyyoutube.Client( api_key="YOUR_API_KEY", timeout=30, proxies={"https": "http://proxy.example.com:8080"}, ) ``` -------------------------------- ### Build Python-YouTube from Source Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/installation.md Follow these steps to clone the repository, set up the environment, and build the library from its source code. ```shell git clone https://github.com/sns-sdks/python-youtube.git cd python-youtube make env make build ``` -------------------------------- ### Get Comment Threads for a Channel Only Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve comment threads that are directly on the channel itself, not on its videos. To get all such threads, set `count=None`. ```python >>> ct_by_channel = api.get_comment_threads(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw", count=2) >>> ct_by_channel.items [CommentThread(kind='youtube#commentThread', id='UgyUBI0HsgL9emxcZpR4AaABAg'), CommentThread(kind='youtube#commentThread', id='Ugzi3lkqDPfIOirGFLh4AaABAg')] ``` -------------------------------- ### Api Initialization (Legacy) Source: https://context7.com/sns-sdks/python-youtube/llms.txt Shows how to initialize the legacy `pyyoutube.Api` class using an API key, an access token, or OAuth client credentials. ```APIDOC ## Api Initialization (Legacy) `pyyoutube.Api` is the original interface, still fully supported. It accepts the same credential parameters as `Client`. ```python from pyyoutube import Api # API key only api = Api(api_key="YOUR_API_KEY") # Access token only api = Api(access_token="YOUR_ACCESS_TOKEN") # OAuth flow credentials api = Api(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET") ``` ``` -------------------------------- ### Get Video Abuse Report Reasons Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve a list of reasons that can be used to report abusive videos. This operation requires authorization and can fetch the 'snippet' part of the reason information. ```APIDOC ## GET Video Abuse Report Reasons ### Description Retrieves a list of reasons that can be used to report abusive videos. ### Method GET ### Endpoint /videoAbuseReportReasons ### Parameters #### Query Parameters - **parts** (string) - Optional - Specifies which parts of the video abuse report reason resource to return. Example: "snippet" ``` -------------------------------- ### Initialize pyyoutube.Client with API Key Source: https://context7.com/sns-sdks/python-youtube/llms.txt Initialize the pyyoutube.Client for public read-only access using an API key. ```python import pyyoutube # Public read-only access (API key) client = pyyoutube.Client(api_key="YOUR_API_KEY") ``` -------------------------------- ### Initialize the YouTube Client Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/introduce-new-structure.md Instantiate the Client with your API key to begin interacting with the YouTube API. ```python from pyyoutube import Client client = Client(api_key="your api key") ``` -------------------------------- ### Initialize pyyoutube.Client from Secret File Source: https://context7.com/sns-sdks/python-youtube/llms.txt Initialize the pyyoutube.Client by loading OAuth credentials from a Google-issued client_secret.json file. ```python import pyyoutube # Load credentials from a Google client_secret.json file client = pyyoutube.Client(client_secret_path="/path/to/client_secret.json") ``` -------------------------------- ### Get Videos by User Rating Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve videos that the authenticated user has rated (e.g., 'like'). This requires authorization. To fetch all rated videos, set `count=None`. ```python >>> videos_by_rating = api.get_videos_by_myrating(rating="like", count=2) ``` -------------------------------- ### Initialize Client with Access Token Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-client.md Initialize the client with an access token for operations that require authentication, such as updating channel data or uploading videos. The access token must have the necessary permissions. ```python from pyyoutube import Client cli = Client(access_token="Access Token with permissions") ``` -------------------------------- ### Get Public Channel Activities Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve a list of public activities for a given channel ID. Specify the 'count' parameter to limit the number of activities returned. ```python >>> r = api.get_activities_by_channel(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw", count=2) >>> r ActivityListResponse(kind='youtube#activityListResponse') >>> r.items [Activity(kind='youtube#activity', id='MTUxNTc3NzM2MDAyODIxOTQxNDM0NjAwMA==', snippet=ActivitySnippet(title='2019 Year in Review - The Developer Show', description='Here to bring you the latest developer news from across Google this year is Developer Advocate Timothy Jordan. In this last week of the year, we’re taking a look back at some of the coolest and biggest announcements we covered in 2019! Follow Google Developers on Instagram → https://goo.gle/googledevs Watch more #DevShow → https://goo.gle/GDevShow Subscribe to Google Developers → https://goo.gle/developers')), Activity(kind='youtube#activity', id='MTUxNTc3MTI4NzIzODIxOTQxNDM0NzI4MA==', snippet=ActivitySnippet(title='GDE Promo - Lara Martin', description='Meet Lara Martin, a Flutter/Dart Google Developers Expert and get inspired by her journey. Watch now for a preview of her story! #GDESpotlights #IncludedWithGoogle Learn about the GDE program → https://goo.gle/2qWOvAy Google Developers Experts → https://goo.gle/GDE Subscribe to Google Developers → https://goo.gle/developers'))] ``` -------------------------------- ### Get Video Categories Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve video categories either by their IDs or by a region code. ```APIDOC ## Get video categories with id(s): ```python >>> video_category_by_id = api.get_video_categories(category_id="17,18") >>> video_category_by_id.items [VideoCategory(kind='youtube#videoCategory', id='17'), VideoCategory(kind='youtube#videoCategory', id='18')] ``` ## Get video categories with region code: ```python >>> video_categories_by_region = api.get_video_categories(region_code="US") >>> video_categories_by_region.items [VideoCategory(kind='youtube#videoCategory', id='1'), VideoCategory(kind='youtube#videoCategory', id='2'), VideoCategory(kind='youtube#videoCategory', id='10'), VideoCategory(kind='youtube#videoCategory', id='15'), ...] ``` ``` -------------------------------- ### Initialize YouTube Client with API Key Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/getting_started.md Use this to initialize the client for retrieving public YouTube data. Ensure you have generated an API key from the Google Cloud Console. ```python from pyyoutube import Client cli = Client(api_key="your api key") ``` -------------------------------- ### Get Videos by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieves video information using one or more video IDs. ```APIDOC ## Get Videos by ID ### Description Retrieves information for one or more videos using their IDs. ### Method `api.get_video_by_id(video_id: str)` ### Parameters - **video_id** (str) - Required - The ID of the video to retrieve. ### Request Example ```python api.get_video_by_id(video_id="CvTApw9X8aA") ``` ### Response Example ```json { "kind": "youtube#videoListResponse", "items": [ { "kind": "youtube#video", "id": "CvTApw9X8aA" } ] } ``` ``` -------------------------------- ### List Channels using Client Source: https://github.com/sns-sdks/python-youtube/blob/master/examples/README.md Use the Client entry point for new implementations and additional capabilities. Requires an API key and a channel ID. ```python from pyyoutube import Client cli = Client(api_key="your key") cli.channels.list(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw") # ChannelListResponse(kind='youtube#channelListResponse') ``` -------------------------------- ### Get Playlists by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieves playlist information using a specific playlist ID. ```APIDOC ## Get Playlist by ID ### Description Retrieves a playlist using its unique ID. ### Method `api.get_playlist_by_id(playlist_id: str)` ### Parameters - **playlist_id** (str) - Required - The ID of the playlist to retrieve. ### Request Example ```python api.get_playlist_by_id(playlist_id="PLOU2XLYxmsIKpaV8h0AGE05so0fAwwfTw") ``` ### Response Example ```json { "items": [ { "kind": "youtube#playlist", "id": "PLOU2XLYxmsIKpaV8h0AGE05so0fAwwfTw" } ] } ``` ``` -------------------------------- ### Initialize pyyoutube Client with API Key Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube Client using an API key for accessing public YouTube data. ```python from pyyoutube import Client client = Client(api_key="your api key") ``` -------------------------------- ### Initialize Client with API Key Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube.Client with an API key to access public YouTube Data API V3 resources. ```APIDOC ## Initialize Client with API Key ### Description Initialize the pyyoutube.Client with an API key to access public YouTube Data API V3 resources. ### Method ```python from pyyoutube import Client client = Client(api_key="your api key") ``` ``` -------------------------------- ### Get Channel Section by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve details for a specific channel section using its ID. ```APIDOC ## GET Channel Section by ID ### Description Retrieves detailed information about a specific channel section using its unique ID. ### Method `api.get_channel_section_by_id` ### Parameters #### Path Parameters - **section_id** (string) - Required - The ID of the channel section to retrieve. ### Response #### Success Response (200) - **ChannelSectionResponse** - Contains the details of the requested channel section. ### Request Example ```python >>> r = api.get_channel_section_by_id(section_id="UC_x5XG1OV2P6uZZ5FSM9Ttw.e-Fk7vMPqLE") ``` ### Response Example ```json ChannelSectionResponse(kind='youtube#channelSectionListResponse') ``` ``` -------------------------------- ### Run Tests for Python-YouTube Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/installation.md After setting up the project environment, execute this command to run the project's tests and generate HTML reports. ```shell make tests-html ``` -------------------------------- ### Get Channel Sections by Channel ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve channel sections for a given channel ID. ```APIDOC ## GET Channel Sections by Channel ID ### Description Retrieves a list of channel sections for a specified YouTube channel. ### Method `api.get_channel_sections_by_channel` ### Parameters #### Path Parameters - **channel_id** (string) - Required - The ID of the channel whose sections are to be retrieved. ### Response #### Success Response (200) - **ChannelSectionResponse** - Contains a list of channel sections. ### Request Example ```python >>> r = api.get_channel_sections_by_channel(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw") ``` ### Response Example ```json ChannelSectionResponse(kind='youtube#channelSectionListResponse') ``` ``` -------------------------------- ### Get Playlist Item by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieves a specific playlist item using its unique ID. ```APIDOC ## Get Playlist Item by ID ### Description Retrieves a playlist item using its unique ID. ### Method `api.get_playlist_item_by_id(playlist_item_id: str)` ### Parameters - **playlist_item_id** (str) - Required - The ID of the playlist item to retrieve. ### Request Example ```python api.get_playlist_item_by_id(playlist_item_id="UExPVTJYTFl4bXNJS3BhVjhoMEFHRTA1c28wZkF3d2ZUdy41NkI0NEY2RDEwNTU3Q0M2") ``` ### Response Example ```json { "items": [ { "kind": "youtube#playlistItem", "id": "UExPVTJYTFl4bXNJS3BhVjhoMEFHRTA1c28wZkF3d2ZUdy41NkI0NEY2RDEwNTU3Q0M2" } ] } ``` ``` -------------------------------- ### Instantiate Api with API Key Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Initialize the Api class with your YouTube Data API key. ```APIDOC ## Instantiate Api with API Key ### Description Initialize the pyyoutube.Api class using an API key. ### Method ```python from pyyoutube import Api api = Api(api_key="your api key") ``` ``` -------------------------------- ### Get Authorized User's Channel Sections Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve channel sections for the currently authenticated user. ```APIDOC ## GET Authorized User's Channel Sections ### Description Retrieves a list of channel sections for the currently authenticated user. ### Method `api.get_channel_sections_by_channel` ### Parameters #### Query Parameters - **mine** (boolean) - Required - Set to `True` to retrieve sections for the authenticated user. ### Response #### Success Response (200) - **ChannelSectionResponse** - Contains a list of channel sections for the authenticated user. ### Request Example ```python >>> r = api.get_channel_sections_by_channel(mine=True) ``` ### Response Example ```json ChannelSectionResponse(kind='youtube#channelSectionListResponse') ``` ``` -------------------------------- ### Client Initialization Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-client.md Instantiate the pyyoutube Client with an API key for public data access or an access token for authenticated operations. ```APIDOC ## Client Initialization ### Description Instantiate the pyyoutube Client with an API key for public data access or an access token for authenticated operations. ### Code Examples **Initialize with API Key:** ```python from pyyoutube import Client cli = Client(api_key="your api key") ``` **Initialize with Access Token:** ```python from pyyoutube import Client cli = Client(access_token="Access Token with permissions") ``` **Initialize with Client ID and Secret for OAuth Flow:** ```python from pyyoutube import Client cli = Client(client_id="ID for app", client_secret="Secret for app") # Get authorization url auth_url, state = cli.get_authorize_url() print(f"Authorization URL: {auth_url}") # After user authorization, copy the redirected URL redirected_url = "your_redirected_url" access_token_info = cli.generate_access_token(authorization_response=redirected_url) print(f"Access Token: {access_token_info.access_token}") ``` **Initialize using client_secret.json:** ```python from pyyoutube import Client file_path = "path/to/client_secret.json" cli = Client(client_secret_path=file_path) # Proceed with the OAuth flow as described above ``` ``` -------------------------------- ### Initialize Client with Access Token Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube.Client with an access token for accessing additional data that requires authorization. ```APIDOC ## Initialize Client with Access Token ### Description Initialize the pyyoutube.Client with an access token for accessing additional data that requires authorization. Refer to the documentation for instructions on obtaining an access token. ### Method ```python from pyyoutube import Client client = Client(access_token='your access token') ``` ``` -------------------------------- ### Initialize pyyoutube Client with Access Token Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube Client using an access token for accessing authorized YouTube data. Refer to the documentation for obtaining an access token. ```python from pyyoutube import Client client = Client(access_token='your access token') ``` -------------------------------- ### Get Comment Thread by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieves comment threads using one or more comment thread IDs. ```APIDOC ## Get Comment Thread by ID ### Description Retrieves comment threads using their unique IDs. ### Method `api.get_comment_thread_by_id(comment_thread_id: str)` ### Parameters - **comment_thread_id** (str) - Required - The ID(s) of the comment thread(s) to retrieve, separated by commas. ### Request Example ```python api.get_comment_thread_by_id(comment_thread_id='Ugz097FRhsQy5CVhAjp4AaABAg,UgzhytyP79_PwaDd4UB4AaABAg') ``` ### Response Example ```json { "items": [ { "kind": "youtube#commentThread", "id": "Ugz097FRhsQy5CVhAjp4AaABAg" }, { "kind": "youtube#commentThread", "id": "UgzhytyP79_PwaDd4UB4AaABAg" } ] } ``` ``` -------------------------------- ### Get Channel Info by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve information for a specific YouTube channel using its channel ID. ```APIDOC ## Get Channel Info by ID ### Description Retrieve information for a specific YouTube channel using its channel ID. The `items` property will be an empty list if the channel is not found. ### Method ```python channel_by_id = api.get_channel_info(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw") print(channel_by_id.items) ``` ``` -------------------------------- ### Client Initialization Source: https://context7.com/sns-sdks/python-youtube/llms.txt Initialize the pyyoutube.Client with an API key for public access, an access token for authenticated operations, or OAuth credentials for authorization flow. Optional timeout and proxy settings can also be configured. ```APIDOC ## Client Initialization `pyyoutube.Client` is the recommended entry point. It accepts an API key for public read-only access, an OAuth 2.0 access token for authenticated operations, or OAuth client credentials to drive the authorization flow. Credentials can also be loaded from a Google-issued `client_secret.json` file. ```python import pyyoutube # Public read-only access (API key) client = pyyoutube.Client(api_key="YOUR_API_KEY") # Authenticated access (access token) client = pyyoutube.Client(access_token="YOUR_ACCESS_TOKEN") # OAuth credentials for initiating the authorization flow client = pyyoutube.Client(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET") # Load credentials from a Google client_secret.json file client = pyyoutube.Client(client_secret_path="/path/to/client_secret.json") # With optional timeout and proxy client = pyyoutube.Client( api_key="YOUR_API_KEY", timeout=30, proxies={"https": "http://proxy.example.com:8080"}, ) ``` ``` -------------------------------- ### Initialize Client from client_secret.json Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-client.md Initialize the client using a client secrets file. This method is suitable for 'web' and some 'installed' application types. Ensure the 'client_id' and 'client_secret' fields are present in the JSON file. The default redirect URI will be set from the 'redirect_uris' field. ```python from pyyoutube import Client file_path = "path/to/client_secret.json" cli = Client(client_secret_path=file_path) # Then go through auth flow descriped above ``` -------------------------------- ### Get Video Caption by ID Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve a specific video caption using its ID, along with the video ID. ```APIDOC ## GET Video Caption by ID ### Description Retrieves a specific caption for a YouTube video using both the video ID and the caption ID. ### Method `api.get_captions_by_video` ### Parameters #### Path Parameters - **video_id** (string) - Required - The ID of the video. - **caption_id** (string) - Required - The ID of the caption to retrieve. - **parts** (list of strings) - Optional - Specifies which parts of the caption resource to include in the response (e.g., `["id", "snippet"]`). ### Response #### Success Response (200) - **CaptionListResponse** - Contains the requested caption. ### Request Example ```python >>> r = api.get_captions_by_video(video_id="oHR3wURdJ94", parts=["id", "snippet"], caption_id="SwPOvp0r7kd9ttt_XhcHdZthMwXG7Z0I") ``` ### Response Example ```json CaptionListResponse(kind='youtube#captionListResponse') ``` ``` -------------------------------- ### Initialize Api with Access Token Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube.Api with an access token for accessing additional data that requires authorization, maintaining compatibility with older code. ```APIDOC ## Initialize Api with Access Token ### Description Initialize the pyyoutube.Api with an access token for accessing additional data that requires authorization, maintaining compatibility with older code. Refer to the documentation for instructions on obtaining an access token. ### Method ```python from pyyoutube import Api api = Api(access_token='your access token') ``` ``` -------------------------------- ### Get Video Captions Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve caption information for a given video. You can specify which parts of the caption resource to include. ```APIDOC ## GET Video Captions ### Description Retrieves caption information for a specified YouTube video. ### Method `api.get_captions_by_video` ### Parameters #### Path Parameters - **video_id** (string) - Required - The ID of the video to retrieve captions for. - **parts** (list of strings) - Optional - Specifies which parts of the caption resource to include in the response (e.g., `["id", "snippet"]`). ### Response #### Success Response (200) - **CaptionListResponse** - Contains a list of captions for the video. ### Request Example ```python >>> r = api.get_captions_by_video(video_id="oHR3wURdJ94", parts=["id", "snippet"]) ``` ### Response Example ```json CaptionListResponse(kind='youtube#captionListResponse') ``` ``` -------------------------------- ### Instantiate Api with OAuth Credentials Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Initialize the Api class for OAuth flow to obtain authorization. ```APIDOC ## Instantiate Api with OAuth Credentials ### Description Initialize the pyyoutube.Api class with client ID and client secret to initiate the OAuth flow. ### Method ```python from pyyoutube import Api api = Api(client_id="client key", client_secret="client secret") # Get authorization url authorization_url, state = api.get_authorization_url() # User performs OAuth flow and obtains authorization_response # ... access_token_info = api.generate_access_token(authorization_response="link for response") ``` ``` -------------------------------- ### Get Subscriptions Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve subscription information by ID, by a specific channel, or your own subscriptions. Requires authorization for non-public subscriptions. ```APIDOC ## To get subscription info by id(s): Your token needs to have the permission for the subscriptions belonging to a channel or user. ```python >>> r = api.get_subscription_by_id( ... subscription_id=[ ... "zqShTXi-2-Tx7TtwQqhCBwViE_j9IEgnmRmPnqJljxo", ... "zqShTXi-2-Rya5uUxEp3ZsPI3fZrFQnSXNQCwvHBGGo"]) >>> r SubscriptionListResponse(kind='youtube#subscriptionListResponse') >>> r.items [Subscription(kind='youtube#subscription', id='zqShTXi-2-Tx7TtwQqhCBwViE_j9IEgnmRmPnqJljxo', snippet=SubscriptionSnippet(title='PyCon 2015', description='')), Subscription(kind='youtube#subscription', id='zqShTXi-2-Rya5uUxEp3ZsPI3fZrFQnSXNQCwvHBGGo', snippet=SubscriptionSnippet(title='ikaros-life', description='This is a test channel.'))] ``` ## Get your own subscriptions: You need to authorize first, and supply the token. ```python >>> r = api.get_subscription_by_me( ... mine=True, ... parts=["id", "snippet"], ... count=2 ... ) >>> r SubscriptionListResponse(kind='youtube#subscriptionListResponse') >>> r.items [Subscription(kind='youtube#subscription', id='zqShTXi-2-Tx7TtwQqhCBwtJ-Aho6DZeutqZiP4Q79Q', snippet=SubscriptionSnippet(title='Next Day Video', description='')), Subscription(kind='youtube#subscription', id='zqShTXi-2-Tx7TtwQqhCBwViE_j9IEgnmRmPnqJljxo', snippet=SubscriptionSnippet(title='PyCon 2015', description=''))] ``` ## Get public channel subscriptions: ```python >>> r = api.get_subscription_by_channel( ... channel_id="UCAuUUnT6oDeKwE6v1NGQxug", ... parts="id,snippet", ... count=2 ... ) >>> r SubscriptionListResponse(kind='youtube#subscriptionListResponse') >>> r.items [Subscription(kind='youtube#subscription', id='FMP3Mleijt-52zZDGkHtR5KhwkvCcdQKWWWIA1j5eGc', snippet=SubscriptionSnippet(title='TEDx Talks', description="TEDx is an international community that organizes TED-style events anywhere and everywhere -- celebrating locally-driven ideas and elevating them to a global stage. TEDx events are produced independently of TED conferences, each event curates speakers on their own, but based on TED's format and rules.\n\nFor more information on using TED for commercial purposes (e.g. employee learning, in a film, or in an online course), please submit a media request using the link below.")), Subscription(kind='youtube#subscription', id='FMP3Mleijt_ZKvy5M-HhRlsqI4wXY7VmP5g8lvmRhVU', snippet=SubscriptionSnippet(title='TED Residency', description='The TED Residency program is an incubator for breakthrough ideas. It is free and open to all via a semi-annual competitive application. Those chosen as TED Residents spend four months at TED headquarters in New York City, working on their idea. Selection criteria include the strength of their idea, their character, and their ability to bring a fresh perspective and positive contribution to the diverse TED community.'))] ``` ``` -------------------------------- ### Initialize Client for OAuth Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube.Client for OAuth flow to allow users to authorize access to their data. ```APIDOC ## Initialize Client for OAuth ### Description Initialize the pyyoutube.Client for OAuth flow. This allows users to authorize access to their data. You will need to provide your client ID and client secret. ### Method ```python from pyyoutube import Client client = Client(client_id="client key", client_secret="client secret") # Get authorization url client.get_authorize_url() # Generate access token after user authorization client.generate_access_token(authorization_response="link for response") ``` ``` -------------------------------- ### Instantiate Api with API Key Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Initialize the Api class with your YouTube Data API key to access public data. Ensure you have a valid API key from the Google Cloud Console. ```python from pyyoutube import Api api = Api(api_key="your api key") ``` -------------------------------- ### Get Video Comments Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieves comment threads for a specific video. Can fetch all threads by setting count to None. ```APIDOC ## Get Video Comments ### Description Retrieves comment threads associated with a specific video. To get all comment threads for the video, set `count=None`. ### Method `api.get_comment_threads(video_id: str, count: int | None = None)` ### Parameters - **video_id** (str) - Required - The ID of the video for which to retrieve comment threads. - **count** (int | None) - Optional - The maximum number of comment threads to return. If `None`, all threads are returned. ### Request Example ```python api.get_comment_threads(video_id="D-lhorsDlUQ", count=2) ``` ### Response Example ```json { "items": [ { "kind": "youtube#commentThread", "id": "UgydxWWoeA7F1OdqypJ4AaABAg" }, { "kind": "youtube#commentThread", "id": "UgxKREWxIgDrw8w2e_Z4AaABAg" } ] } ``` ``` -------------------------------- ### Instantiate Api with Access Token Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Initialize the Api class with an access token for authenticated requests. This is necessary for accessing user-specific data. Refer to the documentation for obtaining an access token. ```python from pyyoutube import Api api = Api(access_token='your api key') ``` -------------------------------- ### Instantiate Api with Access Token Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Initialize the Api class with an OAuth access token for authorized requests. ```APIDOC ## Instantiate Api with Access Token ### Description Initialize the pyyoutube.Api class using an access token. This is required for operations that need user authorization. ### Method ```python from pyyoutube import Api api = Api(access_token='your access token') ``` ``` -------------------------------- ### Get Supported I18n Regions Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieve a list of content regions supported by the YouTube website. Requires the 'snippet' part. ```python >>> r = api.get_i18n_regions(parts=["snippet"]) >>> r.items [I18nRegion(kind='youtube#i18nRegion', id='DZ', snippet=I18nRegionSnippet(gl='DZ', name='Algeria')), I18nRegion(kind='youtube#i18nRegion', id='AR', snippet=I18nRegionSnippet(gl='AR', name='Argentina')), I18nRegion(kind='youtube#i18nRegion', id='AU', snippet=I18nRegionSnippet(gl='AU', name='Australia')) ...] ``` -------------------------------- ### Initialize Client and Get Authorization URL Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/authorization.md Initialize the YouTube client with your application's credentials and retrieve the authorization URL. This URL is used to initiate the OAuth 2.0 flow for user consent. ```python from pyyoutube import Client cli = Client(client_id="you client id", client_secret="you client secret") cli.get_authorize_url() ``` -------------------------------- ### Get Channel Comments Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieves comment threads that are specifically for the channel itself (not its videos). Can fetch all threads by setting count to None. ```APIDOC ## Get Channel Comments ### Description Retrieves comment threads that are directly for the specified channel. To get all such threads, set `count=None`. ### Method `api.get_comment_threads(channel_id: str, count: int | None = None)` ### Parameters - **channel_id** (str) - Required - The ID of the channel for which to retrieve comment threads. - **count** (int | None) - Optional - The maximum number of comment threads to return. If `None`, all threads are returned. ### Request Example ```python api.get_comment_threads(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw", count=2) ``` ### Response Example ```json { "items": [ { "kind": "youtube#commentThread", "id": "UgyUBI0HsgL9emxcZpR4AaABAg" }, { "kind": "youtube#commentThread", "id": "Ugzi3lkqDPfIOirGFLh4AaABAg" } ] } ``` ``` -------------------------------- ### Initialize Api for OAuth Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube.Api for OAuth flow to allow users to authorize access, maintaining compatibility with older code. ```APIDOC ## Initialize Api for OAuth ### Description Initialize the pyyoutube.Api for OAuth flow to allow users to authorize access, maintaining compatibility with older code. You will need to provide your client ID and client secret. ### Method ```python from pyyoutube import Api api = Api(client_id="client key", client_secret="client secret") # Get authorization url api.get_authorization_url() # Generate access token after user authorization api.generate_access_token(authorization_response="link for response") ``` ``` -------------------------------- ### Get Playlists by Channel Source: https://github.com/sns-sdks/python-youtube/blob/master/docs/docs/usage/work-with-api.md Retrieves all playlists associated with a given channel ID. Can fetch all playlists by setting count to None. ```APIDOC ## Get Playlists by Channel ### Description Retrieves playlists belonging to a specific channel. To get all playlists, set `count=None`. ### Method `api.get_playlists(channel_id: str, count: int | None = None)` ### Parameters - **channel_id** (str) - Required - The ID of the channel whose playlists are to be retrieved. - **count** (int | None) - Optional - The maximum number of playlists to return. If `None`, all playlists are returned. ### Request Example ```python api.get_playlists(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw") ``` ### Response Example ```json { "items": [ { "kind": "youtube#playlist", "id": "PLOU2XLYxmsIKpaV8h0AGE05so0fAwwfTw" }, { "kind": "youtube#playlist", "id": "PLOU2XLYxmsIJO83u2UmyC8ud41AvUnhgj" } ] } ``` ``` -------------------------------- ### Initialize pyyoutube Api with Access Token Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube Api using an access token for accessing authorized YouTube data. This is a legacy method. ```python from pyyoutube import Api api = Api(access_token='your access token') ``` -------------------------------- ### Initialize pyyoutube Api with API Key Source: https://github.com/sns-sdks/python-youtube/blob/master/README.rst Initialize the pyyoutube Api using an API key. This is a legacy method for accessing public YouTube data. ```python from pyyoutube import Api api = Api(api_key="your api key") ```