我正在为YouTube的-DL的API
在tkinter
&python
和需要知道:
我努力了:
import subprocess
def execute(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
# Poll process for new output until finished
while True:
nextline = process.stdout.readline()
if nextline == '' and process.poll() != None:
break
sys.stdout.write(nextline.decode('utf-8'))
sys.stdout.flush()
output = process.communicate()[0]
exitCode = process.returncode
if (exitCode == 0):
return output
else:
raise ProcessException(command, exitCode, output)
execute("youtube-dl.exe www.youtube.com/watch?v=9bZkp7q19f0 -t")
但不得不等待,直到完成下载给我的信息;也许有后,来自YouTube-DL源代码信息的一种方式。
尝试是这样的:
from youtube_dl import YoutubeDL
video = "http://www.youtube.com/watch?v=BaW_jenozKc"
with YoutubeDL(youtube_dl_opts) as ydl:
info_dict = ydl.extract_info(video, download=False)
video_url = info_dict.get("url", None)
video_id = info_dict.get("id", None)
video_title = info_dict.get('title', None)
你可能现在想通了这一点,但它可能会帮助别人。
subprocess
;您可以直接使用该模块像往常一样Python模块;参阅本:use youtube-dl module这需要下载源代码,不仅安装应用系统。subprocess
;你应该添加下列参数:冗长/模拟选项:
-q, --quiet activates quiet mode
-s, --simulate do not download the video and do not write anything to disk
--skip-download do not download the video
-g, --get-url simulate, quiet but print URL
-e, --get-title simulate, quiet but print title
--get-thumbnail simulate, quiet but print thumbnail URL
--get-description simulate, quiet but print video description
--get-filename simulate, quiet but print output filename
--get-format simulate, quiet but print output format
sys.output
,通过沟通返回的最后一行;我的建议是简单的未经测试的例子:DEF执行(命令):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
#Poll process for new output until it is finished
while True:
nextline = process.stdout.readline()
if nextline == '' and process.poll() != None:
break
yield nextline
我已经用它在:
for i in execute("sudo apt-get update"):
print i
在任何情况下,不要忘记更新版本。