Skip to content

Instantly share code, notes, and snippets.

@kato-megumi
Last active February 18, 2021 10:57
Show Gist options
  • Save kato-megumi/e5e5bfb3435e0c802aae02452419e392 to your computer and use it in GitHub Desktop.
Save kato-megumi/e5e5bfb3435e0c802aae02452419e392 to your computer and use it in GitHub Desktop.
Youtube on Rasp using vlc, open by phone via termux
#!/usr/bin/python3
#~play.py
import sys,os,subprocess
os.system("killall vlc")
ps = subprocess.run(["pgrep", "play.py"], stdout=subprocess.PIPE).stdout.decode('utf-8').split('\n')[:-2]
for p in ps:
os.system("kill -9 "+p)
if (len(sys.argv)==1): exit()
if 'list' in sys.argv[1]:
ids = subprocess.run(['youtube-dl', '--flat-playlist','--get-id',sys.argv[1]], stdout=subprocess.PIPE).stdout.decode('utf-8').split('\n')[:-1]
else:
id = sys.argv[1][-11:]
link = "https://www.youtube.com/watch?v="+id+"&list=RD"+id
ids = subprocess.run(['youtube-dl', '--flat-playlist','--get-id',link], stdout=subprocess.PIPE).stdout.decode('utf-8').split('\n')[:-1]
print(link)
print(ids)
#exit()
for id in ids:
result = subprocess.run(['youtube-dl', '-g','-f','bestvideo[vcodec!=?vp9][vcodec!*=av01]+bestaudio/best',"https://www.youtube.com/watch?v="+id], stdout=subprocess.PIPE).stdout.decode('utf-8').split('\n')
print(len(result),result)
if (len(result)<=2):
subprocess.run(['vlc','-f',result[0],'vlc://quit'])
else:
subprocess.run(['vlc','-f',result[0],'--input-slave',result[1],'vlc://quit'])
#!/data/data/com.termux/files/usr/bin/bash
#~/bin/termux-url-opener
ssh -t pi@raspberrypi "~/play.py $1"
@kato-megumi
Copy link
Author

add phone ssh key to authorized_keys of rpi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment