在 youtube-dl python 脚本中应将命令参数放在哪里?

Nic*_*sPP 2 python youtube-dl

我通常使用 youtube-dl 和这样的终端

\n\n

youtube-dl -o \'%(uploader)s - %(title)s.%(ext)s\' URL

\n\n

为了让我的输出命名如下:“频道名称 - title.mp4”\xe2\x80\xa6 它对于单个视频非常有用,但如果我想使用这个 python 脚本来下载Mewfree提供的我的字幕:

\n\n
#!/usr/bin/env python3\n\nimport opml\nimport feedparser\nimport youtube_dl\nimport sys\nfrom glob import glob\nfrom pprint import pprint\n\nif sys.version_info[0] < 3:\n    raise Exception(\'Must be using Python 3\')\n\nfrom time import time, mktime, strptime\nfrom datetime import datetime\n\nif len(glob(\'last.txt\')) == 0:\n    f = open(\'last.txt\', \'w\')\n    f.write(str(time()))\n    print(\'Initialized a last.txt file with current timestamp.\')\n    f.close()\n\nelse:\n    f = open(\'last.txt\', \'r\')\n    content = f.read()\n    f.close()\n\n    outline = opml.parse(\'subs.xml\')\n\n    ptime = datetime.utcfromtimestamp(float(content))\n    ftime = time()\n\n    urls = []\n\n    for i in range(0,len(outline[0])):\n        urls.append(outline[0][i].xmlUrl)\n\n    videos = []\n    for i in range(0,len(urls)):\n        print(\'Parsing through channel \'+str(i+1)+\' out of \'+str(len(urls)), end=\'\\r\')\n        feed = feedparser.parse(urls[i])\n        for j in range(0,len(feed[\'items\'])):\n            timef = feed[\'items\'][j][\'published_parsed\']\n            dt = datetime.fromtimestamp(mktime(timef))\n            if dt > ptime:\n                videos.append(feed[\'items\'][j][\'link\'])\n\n    if len(videos) == 0:\n        print(\'Sorry, no new video found\')\n    else:\n        print(str(len(videos))+\' new videos found\')\n\n    ydl_opts = {\'ignoreerrors\': True}\n\n    with youtube_dl.YoutubeDL(ydl_opts) as ydl:\n        ydl.download(videos)\n\n    f = open(\'last.txt\', \'w\')\n    f.write(str(ftime))\n    f.close()\n
Run Code Online (Sandbox Code Playgroud)\n\n

我有一个问题,因为我对 python 一无所知,而且我不知道在哪里以及如何正确放置我的选项。当然,我认为它会在这附近的某个地方:

\n\n
  ydl_opts = {\'ignoreerrors\': True}\n
Run Code Online (Sandbox Code Playgroud)\n\n

由于\'ignoreerrors\'python 脚本反映了youtube-dl 文档中的--ignore-errorsor选项,所以我想我应该有类似的东西,但我不知道如何添加我的选项,并且我尝试的所有内容都失败了,所以真正知道如何操作的人可以它有效,请告诉我我应该做什么?-i\'output\'\'%(uploader)s - %(title)s.%(ext)s\'

\n

Nic*_*sPP 5

非常感谢 c2huc2hu 他向我指出的第二个链接,我一直在寻找'output'它'outtmpl',所以我修改了脚本,如下所示:

ydl_opts = {'ignoreerrors': True, 'outtmpl': '%(uploader)s - %(title)s.%(ext)s'}
Run Code Online (Sandbox Code Playgroud)

它的工作原理就像我想要的那样。