Skip to content

Instantly share code, notes, and snippets.

@miou-gh
Last active March 21, 2018 23:49
Show Gist options
  • Save miou-gh/1dc138c0f8c3a546d0af3bfb0790846e to your computer and use it in GitHub Desktop.
Save miou-gh/1dc138c0f8c3a546d0af3bfb0790846e to your computer and use it in GitHub Desktop.
# 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