hbmartin commited on
Commit
4af667e
·
1 Parent(s): 3456148

fix misspellings

Browse files
pytube/captions.py CHANGED
@@ -41,12 +41,11 @@ class Caption:
41
  :returns:
42
  SubRip Subtitle (str) formatted time duration.
43
 
44
- >>> float_to_srt_time_format(3.89)
45
- '00:00:03,890'
46
  """
47
- frac, whole = math.modf(d)
48
  time_fmt = time.strftime("%H:%M:%S,", time.gmtime(whole))
49
- ms = "{:.3f}".format(frac).replace("0.", "")
50
  return time_fmt + ms
51
 
52
  def xml_caption_to_srt(self, xml_captions: str) -> str:
 
41
  :returns:
42
  SubRip Subtitle (str) formatted time duration.
43
 
44
+ float_to_srt_time_format(3.89) -> '00:00:03,890'
 
45
  """
46
+ fraction, whole = math.modf(d)
47
  time_fmt = time.strftime("%H:%M:%S,", time.gmtime(whole))
48
+ ms = "{:.3f}".format(fraction).replace("0.", "")
49
  return time_fmt + ms
50
 
51
  def xml_caption_to_srt(self, xml_captions: str) -> str:
pytube/cipher.py CHANGED
@@ -254,15 +254,15 @@ def get_signature(js: str, ciphered_signature: str) -> str:
254
  Decrypted signature required to download the media content.
255
 
256
  """
257
- tplan = get_transform_plan(js)
258
  # DE.AJ(a,15) => DE, AJ(a,15)
259
- var, _ = tplan[0].split(".")
260
- tmap = get_transform_map(js, var)
261
  signature = [s for s in ciphered_signature]
262
 
263
- for js_func in tplan:
264
  name, argument = parse_function(js_func)
265
- signature = tmap[name](signature, int(argument))
266
  logger.debug(
267
  "applied transform function\n%s",
268
  pprint.pformat(
@@ -270,7 +270,7 @@ def get_signature(js: str, ciphered_signature: str) -> str:
270
  "output": "".join(signature),
271
  "js_function": name,
272
  "argument": int(argument),
273
- "function": tmap[name],
274
  },
275
  indent=2,
276
  ),
 
254
  Decrypted signature required to download the media content.
255
 
256
  """
257
+ transform_plan = get_transform_plan(js)
258
  # DE.AJ(a,15) => DE, AJ(a,15)
259
+ var, _ = transform_plan[0].split(".")
260
+ transform_map = get_transform_map(js, var)
261
  signature = [s for s in ciphered_signature]
262
 
263
+ for js_func in transform_plan:
264
  name, argument = parse_function(js_func)
265
+ signature = transform_map[name](signature, int(argument))
266
  logger.debug(
267
  "applied transform function\n%s",
268
  pprint.pformat(
 
270
  "output": "".join(signature),
271
  "js_function": name,
272
  "argument": int(argument),
273
+ "function": transform_map[name],
274
  },
275
  indent=2,
276
  ),
pytube/cli.py CHANGED
@@ -25,7 +25,7 @@ def main():
25
  "--version", action="version", version="%(prog)s " + __version__,
26
  )
27
  parser.add_argument(
28
- "--itag", type=int, help=("The itag for the desired stream"),
29
  )
30
  parser.add_argument(
31
  "-l",
@@ -47,7 +47,7 @@ def main():
47
  parser.add_argument(
48
  "--build-playback-report",
49
  action="store_true",
50
- help=("Save the html and js to disk"),
51
  )
52
 
53
  args = parser.parse_args()
@@ -117,10 +117,10 @@ def display_progress_bar(
117
  written to disk.
118
  :param int filesize:
119
  File size of the media stream in bytes.
120
- :param ch str:
121
  Character to use for presenting progress segment.
122
  :param float scale:
123
- Scale multipler to reduce progress bar size.
124
 
125
  """
126
  _, columns = get_terminal_size()
 
25
  "--version", action="version", version="%(prog)s " + __version__,
26
  )
27
  parser.add_argument(
28
+ "--itag", type=int, help="The itag for the desired stream",
29
  )
30
  parser.add_argument(
31
  "-l",
 
47
  parser.add_argument(
48
  "--build-playback-report",
49
  action="store_true",
50
+ help="Save the html and js to disk",
51
  )
52
 
53
  args = parser.parse_args()
 
117
  written to disk.
118
  :param int filesize:
119
  File size of the media stream in bytes.
120
+ :param str ch:
121
  Character to use for presenting progress segment.
122
  :param float scale:
123
+ Scale multiplier to reduce progress bar size.
124
 
125
  """
126
  _, columns = get_terminal_size()
pytube/contrib/playlist.py CHANGED
@@ -134,7 +134,7 @@ class Playlist(object):
134
  :type prefix_number: bool
135
  :param reverse_numbering:
136
  (optional) Lets you number playlists in reverse, since some
137
- playlists are ordered newest -> oldests.
138
  :type reverse_numbering: bool
139
  """
140
 
@@ -180,14 +180,14 @@ class Playlist(object):
180
  req = request.get(url)
181
  open_tag = "<title>"
182
  end_tag = "</title>"
183
- matchresult = re.compile(open_tag + "(.+?)" + end_tag)
184
- matchresult = matchresult.search(req).group()
185
- matchresult = matchresult.replace(open_tag, "")
186
- matchresult = matchresult.replace(end_tag, "")
187
- matchresult = matchresult.replace("- YouTube", "")
188
- matchresult = matchresult.strip()
189
-
190
- return matchresult
191
  except Exception as e:
192
  logger.debug(e)
193
  return None
 
134
  :type prefix_number: bool
135
  :param reverse_numbering:
136
  (optional) Lets you number playlists in reverse, since some
137
+ playlists are ordered newest -> oldest.
138
  :type reverse_numbering: bool
139
  """
140
 
 
180
  req = request.get(url)
181
  open_tag = "<title>"
182
  end_tag = "</title>"
183
+ match_result = re.compile(open_tag + "(.+?)" + end_tag)
184
+ match_result = match_result.search(req).group()
185
+ match_result = match_result.replace(open_tag, "")
186
+ match_result = match_result.replace(end_tag, "")
187
+ match_result = match_result.replace("- YouTube", "")
188
+ match_result = match_result.strip()
189
+
190
+ return match_result
191
  except Exception as e:
192
  logger.debug(e)
193
  return None
pytube/extract.py CHANGED
@@ -165,8 +165,7 @@ def mime_type_codec(mime_type_codec: str) -> Tuple[str, List[str]]:
165
 
166
  **Example**:
167
 
168
- >>> mime_type_codec('audio/webm; codecs="opus"')
169
- ('audio/webm', ['opus'])
170
 
171
  :param str mime_type_codec:
172
  String containing mime type and codecs.
 
165
 
166
  **Example**:
167
 
168
+ mime_type_codec('audio/webm; codecs="opus"') -> ('audio/webm', ['opus'])
 
169
 
170
  :param str mime_type_codec:
171
  String containing mime type and codecs.
pytube/helpers.py CHANGED
@@ -106,8 +106,8 @@ def safe_filename(s: str, max_length: int = 255) -> str:
106
  A sanitized string.
107
  """
108
  # Characters in range 0-31 (0x00-0x1F) are not allowed in ntfs filenames.
109
- ntfs_chrs = [chr(i) for i in range(0, 31)]
110
- chrs = [
111
  '"',
112
  "\#",
113
  "\$",
@@ -129,7 +129,7 @@ def safe_filename(s: str, max_length: int = 255) -> str:
129
  "\~",
130
  "\\\\",
131
  ]
132
- pattern = "|".join(ntfs_chrs + chrs)
133
  regex = re.compile(pattern, re.UNICODE)
134
  filename = regex.sub("", s)
135
  return filename[:max_length].rsplit(" ", 0)[0]
 
106
  A sanitized string.
107
  """
108
  # Characters in range 0-31 (0x00-0x1F) are not allowed in ntfs filenames.
109
+ ntfs_characters = [chr(i) for i in range(0, 31)]
110
+ characters = [
111
  '"',
112
  "\#",
113
  "\$",
 
129
  "\~",
130
  "\\\\",
131
  ]
132
+ pattern = "|".join(ntfs_characters + characters)
133
  regex = re.compile(pattern, re.UNICODE)
134
  filename = regex.sub("", s)
135
  return filename[:max_length].rsplit(" ", 0)[0]
pytube/mixins.py CHANGED
@@ -37,10 +37,11 @@ def apply_signature(config_args: Dict, fmt: str, js: str) -> None:
37
  .get("liveStreamability")
38
  )
39
  for i, stream in enumerate(stream_manifest):
40
- if "url" in stream:
41
  url = stream["url"]
42
- elif live_stream:
43
- raise LiveStreamError("Video is currently being streamed live")
 
44
  # 403 Forbidden fix.
45
  if "signature" in url or (
46
  "s" not in stream and ("&sig=" in url or "&lsig=" in url)
 
37
  .get("liveStreamability")
38
  )
39
  for i, stream in enumerate(stream_manifest):
40
+ try:
41
  url = stream["url"]
42
+ except KeyError:
43
+ if live_stream:
44
+ raise LiveStreamError("Video is currently being streamed live")
45
  # 403 Forbidden fix.
46
  if "signature" in url or (
47
  "s" not in stream and ("&sig=" in url or "&lsig=" in url)
pytube/streams.py CHANGED
@@ -222,7 +222,7 @@ class Stream(object):
222
  (optional) A string that will be prepended to the filename.
223
  For example a number in a playlist or the name of a series.
224
  If one is not specified, nothing will be prepended
225
- This is seperate from filename so you can use the default
226
  filename but still add a prefix.
227
  :type filename_prefix: str or None
228
 
 
222
  (optional) A string that will be prepended to the filename.
223
  For example a number in a playlist or the name of a series.
224
  If one is not specified, nothing will be prepended
225
+ This is separate from filename so you can use the default
226
  filename but still add a prefix.
227
  :type filename_prefix: str or None
228