我想提出一个API在YouTube的-DL 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")
Run Code Online (Sandbox Code Playgroud)
来自这个问题
但它必须等到完成下载才能给我信息; 也许有一种从youtube-dl源代码获取信息的方法.
och*_*che 19
尝试这样的事情:
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)
Run Code Online (Sandbox Code Playgroud)
你现在可能已经想到了这一点,但它可能对其他人有帮助.
subprocess;您可以像通常的python模块一样直接使用该模块;请参考:使用youtube-dl模块,
这不仅需要下载源代码,而且不仅要将应用程序安装到系统中。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
Run Code Online (Sandbox Code Playgroud)
sys.output,由通讯返回;我建议这个简单的未经测试的例子: def execute(命令):
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
Run Code Online (Sandbox Code Playgroud)
我已经在:
for i in execute("sudo apt-get update"):
print i
Run Code Online (Sandbox Code Playgroud)
在任何情况下,请不要忘记更新您的版本。