• Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Store files as YouTube videos == infinite disk space. youtube-drive is totally inspired by YouTubeDrive.

youtube-drive

youtube-drive is totally inspired by YouTubeDrive, a Wolfram Language (aka Mathematica) package. I read the source code of YouTubeDrive and write a Python version with a little change for fun.

youtube-drive is a Python library encodes/decodes arbitrary data to/from simple RGB videos which are automatically uploaded to/downloaded from YouTube. Since YouTube imposes no limits on the total number or length of videos users can upload, this provides an effectively infinite but extremely slow form of file storage.

youtube-drive is a silly proof-of-concept, and I do not endorse its high-volume use either.

Usage Example

Upload: Encode a file to video and upload to YouTube:

python -m youtube_drive upload examples/BesselJ.png
YouTube Video ID: EzqstWlMXyk
YouTube: https://youtu.be/EzqstWlMXyk

Retrieve: Download the video from YouTube and decode to a file:

python -m youtube_drive retrieve --video-id=EzqstWlMXyk -o BesselJ-retrieved.png
/var/folders/md/dnr_ryfs2_x128p26xx2pnnc0000gn/T/tmp6qfm_msc.mp4
[youtube] EzqstWlMXyk: Downloading webpage
[youtube] EzqstWlMXyk: Downloading MPD manifest
[download] Destination: /var/folders/md/dnr_ryfs2_x128p26xx2pnnc0000gn/T/tmp6qfm_msc.f136.mp4
[download] 100% of 1.74MiB in 00:25
[download] Destination: /var/folders/md/dnr_ryfs2_x128p26xx2pnnc0000gn/T/tmp6qfm_msc.mp4.f140
[download] 100% of 58.70KiB in 00:03
[ffmpeg] Merging formats into "/var/folders/md/dnr_ryfs2_x128p26xx2pnnc0000gn/T/tmp6qfm_msc.mp4"
Deleting original file /var/folders/md/dnr_ryfs2_x128p26xx2pnnc0000gn/T/tmp6qfm_msc.f136.mp4 (pass -k to keep)
Deleting original file /var/folders/md/dnr_ryfs2_x128p26xx2pnnc0000gn/T/tmp6qfm_msc.mp4.f140 (pass -k to keep)

The video, video ID is EzqstWlMXyk, youtube-drive produces in this example can be viewed at https://youtu.be/EzqstWlMXyk. The video is encoded from the image BesselJ.png. A 62KB image file will produce a video of size 10+MB.

Another file I uploaded to YouTube is painting.jpg, it produces a video of size 127.5MB, and the original size is 476KB. The video can be viewed at https://youtu.be/gKhXk3IGW2s.

I use opencv to produce mp4 video, if use ffmpeg with optimizing directly, the video maybe compress to a more smaller size.

AGAIN: It is a silly idea, just for fun.

Installation

Notice:

  • I only test with Python 3.8 & 3.9 & 3.10 on MacOS with ffmpeg installed.
  • If it works on your system, please feel free to let me know. Thanks.

For development:

git clone https://github.com/lewangdev/youtube-drive.git
cd youtube-drive
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

Or run directly from sources:

git clone https://github.com/lewangdev/youtube-drive.git
cd youtube-drive
python -m venv .venv
. .venv/bin/activate
python setup.py install

Setup

The first time you try to upload a video to YouTube, you will be asked to follow a URL in your browser to get an authentication token. If you have multiple channels for the logged in user, you will also be asked to pick which one you want to upload the videos to.

You now need to create and use your own OAuth 2.0 file, it's a free service. Steps:

Go to the Google Cloud Console.

  • Create project.
  • Side menu: APIs & Services -> OAuth consent screen: Create app and add the test user you will updoad videos to.
  • Side menu: APIs & Services -> Enabled API & services -> ENABLED API AND SERVICES -> Search youtube -> Choose YouTube Data API v3 and enable it.
  • Side menu: APIs & Services -> Credentials -> Create Credentials -> OAuth client ID: Application type choose Desktop app.
  • Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system. Use this JSON as your credentials file: copy it to ~/.client_secrets.json. Note: client_secrets.json is a file you can download from the developer console, the credentials file is something auto generated after the first time the script is run and the google account sign in is followed, the file is stored at ~/.youtube-upload-credentials.json.

If you feel any difficulty to create OAuth 2.0 file, here is the video I made for you: https://youtu.be/kL2oFZt2xHM

Usage

Commands:

python -m youtube_drive -h
usage: youtube-drive [-h] {encode,en,decode,de,upload,up,retrieve,r} ...

options:
  -h, --help            show this help message and exit

commands:
  {encode,en,decode,de,upload,up,retrieve,r}
    encode (en)         encode a file to mp4 video
    decode (de)         decode a video to a file
    upload (up)         upload a file to YouTube
    retrieve (r)        retrieve a video from YouTube save as <filename>

If you install from source, you can run the script directly:

youtube-drive -h
usage: youtube-drive [-h] {encode,en,decode,de,upload,up,retrieve,r} ...

options:
  -h, --help            show this help message and exit

commands:
  {encode,en,decode,de,upload,up,retrieve,r}
    encode (en)         encode a file to mp4 video
    decode (de)         decode a video to a file
    upload (up)         upload a file to YouTube
    retrieve (r)        retrieve a video from YouTube save as <filename>

Upload:

python -m youtube_drive up -h
usage: youtube-drive upload [-h] filename

positional arguments:
  filename    encode file <filename> to a video and upload to YouTube

options:
  -h, --help  show this help message and exit

Retrieve:

python -m youtube_drive r -h
usage: youtube-drive retrieve [-h] [--video-id video_id] [-o filename]

options:
  -h, --help           show this help message and exit
  --video-id video_id  download YouTube video with <video_id>
  -o filename          save file to <filename>

Local Encode:

python -m youtube_drive en -h
usage: youtube-drive encode [-h] [-i input_filename] [--video-fps video_fps] video_filename

positional arguments:
  video_filename        save the video to this filename

options:
  -h, --help            show this help message and exit
  -i input_filename     encode file <input_filename> to a video
  --video-fps video_fps
                        set video fps, default value is 20

Local Decode:

python -m youtube_drive de -h
usage: youtube-drive decode [-h] [-i input_video_filename] filename

positional arguments:
  filename              Save the output file to this filename

options:
  -h, --help            show this help message and exit
  -i input_video_filename
                        decode the video <input_video_filename> to a file

The difference between youtube-drive and YouTubeDrive

I add 4 bytes for representing data length at the beginning for the file for easily padding to video frames

More Repositories

1

gost-install.ipynb

通过 Jupyter Notebook 安装 GOST
Jupyter Notebook
684
star
2

autotranslate

Videos Transcription and Translation with Faster Whisper and ChatGPT
Jupyter Notebook
233
star
3

scel2txt

搜狗细胞词库转鼠须管(Rime)词库
Python
180
star
4

shanghai-lockdown-covid-19

Coronavirus (COVID-19) statistics data in Shanghai lockdown. 封控期间上海疫情数据,包括病例数、死亡数、确诊数、无症状数和疫情地址等。
HTML
159
star
5

ShadowsocksX-NG-GostPlugin

ShadowsocksX-NG 的 gost 插件脚本,方便在 ShadowsocksX-NG 中使用 gost
Shell
119
star
6

PaddleWebOCR

开源的中英文离线 OCR,使用 PaddleOCR 实现,提供了简单的 Web 页面及接口
Vue
115
star
7

chatglm2-6b-colab

Colab for chatglm2-6b
Jupyter Notebook
72
star
8

MQTT-Web-Terminal

Bring any Linux device/server to the web, whenever they have public ip or not
Python
41
star
9

bookbookgo_bot

A Telegram bot for book-searcher. Create and search books index, create your private library on Telegram.
Python
38
star
10

certbot-self-hosting

A certbot container is used similarly to acme.sh
Shell
20
star
11

Alacritty.icns

一组 Alacritty 图标
18
star
12

paipai

上海车牌沪牌拍牌助手(不能使用了,仅供参考)
Python
15
star
13

miniblog

A miniblog demo powered by web.py and rye
Python
11
star
14

meow

Meow~喵~是一个面向新手的 Git/GitHub/GitLab 团队开发协作修炼场所
Python
7
star
15

rime_dict_maker

A tool to make your rime dict
Python
7
star
16

jsmwlwedding

A simple parallax scrolling website for my wedding
SCSS
5
star
17

CN-Traffic-Tickets-Query-Adapter

A pyAdapter for querying traffic tickets in China
Python
3
star
18

picb0

Free Pictures Hosting On Github/Statically
Shell
3
star
19

nucintosh

Nucintosh - Hackintosh on Intel NUC8i5BEH/NUC8i7BEH
2
star
20

rtl8723bu

RTL8723BU WiFi Linux Driver v5.2.17.1 for Raspberry Pi
C
2
star
21

pyqt5-examples

PyQt5 示例
Python
2
star
22

WGD-gobinet

MeiG SLM750 GobiNet Driver for Linux
C
2
star
23

jwow

A very simple non-blocking http server
Java
1
star
24

tesla-instrument-panel

Instrument Panel for Tesla Model 3/Y
JavaScript
1
star
25

akoola_tv

An android app plays like a TV remote controller
Java
1
star
26

lewangdev.github.io

Personal Blog of Le
HTML
1
star
27

catcatgo

Catcatgo, 猫猫快跑 is a fast & simple static site generator powered by Python 3.
HTML
1
star
28

ggwave-fork

C++
1
star
29

folotoy-tool

Flasher tool for FoloToys, running in web browser using WebSerial.
Vue
1
star