|
| 1 | +.. youtool documentation master file, created by |
| 2 | + sphinx-quickstart on Mon Jul 8 14:31:22 2024. |
| 3 | + You can adapt this file completely to your liking, but it should at least |
| 4 | + contain the root `toctree` directive. |
| 5 | +
|
| 6 | +Welcome to youtool documentation! |
| 7 | +================================= |
| 8 | + |
| 9 | +Easily access YouTube Data API v3 in batches |
| 10 | +-------------------------------------------- |
| 11 | + |
| 12 | +.. toctree:: |
| 13 | + :maxdepth: 2 |
| 14 | + |
| 15 | + contributing |
| 16 | + |
| 17 | +-------------------------------------------- |
| 18 | + |
| 19 | +Python library and command-line interface to crawl YouTube Data API v3 in batch operations and other related tasks. |
| 20 | +Easier to use than alternatives - you don't need to spend time learning the YouTube API and its caveats. |
| 21 | +With this library you can get: |
| 22 | + |
| 23 | +- Channel ID from channel URL (scraping) or username (API) |
| 24 | +- Channel information (title, subscribers etc.) |
| 25 | +- List of playlists for a channel |
| 26 | +- List of videos for a playlist |
| 27 | +- Video information (title, description, likes, comments etc.) |
| 28 | +- Comments |
| 29 | +- Livechat, including superchat (scraping using chat-downloader) |
| 30 | +- Automatic transcription (scraping using yt-dlp) |
| 31 | + |
| 32 | +The library will automatically: |
| 33 | + |
| 34 | +- Try as many keys as you provide |
| 35 | +- Use batch of 50 items in supported API endpoints |
| 36 | +- Paginate when needed |
| 37 | + |
| 38 | +Installation |
| 39 | +------------ |
| 40 | + |
| 41 | +Install project by running |
| 42 | + |
| 43 | +.. code-block:: python |
| 44 | +
|
| 45 | + pip install youtool |
| 46 | +
|
| 47 | +Using as a library |
| 48 | +------------------ |
| 49 | +Just follow the tutorial/examples below and check the ``help()`` for ``YouTube`` methods. |
| 50 | + |
| 51 | +`GitHub Repository <https://github.com/PythonicCafe/youtool?tab=readme-ov-file#using-as-a-library:~:text=Using%20as%20a-,library,-Just%20follow%20the>`_ |
| 52 | + |
| 53 | +1. Initializing the YouTube API: |
| 54 | + |
| 55 | +.. code-block:: python |
| 56 | +
|
| 57 | + from youtool import YouTube |
| 58 | +
|
| 59 | + api_keys = ["key1", "key2", ...] |
| 60 | + yt = YouTube(api_keys, disable_ipv6=True) |
| 61 | +
|
| 62 | +Here, we are creating an instance of the YouTube class using a list of YouTube API keys. |
| 63 | +The disable_ipv6=True option is passed to disable IPv6 usage. |
| 64 | + |
| 65 | +2. Extracting Channel IDs by url: |
| 66 | + |
| 67 | +.. code-block:: python |
| 68 | +
|
| 69 | + channel_id_1 = yt.channel_id_from_url("https://youtube.com/c/PythonicCafe/") |
| 70 | + print(f"Pythonic Café's channel ID (got from URL): {channel_id_1}") |
| 71 | +
|
| 72 | +3. Extracting Channel IDs by username: |
| 73 | + |
| 74 | +.. code-block:: python |
| 75 | +
|
| 76 | + channel_id_2 = yt.channel_id_from_username("turicas") |
| 77 | + print(f"Turicas' channel ID (got from username): {channel_id_2}") |
| 78 | +
|
| 79 | +4. Listing Playlists from a Channel: |
| 80 | + |
| 81 | +.. code-block:: python |
| 82 | +
|
| 83 | + for playlist in yt.channel_playlists(channel_id_2): |
| 84 | + for video in yt.playlist_videos(playlist["id"]): |
| 85 | + print(f" Video: {video}") |
| 86 | +
|
| 87 | +Here, we iterate through playlists of a specific channel (channel_id_2) and list the videos in each playlist. |
| 88 | + |
| 89 | +5. Searching for Videos: |
| 90 | + |
| 91 | +.. code-block:: python |
| 92 | +
|
| 93 | + for index, video in enumerate(yt.video_search(term="Álvaro Justen")): |
| 94 | + print(f" Video: {video}") |
| 95 | + if index == 4: |
| 96 | + break |
| 97 | +
|
| 98 | +This snippet searches for videos related to a specific term using the video_search method of the yt instance. |
| 99 | + |
| 100 | +6. Fetching Detailed Video Information: |
| 101 | + |
| 102 | +.. code-block:: python |
| 103 | +
|
| 104 | + last_video = list(yt.videos_infos([video["id"]]))[0] |
| 105 | + pprint(last_video) |
| 106 | +
|
| 107 | +Here, we fetch detailed information about a specific video using the videos_infos method of the yt instance. |
| 108 | + |
| 109 | +7. Fetching Channel Information: |
| 110 | + |
| 111 | +.. code-block:: python |
| 112 | +
|
| 113 | + for channel in yt.channels_infos([channel_id_1, channel_id_2]): |
| 114 | + print(channel) |
| 115 | +
|
| 116 | +This snippet fetches detailed information about multiple channels using the channels_infos method of the yt instance. |
| 117 | + |
| 118 | +8. Fetching Video Comments and Live Chat: |
| 119 | + |
| 120 | +.. code-block:: python |
| 121 | +
|
| 122 | + for comment in yt.video_comments(video_id): |
| 123 | + print(comment) |
| 124 | + for chat_message in yt.video_livechat(live_video_id): |
| 125 | + print(chat_message) |
| 126 | +
|
| 127 | +Here, we fetch comments and live chat messages from specific videos using the video_comments and video_livechat methods of the yt instance. |
| 128 | + |
| 129 | +9. Downloading Video Transcriptions: |
| 130 | + |
| 131 | +.. code-block:: python |
| 132 | +
|
| 133 | + yt.videos_transcriptions([video_id, live_video_id], language_code="pt", path=download_path) |
| 134 | +
|
| 135 | +This snippet downloads transcriptions for specific videos using the videos_transcriptions method of the yt instance. |
| 136 | + |
| 137 | +How to contribute |
| 138 | +------------------ |
| 139 | + |
| 140 | +Welcome to contributing documentation youtool project |
| 141 | + |
| 142 | +See :doc:`contributing` for more detail. |
| 143 | + |
| 144 | +- `Issue Tracker <https://github.com/PythonicCafe/youtool/issues>`_ |
| 145 | +- `Source Code <https://github.com/PythonicCafe/youtool/blob/develop/youtool.py>`_ |
| 146 | + |
| 147 | +Support |
| 148 | +------- |
| 149 | + |
| 150 | +If you are having issues, please let us know |
| 151 | + |
| 152 | +License |
| 153 | +------- |
| 154 | +GNU Lesser General Public License (LGPL) version3 |
| 155 | + |
| 156 | +This project was developed in a partnership between Pythonic Café and `Novelo Data <https://www.novelo.io/>`_ |
0 commit comments