{"id":17464199,"url":"https://github.com/onlyphantom/youtube_api_python","last_synced_at":"2025-04-19T18:59:15.331Z","repository":{"id":39962931,"uuid":"487273902","full_name":"onlyphantom/youtube_api_python","owner":"onlyphantom","description":"Working with the official YouTube's API in python","archived":false,"fork":false,"pushed_at":"2023-05-02T11:33:23.000Z","size":22,"stargazers_count":13,"open_issues_count":1,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T12:02:26.594Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onlyphantom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-30T12:39:30.000Z","updated_at":"2025-01-26T01:31:45.000Z","dependencies_parsed_at":"2023-02-03T22:30:43.197Z","dependency_job_id":null,"html_url":"https://github.com/onlyphantom/youtube_api_python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlyphantom%2Fyoutube_api_python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlyphantom%2Fyoutube_api_python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlyphantom%2Fyoutube_api_python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlyphantom%2Fyoutube_api_python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onlyphantom","download_url":"https://codeload.github.com/onlyphantom/youtube_api_python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249771289,"owners_count":21323076,"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":[],"created_at":"2024-10-18T10:44:56.700Z","updated_at":"2025-04-19T18:59:15.305Z","avatar_url":"https://github.com/onlyphantom.png","language":"Python","readme":"### YouTube API (Python)\nThis is a repository hosting the code examples demonstrated in the YouTube API tutorial on my youtube channel. \n- [YouTube Analytics API tutorial | YouTube](https://youtu.be/rcE3iL0URhU)\n\n### Usage\nThere are two main Python scripts: `yt_auth.py` and `yt_public.py`. \n\n1. Install the dependencies `pip install -r requirements.txt`\n\n1. Execute the scripts\n    - To run `yt_auth`, you will need store your secrets as `client_secret.json` in the same directory. \n    - 2b. To run `yt_public`, simply create a `.env` file and add a line to your API key: `API_KEY=\u003cYOUR_API_KEY\u003e`\n\n1. Experiment! Modify `yt_public.py` to use one the ready-made functions (`search_result`, `comment_threads` etc) with a YouTube video ID / channel ID. The function names are pretty self-explanatory. Modify `yt_auth.py` to modify what gets returned, `startDate`, `endDate` etc. \n\n```python\npyscriptVidId = 'Qo8dXyKXyME'\nchannelId = 'UCzIxc8Vg53_ewaRIk3shBug'\n\n# try one of the following (uncomment) \n# response = search_result(\"pyscript\")\nresponse = channel_stats(channelId) \n# response = comment_threads(pyscriptVidId)\nprint(response)\n```\n\n### Example:\n```bash\n# when returning channel_stats\npython yt_public.py\n\n# returns:\n{'kind': 'youtube#channelListResponse', 'etag': '5AtqmD44H4QfpPsqQ4Wnihwsngc', 'pageInfo': {'totalResults': 1, 'resultsPerPage': 5}, 'items': [{'kind': 'youtube#channel', 'etag': 'GB2ykHK9DVB-53aKbVA6YAUXNkE', 'id': 'UCzIxc8Vg53_ewaRIk3shBug', 'statistics': {'viewCount': '57498', 'subscriberCount': '961', 'hiddenSubscriberCount': False, 'videoCount': '59'}}]}\n```\n\nWhen returning `comment_threads`, it is recommended to return it with a `maxResults` parameter for videos with many comments:\n\n```bash\npython yt_public.py\n{'kind': 'youtube#commentThreadListResponse', 'etag': 'Ic9b-4hLJVdF7UDLjD4AtQLB0Lw', 'nextPageToken': 'QURTSl9pM0hzMS1NSUo2c1lwNFloWWIwakpIanhtemlCdkRqYXJ6SlUtLVpVYVFwU2RyeE5RZ0dlX0cyLU0ya3JHWmlKdldRSVFXWU9HRQ==', 'pageInfo': {'totalResults': 20, 'resultsPerPage': 20}, 'items': [{'kind': 'youtube#commentThread', 'etag': 'TIrOdgUxY0GufmjsAq37cP98_wI', 'id': 'UgwyC-Lg8xTM-ZwDIMl4AaABAg', 'snippet': {'videoId': 'Qo8dXyKXyME', 'topLevelComment': {'kind': 'youtube#comment', 'etag': 'r-Y1IQx1b405LtcbYs4TnrJh3Jg', 'id': 'UgwyC-Lg8xTM-ZwDIMl4AaABAg', 'snippet': {'videoId': 'Qo8dXyKXyME', 'textDisplay': 'Ahuet guys, it was really impressive, obviously when he create repl tag and instead html-page he got realtime pyhton console!', 'textOriginal': 'Ahuet guys, it was really impressive, obviously when he create repl tag and instead html-page he got realtime pyhton console!', 'authorDisplayName': 'Белгородский Джедай', 'authorProfileImageUrl': 'https://yt3.ggpht.com/ytc/AKedOLS9oo0Gh5C7ENfUDlUz3yrFTwVNGN7SFLNauA=s48-c-k-c0x00ffffff-no-rj', 'authorChannelUrl': 'http://www.youtube.com/channel/UCDqaIEKwP63mCEa1DbdI8sg', 'authorChannelId': {'value': 'UCDqaIEKwP63mCEa1DbdI8sg'}, 'canRate': True, 'viewerRating': 'none', 'likeCount': 0, 'publishedAt': '2022-05-09T19:47:23Z', 'updatedAt': '2022-05-09T19:47:23Z'}}, 'canReply': True, 'totalReplyCount': 0, 'isPublic': True}}, {'kind': 'youtube#commentThread', 'etag': 'XuqkWlpnGIcVU4IpNssELzh6cGE', 'id': 'Ugx7GGYIl6G4UYf-PSR4AaABAg', 'snippet': {'videoId': 'Qo8dXyKXyME', 'topLevelComment': {'kind': 'youtube#comment', 'etag': 'v2NOrgq8b3kEr1kSpq6vQJ2CnhE', 'id': 'Ugx7GGYIl6G4UYf-PSR4AaABAg', 'snippet': {'videoId': 'Qo8dXyKXyME', 'textDisplay': 'Thank you very much.. Please add more more more project about pyscript.... From Indonesia🇮🇩', 'textOriginal': 'Thank you very much.. Please add more more more project about pyscript.... From Indonesia🇮🇩', 'authorDisplayName': 'Renni Ekaputri', 'authorProfileImageUrl': 'https://yt3.ggpht.com/d7JLKybsXKEnS6_TKQI8wNcGCxSOeiy92-bUPWKUsYjHU2s52wapXgSfKQiOa-3IpC14d9vA_w=s48-c-k-c0x00ffffff-no-rj', 'authorChannelUrl': 'http://www.youtube.com/channel/UCrsuj8xA6W_pUIo5yagHgYA', 'authorChannelId': {'value': 'UCrsuj8xA6W_pUIo5yagHgYA'}, 'canRate': True, 'viewerRating': 'none', 'likeCount': 0, 'publishedAt': '2022-05-09T18:45:03Z', 'updatedAt': '2022-05-09T18:45:03Z'}}, 'canReply': True, 'totalReplyCount': 1, 'isPublic': True}, 'replies': {'comments': [{'kind': 'youtube#comment', 'etag': 'wUSmUhfU3ox5KY0Sz0KsPnp6iB4', 'id': 'Ugx7GGYIl6G4UYf-PSR4AaABAg.9aolZGyDz3w9apYGzzghC4', 'snippet': {'videoId': 'Qo8dXyKXyME', 'textDisplay': 'Thank you Renni! Check out the other projects we build with pyscript too 😀\u003cbr\u003e\u003cbr\u003ePart 1 (intro to PyScript): \u003ca href=\"https://youtu.be/Qo8dXyKXyME\"\u003ehttps://youtu.be/Qo8dXyKXyME\u003c/a\u003e\u003cbr\u003ePart 2 (PyScript deployment): \u003ca href=\"https://youtu.be/oH_rTTDjMvM\"\u003ehttps://youtu.be/oH_rTTDjMvM\u003c/a\u003e\u003cbr\u003ePart 3 (PyScript + Altair data dashboard): \u003ca href=\"https://youtu.be/ugSBaOT0rVI\"\u003ehttps://youtu.be/ugSBaOT0rVI\u003c/a\u003e\u003cbr\u003ePart 4 (PyScript Guest Book app, CRUD): \u003ca href=\"https://youtu.be/H6rNzQeryQo\"\u003ehttps://youtu.be/H6rNzQeryQo\u003c/a\u003e', 'textOriginal': 'Thank you Renni! Check out the other projects we build with pyscript too 😀\\n\\nPart 1 (intro to PyScript): https://youtu.be/Qo8dXyKXyME\\nPart 2 (PyScript deployment): https://youtu.be/oH_rTTDjMvM\\nPart 3 (PyScript + Altair data dashboard): https://youtu.be/ugSBaOT0rVI\\nPart 4 (PyScript Guest Book app, CRUD): https://youtu.be/H6rNzQeryQo', 'parentId': 'Ugx7GGYIl6G4UYf-PSR4AaABAg', 'authorDisplayName': 'Samuel Chan', 'authorProfileImageUrl': 'https://yt3.ggpht.com/ytc/AKedOLRGpq_SJ3BGRNRqjdgeo8_STiwyFFheA6jdGbKr=s48-c-k-c0x00ffffff-no-rj', 'authorChannelUrl': 'http://www.youtube.com/channel/UCzIxc8Vg53_ewaRIk3shBug', 'authorChannelId': {'value': 'UCzIxc8Vg53_ewaRIk3shBug'}, 'canRate': True, 'viewerRating': 'none', 'likeCount': 0, 'publishedAt': '2022-05-10T01:59:27Z', 'updatedAt': '2022-05-10T01:59:27Z'}}]}}, {'kind': 'youtube#commentThread', 'etag': 'KmRQzOOglhz5HHoGpXcEri1TS28', 'id': 'Ugxo6DY0jEyzXfmye2R4AaABAg', 'snippet': {'videoId': 'Qo8dXyKXyME', 'topLevelComment': {'kind': 'youtube#comment', 'etag': '5cTRv8hTa0SnVvzegMjpA0zg4y8', 'id': 'Ugxo6DY0jEyzXfmye2R4AaABAg', 'snippet': {'videoId': 'Qo8dXyKXyME', 'textDisplay': 'Nice 👍\u003cbr\u003eDoes it take in .ipynb files?', 'textOriginal': 'Nice 👍\\nDoes it take in .ipynb files?', 'authorDisplayName': 'phlorah', 'authorProfileImageUrl': 'https://yt3.ggpht.com/ytc/AKedOLTy0xRUqmV5i3c6MpvYdh33oTA7F8AMn4vXaBUGX-rPth6cSlW_P1bP3G1_VGmH=s48-c-k-c0x00ffffff-no-rj', 'authorChannelUrl': 'http://www.youtube.com/channel/UCq035cbe5f_l8b8KNN08NnA', 'authorChannelId': {'value': 'UCq035cbe5f_l8b8KNN08NnA'}}}}}]}\n```\n\n\n```bash\npython yt_auth.py\n\n# returns:\n+------------+-------------------+-------+-------+-------------------+\n|    date    | estMinutesWatched | views | likes | subscribersGained |\n+------------+-------------------+-------+-------+-------------------+\n| 2022-05-01 |        756        |  194  |   9   |        11         |\n| 2022-05-02 |        886        |  248  |   4   |         8         |\n| 2022-05-03 |        589        |  247  |   7   |         1         |\n| 2022-05-04 |       4972        | 1346  |  50   |        22         |\n| 2022-05-05 |       9866        | 2689  |  62   |        55         |\n| 2022-05-06 |       10002       | 2759  |  98   |        92         |\n| 2022-05-07 |       10243       | 3200  |  96   |        78         |\n| 2022-05-08 |       12072       | 3600  |  108  |        100        |\n| 2022-05-09 |       11594       | 3746  |  116  |        92         |\n| 2022-05-10 |       8958        | 2762  |  66   |        69         |\n| 2022-05-11 |       7152        | 2156  |  33   |        51         |\n| 2022-05-12 |       8462        | 2269  |  63   |        61         |\n| 2022-05-13 |       7275        | 2480  |  64   |        52         |\n| 2022-05-14 |       5567        | 1702  |  36   |        33         |\n| 2022-05-15 |       4054        | 1218  |  22   |        32         |\n| 2022-05-16 |       3759        | 1138  |  15   |        29         |\n| 2022-05-17 |       3555        | 1040  |  16   |        21         |\n| 2022-05-18 |       3612        |  921  |  21   |        15         |\n| 2022-05-19 |       3134        |  899  |  19   |        15         |\n| 2022-05-20 |       2649        |  656  |  10   |        17         |\n| 2022-05-21 |       2569        |  678  |  14   |        12         |\n| ... \u003cTRUNCATED\u003e ...                                                |\n| 2023-04-17 |       2646        |  723  |  12   |        13         |\n| 2023-04-18 |       2098        |  660  |   8   |        15         |\n| 2023-04-19 |       2244        |  653  |   7   |        10         |\n| 2023-04-20 |       1897        |  589  |  13   |        17         |\n| 2023-04-21 |       2277        |  699  |  10   |        20         |\n| 2023-04-22 |       2694        |  734  |  11   |        20         |\n| 2023-04-23 |       2642        |  694  |   8   |        19         |\n| 2023-04-24 |       3174        |  839  |  20   |        24         |\n| 2023-04-25 |       3472        |  916  |  20   |        20         |\n| 2023-04-26 |       4346        | 1088  |  32   |        23         |\n| 2023-04-27 |       3838        |  964  |  14   |        18         |\n| 2023-04-28 |       3884        |  957  |  20   |        26         |\n+------------+-------------------+-------+-------+-------------------+\n```\n\nIt will also save the data into a csv file in the same directory. You can modify these behaviors, including the filename, the desired columns, and date ranges etc by modifying the `yt_auth.py` file.\n\n### Next Steps\n- [ ] Add `argparse`\n- [ ] Refactor code to make them parameterized functions\n- [ ] Simple charting / tabular printing\n- [ ] Supports other methods from YouTube API\n- [ ] Provide cleaning utility for unpacking returned results","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonlyphantom%2Fyoutube_api_python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonlyphantom%2Fyoutube_api_python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonlyphantom%2Fyoutube_api_python/lists"}