[Tutor] Wondering about a project
dw
bw_dw at fastmail.fm
Mon Feb 2 19:42:19 CET 2015
Well I've made some progress in terminal mode.
The OS is Ubuntu 12.04 LXDE desktop
This script works.
It prompts for the url, lets the user confirm download and then runs the
video in Gnome-Player.
Once Gnome-Player is dropped by the user, it prompts to either move the
file to storage or delete. Then returns for another round.
-----------------------------------------------
#!/usr/bin/python
from subprocess import call
import glob,re,shutil,os,time
geturl=""
while True:
call(["clear"])
geturl= input("Enter Youtube URL ")
if len(geturl)==0:
break
def unquote(geturl):
return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m:
chr(int(m.group(1),16)), geturl)
print("Download %s?" %geturl)
answer= raw_input("Press ENTER to continue: ")
call(["youtube-dl", geturl])
#get the youtube video file names
YTfile=glob.glob('./*.mp4')
print("%s Youtube files: "%(YTfile))
#clean up the file names
for x in range(len(YTfile)):
YTfile[x] = YTfile[x][2:]
print("%s: "+str(x)+" "+YTfile[x]+'\n')
#now play the youtube video
#for x in range(len(YTfile)):
call(["gnome-mplayer", YTfile[0]])
#Decide to save the file or delete it
dofile = raw_input('Save or Delete: S or D ')
if dofile=='S':
#save the file by moving it into folder
for x in range(len(YTfile)):
shutil.move(YTfile[x],'/home/user/Documents/YOUTUBEFILES')
#delete the file
else:
os.remove(YTfile[0])
print("Deleted %s "%YTfile[0])
time.sleep( 3 )
--
Bw_dw at fastmail.net
More information about the Tutor
mailing list