源代码
# -*- coding:utf-8 -*-
from yt_dlp import YoutubeDL
import pickle,os
os.environ["http_proxy"] = "http://127.0.0.1:10809"
os.environ["https_proxy"] = "http://127.0.0.1:10809"
with open('../urls.pkl','rb')as f:
urls_list=pickle.load(f)
# youtube测试网址
# https://www.youtube.com/watch?v=BaW_jenozKc
urls_list=[ "https://www.youtube.com/watch?v="+url for url in urls_list]
# urls_list = ['https://www.youtube.com/watch?v=BaW_jenozKc']
# print(urls_list)
start_time = '00:00:5' # start time in HH:MM:SS format
end_time = '00:00:10'
yld_opts={
'format': 'bestvideo[height<=360]',
'noplaylist': True,
'writesubtitles': False,
'audio': False,
'outtmpl':'../origin_data/%(title)s_%(id)s.%(ext)s',
'concurrent_fragment_downloads': 4,
'limit_rate': None,
# 'download_sections': f"*{start_time}-{end_time}"
}
x=1
with YoutubeDL(yld_opts) as ydl:
ydl.download(urls_list[50:100])
进入YoutubeDL.py
- __init__最后一行,返回self.archive=None
...
except OSError as ioe:
if ioe.errno != errno.ENOENT:
raise
return archive
self.archive = preload_download_archive(self.params.get('download_archive'))
...
- download()
for url in url_list:
self.__download_wrapper(self.extract_info)(
url, force_generic_extractor=self.params.get('force_generic_extractor', False))
return self._download_retcode
force_generic_extractor:False
3. extract_info
if ie_key:
ies = {ie_key: self._ies[ie_key]} if ie_key in self._ies else {}
else:
ies = self._ies
ies=self._ies