exceptions.py
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
"""Library specific exception definitions."""
from typing import Pattern
from typing import Union
class PytubeError(Exception):
"""Base pytube exception that all others inherent.
This is done to not pollute the built-in exceptions, which *could* result
in unintended errors being unexpectedly and incorrectly handled within
implementers code.
"""
class ExtractError(PytubeError):
"""Data extraction based exception."""
class RegexMatchError(ExtractError):
"""Regex pattern did not return any matches."""
def __init__(self, caller: str, pattern: Union[str, Pattern]):
"""
:param str caller:
Calling function
:param str pattern:
Pattern that failed to match
"""
super().__init__(f"{caller}: could not find match for {pattern}")
self.caller = caller
self.pattern = pattern
class LiveStreamError(ExtractError):
"""Video is a live stream."""
def __init__(self, video_id: str):
"""
:param str video_id:
A YouTube video identifier.
"""
super().__init__(f"{video_id} is streaming live and cannot be loaded")
self.video_id = video_id
class VideoUnavailable(PytubeError):
"""Video is unavailable."""
def __init__(self, video_id: str):
"""
:param str video_id:
A YouTube video identifier.
"""
super().__init__(f"{video_id} is unavailable")
self.video_id = video_id
class VideoPrivate(ExtractError):
def __init__(self, video_id: str):
"""
:param str video_id:
A YouTube video identifier.
"""
super().__init__('%s is a private video' % video_id)
self.video_id = video_id
class RecordingUnavailable(ExtractError):
def __init__(self, video_id: str):
"""
:param str video_id:
A YouTube video identifier.
"""
super().__init__(
'%s does not have a live stream recording available' % video_id
)
self.video_id = video_id
class HTMLParseError(PytubeError):
"""HTML could not be parsed"""