2
0
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:
kev
2015-07-13 00:43:50 +08:00
parent f7ab308b18
commit 0719f68028
7 changed files with 126 additions and 1 deletions

View 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"]

View 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/

View 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"]

View 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
```

View 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

View 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)