Make ZIM file from a Youtube channel, user or playlist(s)
Project description
Youtube2zim
⚠️ Disclaimer:
The main branch is currently unstable as the scraper is undergoing significant rework for the 3.0 release. If an important patch needs to be applied before the v3 release, please refer to the v2 branch.
youtube2zim
allows you to create a ZIM file
from a Youtube Channel/Username or one-or-more Playlists.
It downloads the videos (webm
or mp4
extension – optionally
recompress them in lower-quality, smaller size), the thumbnails, the
subtitles and the authors' profile pictures; It then produces JSON files containing content for the channel, playlists, and videos, which are used by the UI, which is a Vue.js application that needs to be compiled as a static website with Vite and is then embedded inside the ZIM.
youtube2zim
adheres to openZIM's Contribution Guidelines.
youtube2zim
has implemented openZIM's Python bootstrap, conventions and policies v1.0.2.
Requirements
Installation
Here comes a few different ways to install youtube2zim
.
Virtualenv
youtube2zim
is a Python3 software. If you are not using the Docker image,
you are advised to use it in a virtualenv to avoid installing software
dependencies on your system. Hatch is the proper tool to create the
virtualenv and install the software locally. Ensure to use proper Python version as well (see
pyproject.toml).
If you do not already have it on your system, install hatch to build the software and manage virtual environments (you might be interested by our detailed Developer Setup as well, especially regarding how to configure hatch globally for proper detection of its virtual environments by Visual Studio Code).
pip3 install hatch
Start a hatch shell: this will install software including dependencies in an isolated virtual environment.
cd scraper
hatch shell
youtube2zim --help # Display youtube2zim help
Docker
docker run -v my_dir:/output ghcr.io/openzim/youtube youtube2zim --help
Usage
youtube2zim
uses Youtube API v3 to fetch data from Youtube. You thus need to provide an API_KEY
to use the scraper.
To get an API:
- Connect to Google Developers Console
- Create a new Project then Select it.
- When asked, choose Create Credentials and select the API Key type. (Credentials page)
youtube2zim --api-key "<your-api-key>" --type user --id "Vsauce" --name "vsauce"
Notes
- Your API_KEY is subject to usage quotas (10,000 requests/day by default). Be careful to not waste your quota, especially when scraping large channels.
youtube2zim-playlists
youtube2zim
produces a single ZIM file for a youtube request (channel
, user
, playlist
).
youtube2zim-playlists
allows you to automatically create one ZIM file per playlist of a given channel or user instead.
This script is a wrapper around youtube2zim
and is bundled with the main package.
The difference between a channel and a user is due to Youtube legacy. Some old users have to be searched as a user, while more recent ones have to be searched as a channel. Try your best bet, and if it fails try the other type.
Usage
youtube2zim-playlists --help
Sample usage:
youtube2zim-playlists --indiv-playlists --api-key XXX --type user --id Vsauce --playlists-name="vsauce_en_playlist-{playlist_id}"
Those are the required arguments for youtube2zim-playlists
but you can also pass any regular youtube2zim
argument. Those will be forwarded to youtube2zim
(which will be run independently for each playlist).
Specificities:
--title
and--description
are mutually exclusive with--playlists-title
and--playlists-description
.- If using
--title
or--description
, all your playlists ZIMs will have the same, static metadata. This is rarely wanted. --playlists-title
and--playlists-description
allows you to dynamically customize them via some playlist-related variables:{title}
: the playlist title{description}
: the playlist description{slug}
: slugified version of the playlist title{playlist_id}
: playlist ID on youtube{creator_id}
: playlist's owner channel/user ID.{creator_name}
: playlist's owner channel/user name.
- You can omit them and
youtube2zim
will auto-generate those. - you must specify
--playlists-name
(supports variables listed above). --playlists-name
is used to set theName
metadata of the ZIM (should be unique) and if not set separately, the output file name for the ZIM.--metadata-from
allows to specify a path or URL to a JSON file specifying custom static metadata for individual playlists. Format:
{
"<playlist-id>": {
"name": "",
"zim-file": "",
"title": "",
"description": "",
"tags": "",
"creator": "",
"profile": "",
"banner": ""
}
}
All fields are optional and taken from command-line/default if not found. <playlist-id>
represents the Youtube Playlist ID.
If you feel the need for setting additional details in this file, chances are you should run youtube2zim
independently for that playlist (still possible!)
Development
Before contributing be sure to check out the CONTRIBUTING.md guidelines.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file youtube2zim-3.0.0.tar.gz
.
File metadata
- Download URL: youtube2zim-3.0.0.tar.gz
- Upload date:
- Size: 34.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddaf2c4803f8c4f063563ba672fb46c101d4d3b4335437d3e67a869df453d0f9 |
|
MD5 | aeef2cb7ec0cf7f14336e4fbc38d9238 |
|
BLAKE2b-256 | 6868cb03638450d2ede65e8baa4e4ea0f4e3de93be80c4f1469810ee1e12eeba |
File details
Details for the file youtube2zim-3.0.0-py3-none-any.whl
.
File metadata
- Download URL: youtube2zim-3.0.0-py3-none-any.whl
- Upload date:
- Size: 29.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2a9c6ee0ee3f3fb7b2d05c5e36e1cba63a0dc4674270f6f8ca2cd9a18165f73 |
|
MD5 | fb6d22deff5518e4e34320a319cab760 |
|
BLAKE2b-256 | be10f781ddad1b24e8b7bea3d5e5a95d460dbebbe5bd4d5b196f9133b93aefca |