本文整理汇总了Python中youtube_dl.utils.DownloadError方法的典型用法代码示例。如果您正苦于以下问题:Python utils.DownloadError方法的具体用法?Python utils.DownloadError怎么用?Python utils.DownloadError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类youtube_dl.utils
的用法示例。
在下文中一共展示了utils.DownloadError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ignore_tmr_failure
# 需要导入模块: from youtube_dl import utils [as 别名]
# 或者: from youtube_dl.utils import DownloadError [as 别名]
def ignore_tmr_failure(func):
"""
Ignore "Too many requests" failures in a test.
YouTube will sometimes throttle us and cause the tests to flap. This decorator
catches the "Too many requests" exceptions in tests and ignores them.
"""
def wrapper(*args):
try:
return func(*args)
except DownloadError as err:
if "HTTP Error 429:" in str(err):
pass
else:
raise
return wrapper
示例2: on_update
# 需要导入模块: from youtube_dl import utils [as 别名]
# 或者: from youtube_dl.utils import DownloadError [as 别名]
def on_update(self, status):
if options['debug']:
print('incoming status: acct={!r}'.format(status.account.acct))
if self.users and normalize_username(status.account.acct, self.instance) not in self.users:
if options['debug']:
print('skipping status due to username filtering')
return
tags = extract_tags(status)
if options['debug']:
print('expecting: {!r}, extracted tags: {!r}'.format(LISTEN_TO_HASHTAG, tags))
if LISTEN_TO_HASHTAG in tags:
links = extract_links(status)
if options['debug']:
print('links: {!r}'.format(links))
for link in links:
try:
click.echo('==> Trying {}'.format(link))
self.queue.add(link)
return
except DownloadError:
pass
示例3: download_video
# 需要导入模块: from youtube_dl import utils [as 别名]
# 或者: from youtube_dl.utils import DownloadError [as 别名]
def download_video(viewkey, name="single_videos"):
"""Download the video."""
# Decide which domain should be used, depending if the user has a premium account
is_premium = os.path.exists("cookie_file")
if is_premium:
video_url = f"https://www.pornhubpremium.com/view_video.php?viewkey={viewkey}"
else:
video_url = f"https://www.pornhub.com/view_video.php?viewkey={viewkey}"
options = {
"outtmpl": f"~/pornhub/{name}/%(title)s.%(ext)s",
"format": "best",
"quiet": True,
"retries": 3,
"nooverwrites": False,
"continuedl": True,
}
if is_premium:
options["cookiefile"] = "cookie_file"
ydl = youtube_dl.YoutubeDL(options)
tries = 0
while True:
try:
logger.info(f"Start downloading: {video_url}")
info = ydl.extract_info(video_url)
info["out_path"] = f'~/pornhub/{name}/{info["title"]}.{info["ext"]}'
return True, info
except TypeError:
# This is an error that seems to occurr from time to time
# A short wait and retry often seems to fix the problem
# This is something about pornhub not properly loading the video.
logger.info("Got TypeError bug")
time.sleep(20)
tries += 1
# If this happens too many times, something else must be broken.
if tries > 10:
return False, None
continue
except DownloadError:
# We got a download error.
# Ignore for now and continue downloading the other videos
logger.error(f"DownloadError: Failed to download video: {viewkey}.")
return False, None
time.sleep(6)
return False, None
示例4: add_stream_entry
# 需要导入模块: from youtube_dl import utils [as 别名]
# 或者: from youtube_dl.utils import DownloadError [as 别名]
def add_stream_entry(self, song_url, info=None, **meta):
if info is None:
info = {'title': song_url, 'extractor': None}
try:
info = await self.downloader.extract_info(self.loop, song_url, download=False)
except DownloadError as e:
if e.exc_info[0] == UnsupportedError: # ytdl doesn't like it but its probably a stream
log.debug("Assuming content is a direct stream")
elif e.exc_info[0] == URLError:
if os.path.exists(os.path.abspath(song_url)):
raise ExtractionError("This is not a stream, this is a file path.")
else: # it might be a file path that just doesn't exist
raise ExtractionError("Invalid input: {0.exc_info[0]}: {0.exc_info[1].reason}".format(e))
else:
# traceback.print_exc()
raise ExtractionError("Unknown error: {}".format(e))
except Exception as e:
log.error('Could not extract information from {} ({}), falling back to direct'.format(song_url, e), exc_info=True)
if info.get('is_live') is None and info.get('extractor', None) is not 'generic': # wew hacky
raise ExtractionError("This is not a stream.")
dest_url = song_url
if info.get('extractor'):
dest_url = info.get('url')
if info.get('extractor', None) == 'twitch:stream': # may need to add other twitch types
title = info.get('description')
else:
title = info.get('title', 'Untitled')
# TODO: A bit more validation, "~stream some_url" should not just say :ok_hand:
entry = StreamPlaylistEntry(
self,
song_url,
title,
destination = dest_url,
**meta
)
self._add_entry(entry)
return entry, len(self.entries)