Last active
March 21, 2018 23:49
-
-
Save miou-gh/1dc138c0f8c3a546d0af3bfb0790846e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place in ~/.bashrc | |
# replace ~/scripts/ with the directory where you placed the script | |
yt() { | |
(python /home/allie/scripts/youtube.py "$1" </dev/null &>/dev/null &) | |
} | |
############ | |
# youtube.py | |
############ | |
import sys | |
import subprocess | |
import youtube_dl | |
player_run = False | |
p = None | |
def hook(status): | |
global player_run, p | |
if not player_run: | |
player_run = True | |
p = subprocess.Popen(['vlc', status['filename']]) | |
opts = { | |
'format': 'best', | |
'nopart': True, | |
'progress_hooks': [hook], | |
'verbose': True, | |
'outtmpl': '/tmp/%(title)s-%(id)s.%(ext)s', | |
} | |
with youtube_dl.YoutubeDL(opts) as ydl: | |
ydl.download([ sys.argv[1] ]) | |
p.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment