def youtube_download(self,url,id):
#download_command=['youtube-dl -f bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio\
# --merge-output-format mp4 -o /Users/wujishanxia/Downloads/test.mp4',url]
command='youtube-dl'+' -f bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'+' -o'+' '+str(id)+'.mp4'+' '+url
#thread=threading.Thread(target=self.download,args=(command,id))
#thread.setDaemon(True)
#thread.start()
download=subprocess.Popen(command,shell=True)
#download = subprocess.Popen('echo "hello"',shell=True)
download.wait()
#with youtube_dl.YoutubeDL() as ydl:
# ydl.download(['http://www.bilibili.com/video/av2331280?from=search&seid=831467570734192523'])
print 'download video successfully'
gif_command='ffmpeg -ss 20 -t 20 -i'+' '+str(id)+'.mp4 -s 320x240 -f gif'+' '+str(id)+'.gif'
gif=subprocess.Popen(gif_command,shell=True)
gif.wait()
print 'generate gif successfully'
cp_command='cp'+' '+str(id)+'.gif'+' /home/www/public/media'
cp = subprocess.Popen(cp_command, shell=True)
cp.wait()
print 'copy gif to media successfully'
rm_command='rm'+' '+str(id)+'.mp4'
rm = subprocess.Popen(rm_command,shell=True)
rm.wait()
print 'rm mp4 successfully'
评论列表
文章目录