mirror of
https://github.com/vimagick/dockerfiles.git
synced 2025-12-21 13:23:02 +01:00
add youtube-dl
This commit is contained in:
19
youtube/youtube-dl/Dockerfile
Normal file
19
youtube/youtube-dl/Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Dockerfile for youtube-dl
|
||||
#
|
||||
|
||||
FROM alpine
|
||||
MAINTAINER kev <noreply@datageek.info>
|
||||
|
||||
RUN apk add -U ca-certificates \
|
||||
ffmpeg \
|
||||
python \
|
||||
&& rm -rf /var/cache/apk/* \
|
||||
&& wget -O- https://bootstrap.pypa.io/get-pip.py | python \
|
||||
&& pip install youtube-dl \
|
||||
&& mkdir -p /data
|
||||
|
||||
WORKDIR /data
|
||||
|
||||
ENTRYPOINT ["youtube-dl"]
|
||||
CMD ["--help"]
|
||||
23
youtube/youtube-dl/README.md
Normal file
23
youtube/youtube-dl/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
youtube-dl
|
||||
==========
|
||||
|
||||
[`youtube-dl`][1] is a small command-line program to download videos from
|
||||
<https://www.youtube.com/> and a few more sites.
|
||||
|
||||
## Tutorial
|
||||
|
||||
```
|
||||
# create a alias
|
||||
$ alias yt='docker run --rm -v `pwd`:/data vimagick/youtube-dl'
|
||||
|
||||
# list all formats
|
||||
$ yt -F nVjsGKrE6E8
|
||||
|
||||
# download it
|
||||
$ yt nVjsGKrE6E8
|
||||
|
||||
# play it
|
||||
$ vlc *-nVjsGKrE6E8.mp4
|
||||
```
|
||||
|
||||
[1]: https://rg3.github.io/youtube-dl/
|
||||
16
youtube/youtube-worker/Dockerfile
Normal file
16
youtube/youtube-worker/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# Dockerfile for youtube-worker
|
||||
#
|
||||
|
||||
FROM alpine
|
||||
MAINTAINER kev <noreplay@datageek.info>
|
||||
|
||||
RUN apk add -U ca-certificates py-pip \
|
||||
&& rm -rf /var/cache/apk/* \
|
||||
&& pip install redis youtube-dl
|
||||
|
||||
COPY worker.py /code/
|
||||
VOLUME /data
|
||||
WORKDIR /data
|
||||
|
||||
CMD ["python", "/code/worker.py"]
|
||||
55
youtube/youtube-worker/README.md
Normal file
55
youtube/youtube-worker/README.md
Normal file
@@ -0,0 +1,55 @@
|
||||
youtube-worker
|
||||
==============
|
||||
|
||||
youtube-worker = youtube-dl + redis
|
||||
|
||||
## docker-compose.yml
|
||||
|
||||
```
|
||||
worker:
|
||||
image: vimagick/youtube-worker
|
||||
links:
|
||||
- redis
|
||||
volumes:
|
||||
- data:/data
|
||||
environment:
|
||||
- PASSWORD=secret-passwd
|
||||
restart: always
|
||||
|
||||
redis:
|
||||
image: redis
|
||||
command: redis-server --requirepass 'secret-passwd'
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: always
|
||||
```
|
||||
|
||||
## server
|
||||
|
||||
```
|
||||
$ cd ~/fig/youtube/
|
||||
|
||||
$ docker-compose up -d
|
||||
|
||||
$ docker-compose logs
|
||||
Attaching to youtube_worker_1
|
||||
worker_1 | 2015-07-12T16:07:07 [INFO] connect redis
|
||||
worker_1 | 2015-07-12T16:07:26 [INFO] process: %s
|
||||
worker_1 | [youtube] os6U77Hhm_s: Downloading webpage
|
||||
worker_1 | [youtube] os6U77Hhm_s: Downloading video info webpage
|
||||
worker_1 | [youtube] os6U77Hhm_s: Extracting video information
|
||||
worker_1 | [youtube] os6U77Hhm_s: Downloading DASH manifest
|
||||
worker_1 | [youtube] os6U77Hhm_s: Downloading DASH manifest
|
||||
worker_1 | [download] Destination: Shia LaBeouf TED Talk-os6U77Hhm_s.mp4
|
||||
[download] 100% of 11.03MiB in 00:0297MiB/s ETA 00:00known ETA
|
||||
```
|
||||
|
||||
## client
|
||||
|
||||
```
|
||||
$ redis-cli -h server -a 'secret-passwd'
|
||||
server> lpush urls 'https://www.youtube.com/watch?v=os6U77Hhm_s'
|
||||
server> quit
|
||||
|
||||
$ rsync -ahP user@server:fig/youtube/data ~/Movies/youtube
|
||||
```
|
||||
16
youtube/youtube-worker/docker-compose.yml
Normal file
16
youtube/youtube-worker/docker-compose.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
worker:
|
||||
image: vimagick/youtube-worker
|
||||
links:
|
||||
- redis
|
||||
volumes:
|
||||
- data:/data
|
||||
environment:
|
||||
- PASSWORD=secret-passwd
|
||||
restart: always
|
||||
|
||||
redis:
|
||||
image: redis
|
||||
command: redis-server --requirepass 'secret-passwd'
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: always
|
||||
32
youtube/youtube-worker/worker.py
Executable file
32
youtube/youtube-worker/worker.py
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# youtube_dl worker
|
||||
#
|
||||
|
||||
import logging
|
||||
import os
|
||||
import redis
|
||||
import youtube_dl
|
||||
|
||||
|
||||
def download(url):
|
||||
|
||||
with youtube_dl.YoutubeDL() as ydl:
|
||||
ydl.download([url])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(msg)s', datefmt='%FT%T', level='INFO')
|
||||
logging.info('connect redis')
|
||||
rdb = redis.StrictRedis(host='redis', password=os.getenv('PASSWORD'))
|
||||
rdb.ping()
|
||||
|
||||
while True:
|
||||
try:
|
||||
_, url = rdb.brpop('urls')
|
||||
logging.info('process: %s', url)
|
||||
download(url)
|
||||
except Exception as ex:
|
||||
logging.error('error: %s', ex)
|
||||
|
||||
Reference in New Issue
Block a user