File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 1
1
import re
2
- from typing import List , Optional , cast
2
+ from typing import List , Optional , cast , overload
3
3
4
4
import warnings
5
5
from contextlib import contextmanager
@@ -94,8 +94,16 @@ def get_outer_html(self) -> str:
94
94
def __getitem__ (self , name : str ) -> str :
95
95
return cast (str , super ().__getitem__ (name ))
96
96
97
- def get (self , name : str ) -> Optional [str ]:
98
- return cast (Optional [str ], super ().get (name ))
97
+ @overload
98
+ def get (self , name : str , default : str = ...) -> str :
99
+ ...
100
+
101
+ @overload
102
+ def get (self , name : str , default : None = ...) -> Optional [str ]:
103
+ ...
104
+
105
+ def get (self , name : str , default : Optional [str ] = None ) -> Optional [str ]:
106
+ return cast (Optional [str ], super ().get (name , default ))
99
107
100
108
def get_list (self , name : str ) -> List [str ]:
101
109
value = super ().get (name )
Original file line number Diff line number Diff line change @@ -101,10 +101,14 @@ def get_video_captions(
101
101
captions = []
102
102
103
103
for item in soup .select ("text" ):
104
+
105
+ # NOTE: sometimes duration is absent. I don't really
106
+ # know what is the best solution there (merging with
107
+ # previous item?). So for now, we default duration to 0.
104
108
captions .append (
105
109
YouTubeCaptionLine (
106
110
float (item ["start" ]),
107
- float (item [ "dur" ] ),
111
+ float (item . get ( "dur" , "0" ) ),
108
112
unescape (item .get_text ().strip ()),
109
113
)
110
114
)
You can’t perform that action at this time.
0 commit comments