tweaks to logging
Browse files- pytube/cipher.py +14 -3
- pytube/helpers.py +2 -2
- pytube/logging.py +3 -2
- pytube/mixins.py +3 -2
- pytube/streams.py +3 -3
pytube/cipher.py
CHANGED
@@ -18,9 +18,11 @@ signature and decoding it.
|
|
18 |
from __future__ import absolute_import
|
19 |
|
20 |
import logging
|
|
|
21 |
import re
|
22 |
from itertools import chain
|
23 |
|
|
|
24 |
from pytube.helpers import memoize
|
25 |
from pytube.helpers import regex_search
|
26 |
|
@@ -173,7 +175,10 @@ def map_functions(js_func):
|
|
173 |
for pattern, fn in mapper:
|
174 |
if re.search(pattern, js_func):
|
175 |
return fn
|
176 |
-
|
|
|
|
|
|
|
177 |
|
178 |
|
179 |
def parse_function(js_func):
|
@@ -218,7 +223,13 @@ def get_signature(js, ciphered_signature):
|
|
218 |
name, argument = parse_function(js_func)
|
219 |
signature = tmap[name](signature, int(argument))
|
220 |
logger.debug(
|
221 |
-
'
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
)
|
224 |
return ''.join(signature)
|
|
|
18 |
from __future__ import absolute_import
|
19 |
|
20 |
import logging
|
21 |
+
import pprint
|
22 |
import re
|
23 |
from itertools import chain
|
24 |
|
25 |
+
from pytube.exceptions import RegexMatchError
|
26 |
from pytube.helpers import memoize
|
27 |
from pytube.helpers import regex_search
|
28 |
|
|
|
175 |
for pattern, fn in mapper:
|
176 |
if re.search(pattern, js_func):
|
177 |
return fn
|
178 |
+
raise RegexMatchError(
|
179 |
+
'could not find python equivalent function for: ',
|
180 |
+
js_func,
|
181 |
+
)
|
182 |
|
183 |
|
184 |
def parse_function(js_func):
|
|
|
223 |
name, argument = parse_function(js_func)
|
224 |
signature = tmap[name](signature, int(argument))
|
225 |
logger.debug(
|
226 |
+
'applied transform function\n%s', pprint.pformat(
|
227 |
+
{
|
228 |
+
'output': ''.join(signature),
|
229 |
+
'js_function': name,
|
230 |
+
'argument': int(argument),
|
231 |
+
'function': tmap[name],
|
232 |
+
}, indent=2,
|
233 |
+
),
|
234 |
)
|
235 |
return ''.join(signature)
|
pytube/helpers.py
CHANGED
@@ -9,8 +9,8 @@ Various helper functions implemented by pytube.
|
|
9 |
from __future__ import absolute_import
|
10 |
|
11 |
import functools
|
12 |
-
import json
|
13 |
import logging
|
|
|
14 |
import re
|
15 |
|
16 |
from pytube.exceptions import RegexMatchError
|
@@ -35,7 +35,7 @@ def regex_search(pattern, string, groups=False, group=None, flags=0):
|
|
35 |
results = regex.search(string)
|
36 |
logger.debug(
|
37 |
'finished regex search: %s',
|
38 |
-
|
39 |
{
|
40 |
'pattern': pattern,
|
41 |
'results': results.group(0),
|
|
|
9 |
from __future__ import absolute_import
|
10 |
|
11 |
import functools
|
|
|
12 |
import logging
|
13 |
+
import pprint
|
14 |
import re
|
15 |
|
16 |
from pytube.exceptions import RegexMatchError
|
|
|
35 |
results = regex.search(string)
|
36 |
logger.debug(
|
37 |
'finished regex search: %s',
|
38 |
+
pprint.pprint(
|
39 |
{
|
40 |
'pattern': pattern,
|
41 |
'results': results.group(0),
|
pytube/logging.py
CHANGED
@@ -11,8 +11,9 @@ import logging
|
|
11 |
|
12 |
|
13 |
def create_logger(level=logging.DEBUG):
|
14 |
-
fmt = '%(asctime)s
|
15 |
-
|
|
|
16 |
|
17 |
handler = logging.StreamHandler()
|
18 |
handler.setFormatter(formatter)
|
|
|
11 |
|
12 |
|
13 |
def create_logger(level=logging.DEBUG):
|
14 |
+
fmt = '[%(asctime)s] %(levelname)s in %(module)s: %(message)s'
|
15 |
+
date_fmt = '%H:%M:%S'
|
16 |
+
formatter = logging.Formatter(fmt, datefmt=date_fmt)
|
17 |
|
18 |
handler = logging.StreamHandler()
|
19 |
handler.setFormatter(formatter)
|
pytube/mixins.py
CHANGED
@@ -8,8 +8,8 @@ Applies in-place data mutations.
|
|
8 |
"""
|
9 |
from __future__ import absolute_import
|
10 |
|
11 |
-
import json
|
12 |
import logging
|
|
|
13 |
|
14 |
from pytube import cipher
|
15 |
from pytube.compat import parse_qsl
|
@@ -46,7 +46,7 @@ def apply_signature(config_args, fmt, js):
|
|
46 |
|
47 |
logger.debug(
|
48 |
'finished descrambling signature for itag=%s\n%s',
|
49 |
-
stream['itag'],
|
50 |
{
|
51 |
's': stream['s'],
|
52 |
'signature': signature,
|
@@ -69,3 +69,4 @@ def apply_descrambler(stream_data, key):
|
|
69 |
{k: unquote(v) for k, v in parse_qsl(i)}
|
70 |
for i in stream_data[key].split(',')
|
71 |
]
|
|
|
|
8 |
"""
|
9 |
from __future__ import absolute_import
|
10 |
|
|
|
11 |
import logging
|
12 |
+
import pprint
|
13 |
|
14 |
from pytube import cipher
|
15 |
from pytube.compat import parse_qsl
|
|
|
46 |
|
47 |
logger.debug(
|
48 |
'finished descrambling signature for itag=%s\n%s',
|
49 |
+
stream['itag'], pprint.pprint(
|
50 |
{
|
51 |
's': stream['s'],
|
52 |
'signature': signature,
|
|
|
69 |
{k: unquote(v) for k, v in parse_qsl(i)}
|
70 |
for i in stream_data[key].split(',')
|
71 |
]
|
72 |
+
logger.debug('applying descrambler\n%s', pprint.pprint(stream_data[key]))
|
pytube/streams.py
CHANGED
@@ -10,9 +10,9 @@ separately).
|
|
10 |
"""
|
11 |
from __future__ import absolute_import
|
12 |
|
13 |
-
import json
|
14 |
import logging
|
15 |
import os
|
|
|
16 |
|
17 |
from pytube import extract
|
18 |
from pytube import request
|
@@ -181,8 +181,8 @@ class Stream(object):
|
|
181 |
"""
|
182 |
file_handler.write(chunk)
|
183 |
logger.debug(
|
184 |
-
'download progress
|
185 |
-
|
186 |
{
|
187 |
'chunk_size': len(chunk),
|
188 |
'bytes_remaining': bytes_remaining,
|
|
|
10 |
"""
|
11 |
from __future__ import absolute_import
|
12 |
|
|
|
13 |
import logging
|
14 |
import os
|
15 |
+
import pprint
|
16 |
|
17 |
from pytube import extract
|
18 |
from pytube import request
|
|
|
181 |
"""
|
182 |
file_handler.write(chunk)
|
183 |
logger.debug(
|
184 |
+
'download progress\n%s',
|
185 |
+
pprint.pprint(
|
186 |
{
|
187 |
'chunk_size': len(chunk),
|
188 |
'bytes_remaining': bytes_remaining,
|