Last active
October 31, 2018 20:54
-
-
Save AmanTifli/7394882 to your computer and use it in GitHub Desktop.
small python script which takes a youtube url and streams the video directly to your desktop. Requires youtube-dl and mplayer.
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
#!/usr/bin/env/python | |
from os import system as syscommand | |
class PlayVideo(): | |
def __init__(self): | |
self.getUrl(); | |
def getUrl(self): | |
url = raw_input("Enter a youtube url: ") | |
do = True; | |
#keep looping till a valid answer is accepted | |
while(do == True): | |
useCookies = raw_input("Use cookies? [Y/n]: ") | |
if useCookies == "Y" or useCookies == "y": | |
useCookies = True; | |
do = False; | |
elif useCookies == "n" or useCookies == "N": | |
useCookies = False; | |
do = False; | |
else: | |
print "Invalid input. Please enter again..." | |
self.playVideo(url,useCookies); | |
def playVideo(self,url,requireCookies): | |
ytURL = url; | |
if requireCookies: | |
syscommand("mplayer -cookies -cookies-file $HOME/tmp/ytcookie.txt $(youtube-dl -g --cookies $HOME/tmp/ytcookie.txt \"%s\")" % ytURL) | |
else: | |
syscommand("mplayer $(youtube-dl -g \"%s\")" % ytURL); | |
if __name__ == '__main__': | |
PlayVideo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment