fixes for logging setup
Browse files- pytube/__init__.py +0 -4
- pytube/cipher.py +3 -3
- pytube/cli.py +5 -5
- pytube/extract.py +4 -1
- pytube/helpers.py +1 -2
pytube/__init__.py
CHANGED
@@ -10,13 +10,9 @@ __license__ = "MIT License"
|
|
10 |
__copyright__ = "Copyright 2019 Nick Ficano"
|
11 |
|
12 |
from pytube.version import __version__
|
13 |
-
from pytube.helpers import create_logger
|
14 |
from pytube.streams import Stream
|
15 |
from pytube.captions import Caption
|
16 |
from pytube.query import CaptionQuery
|
17 |
from pytube.query import StreamQuery
|
18 |
from pytube.__main__ import YouTube
|
19 |
from pytube.contrib.playlist import Playlist
|
20 |
-
|
21 |
-
logger = create_logger()
|
22 |
-
logger.info("%s v%s", __title__, __version__)
|
|
|
10 |
__copyright__ = "Copyright 2019 Nick Ficano"
|
11 |
|
12 |
from pytube.version import __version__
|
|
|
13 |
from pytube.streams import Stream
|
14 |
from pytube.captions import Caption
|
15 |
from pytube.query import CaptionQuery
|
16 |
from pytube.query import StreamQuery
|
17 |
from pytube.__main__ import YouTube
|
18 |
from pytube.contrib.playlist import Playlist
|
|
|
|
|
|
pytube/cipher.py
CHANGED
@@ -14,15 +14,15 @@ functions" (2) maps them to Python equivalents and (3) taking the ciphered
|
|
14 |
signature and decoding it.
|
15 |
|
16 |
"""
|
17 |
-
|
18 |
import re
|
19 |
from itertools import chain
|
20 |
from typing import List, Tuple, Dict, Callable, Any, Optional
|
21 |
|
22 |
from pytube.exceptions import RegexMatchError
|
23 |
-
from pytube.helpers import regex_search,
|
24 |
|
25 |
-
logger =
|
26 |
|
27 |
|
28 |
class Cipher:
|
|
|
14 |
signature and decoding it.
|
15 |
|
16 |
"""
|
17 |
+
import logging
|
18 |
import re
|
19 |
from itertools import chain
|
20 |
from typing import List, Tuple, Dict, Callable, Any, Optional
|
21 |
|
22 |
from pytube.exceptions import RegexMatchError
|
23 |
+
from pytube.helpers import regex_search, cache
|
24 |
|
25 |
+
logger = logging.getLogger(__name__)
|
26 |
|
27 |
|
28 |
class Cipher:
|
pytube/cli.py
CHANGED
@@ -17,9 +17,7 @@ from typing import Any, Optional, List
|
|
17 |
from pytube import __version__, CaptionQuery, Stream, Playlist
|
18 |
from pytube import YouTube
|
19 |
from pytube.exceptions import PytubeError
|
20 |
-
from pytube.helpers import safe_filename
|
21 |
-
|
22 |
-
logger = logging.getLogger(__name__)
|
23 |
|
24 |
|
25 |
def main():
|
@@ -27,7 +25,9 @@ def main():
|
|
27 |
# noinspection PyTypeChecker
|
28 |
parser = argparse.ArgumentParser(description=main.__doc__)
|
29 |
args = _parse_args(parser)
|
30 |
-
|
|
|
|
|
31 |
|
32 |
if not args.url or "youtu" not in args.url:
|
33 |
parser.print_help()
|
@@ -99,7 +99,7 @@ def _parse_args(
|
|
99 |
action="count",
|
100 |
default=0,
|
101 |
dest="verbosity",
|
102 |
-
help="Verbosity level",
|
103 |
)
|
104 |
parser.add_argument(
|
105 |
"--build-playback-report",
|
|
|
17 |
from pytube import __version__, CaptionQuery, Stream, Playlist
|
18 |
from pytube import YouTube
|
19 |
from pytube.exceptions import PytubeError
|
20 |
+
from pytube.helpers import safe_filename, setup_logger
|
|
|
|
|
21 |
|
22 |
|
23 |
def main():
|
|
|
25 |
# noinspection PyTypeChecker
|
26 |
parser = argparse.ArgumentParser(description=main.__doc__)
|
27 |
args = _parse_args(parser)
|
28 |
+
if args.verbosity:
|
29 |
+
log_level = min(args.verbosity, 4) * 10
|
30 |
+
setup_logger(logging.FATAL - log_level)
|
31 |
|
32 |
if not args.url or "youtu" not in args.url:
|
33 |
parser.print_help()
|
|
|
99 |
action="count",
|
100 |
default=0,
|
101 |
dest="verbosity",
|
102 |
+
help="Verbosity level, use up to 4 to increase logging -vvvv",
|
103 |
)
|
104 |
parser.add_argument(
|
105 |
"--build-playback-report",
|
pytube/extract.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
# -*- coding: utf-8 -*-
|
2 |
"""This module contains all non-cipher related data extraction logic."""
|
3 |
import json
|
|
|
4 |
import re
|
5 |
from collections import OrderedDict
|
6 |
from html.parser import HTMLParser
|
@@ -10,7 +11,9 @@ from urllib.parse import urlencode
|
|
10 |
|
11 |
from pytube.cipher import Cipher
|
12 |
from pytube.exceptions import RegexMatchError, HTMLParseError, LiveStreamError
|
13 |
-
from pytube.helpers import regex_search
|
|
|
|
|
14 |
|
15 |
|
16 |
class PytubeHTMLParser(HTMLParser):
|
|
|
1 |
# -*- coding: utf-8 -*-
|
2 |
"""This module contains all non-cipher related data extraction logic."""
|
3 |
import json
|
4 |
+
import logging
|
5 |
import re
|
6 |
from collections import OrderedDict
|
7 |
from html.parser import HTMLParser
|
|
|
11 |
|
12 |
from pytube.cipher import Cipher
|
13 |
from pytube.exceptions import RegexMatchError, HTMLParseError, LiveStreamError
|
14 |
+
from pytube.helpers import regex_search
|
15 |
+
|
16 |
+
logger = logging.getLogger(__name__)
|
17 |
|
18 |
|
19 |
class PytubeHTMLParser(HTMLParser):
|
pytube/helpers.py
CHANGED
@@ -86,7 +86,7 @@ def safe_filename(s: str, max_length: int = 255) -> str:
|
|
86 |
return filename[:max_length].rsplit(" ", 0)[0]
|
87 |
|
88 |
|
89 |
-
def
|
90 |
"""Create a configured instance of logger.
|
91 |
|
92 |
:param int level:
|
@@ -103,7 +103,6 @@ def create_logger(level: int = logging.ERROR) -> logging.Logger:
|
|
103 |
logger = logging.getLogger("pytube")
|
104 |
logger.addHandler(handler)
|
105 |
logger.setLevel(level)
|
106 |
-
return logger
|
107 |
|
108 |
|
109 |
GenericType = TypeVar("GenericType")
|
|
|
86 |
return filename[:max_length].rsplit(" ", 0)[0]
|
87 |
|
88 |
|
89 |
+
def setup_logger(level: int = logging.ERROR):
|
90 |
"""Create a configured instance of logger.
|
91 |
|
92 |
:param int level:
|
|
|
103 |
logger = logging.getLogger("pytube")
|
104 |
logger.addHandler(handler)
|
105 |
logger.setLevel(level)
|
|
|
106 |
|
107 |
|
108 |
GenericType = TypeVar("GenericType")
|