Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
nficano committed Jul 17, 2020
1 parent f1cd745 commit ee0deb6
Show file tree
Hide file tree
Showing 29 changed files with 466 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
runtime_version = "3.x.x"
2 changes: 1 addition & 1 deletion .idea/dictionaries/haroldmartin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 38 additions & 33 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@
import sys

import sphinx_rtd_theme
sys.path.insert(0, os.path.abspath('../'))

sys.path.insert(0, os.path.abspath("../"))

from pytube import __version__ # noqa

# -- General configuration ------------------------------------------------

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.todo',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.todo",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
]

autosummary_generate = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'pytube3'
copyright = '2019, Nick Ficano'
author = 'Nick Ficano, Harold Martin'
project = "pytube3"
copyright = "2019, Nick Ficano"
author = "Nick Ficano, Harold Martin"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -57,16 +58,16 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
"python": ("https://docs.python.org/3/", None),
}


Expand All @@ -75,7 +76,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Theme options are theme-specific and customize the look and feel of a theme
Expand All @@ -87,28 +88,28 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
'donate.html',
"**": [
"about.html",
"navigation.html",
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
"donate.html",
],
}


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'pytube3doc'
htmlhelp_basename = "pytube3doc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -120,8 +121,11 @@
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(
master_doc, 'pytube3.tex', 'pytube3 Documentation',
'Nick Ficano', 'manual',
master_doc,
"pytube3.tex",
"pytube3 Documentation",
"Nick Ficano",
"manual",
),
]

Expand All @@ -131,10 +135,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(
master_doc, 'pytube3', 'pytube3 Documentation',
[author], 1,
),
(master_doc, "pytube3", "pytube3 Documentation", [author], 1,),
]


Expand All @@ -145,8 +146,12 @@
# dir menu entry, description, category)
texinfo_documents = [
(
master_doc, 'pytube3', 'pytube3 Documentation',
author, 'pytube3', 'One line description of project.',
'Miscellaneous',
master_doc,
"pytube3",
"pytube3 Documentation",
author,
"pytube3",
"One line description of project.",
"Miscellaneous",
),
]
64 changes: 47 additions & 17 deletions pytube/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@
smaller peripheral modules and functions.
"""

import json
import logging
from typing import Optional, Dict, List
from urllib.parse import parse_qsl
from html import unescape
from typing import Dict
from typing import List
from typing import Optional
from urllib.parse import parse_qsl

from pytube import Caption
from pytube import CaptionQuery
from pytube import extract
from pytube import request
from pytube import Stream
from pytube import StreamQuery
from pytube.extract import apply_descrambler, apply_signature, get_ytplayer_config
from pytube.helpers import install_proxy
from pytube.exceptions import VideoUnavailable
from pytube.monostate import OnProgress, OnComplete, Monostate
from pytube.extract import apply_descrambler
from pytube.extract import apply_signature
from pytube.extract import get_ytplayer_config
from pytube.helpers import install_proxy
from pytube.monostate import Monostate
from pytube.monostate import OnComplete
from pytube.monostate import OnProgress

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,17 +59,23 @@ def __init__(
"""
self.js: Optional[str] = None # js fetched by js_url
self.js_url: Optional[str] = None # the url to the js, parsed from watch html
self.js_url: Optional[
str
] = None # the url to the js, parsed from watch html

# note: vid_info may eventually be removed. It sounds like it once had
# additional formats, but that doesn't appear to still be the case.

# the url to vid info, parsed from watch html
self.vid_info_url: Optional[str] = None
self.vid_info_raw: Optional[str] = None # content fetched by vid_info_url
self.vid_info_raw: Optional[
str
] = None # content fetched by vid_info_url
self.vid_info: Optional[Dict] = None # parsed content of vid_info_raw

self.watch_html: Optional[str] = None # the html of /watch?v=<video_id>
self.watch_html: Optional[
str
] = None # the html of /watch?v=<video_id>
self.embed_html: Optional[str] = None
self.player_config_args: Dict = {} # inline js in the html containing
self.player_response: Dict = {}
Expand Down Expand Up @@ -109,11 +120,15 @@ def descramble(self) -> None:
self.player_config_args = self.vid_info
else:
assert self.watch_html is not None
self.player_config_args = get_ytplayer_config(self.watch_html)["args"]
self.player_config_args = get_ytplayer_config(self.watch_html)[
"args"
]

# Fix for KeyError: 'title' issue #434
if "title" not in self.player_config_args: # type: ignore
i_start = self.watch_html.lower().index("<title>") + len("<title>")
i_start = self.watch_html.lower().index("<title>") + len(
"<title>"
)
i_end = self.watch_html.lower().index("</title>")
title = self.watch_html[i_start:i_end].strip()
index = title.lower().rfind(" - youtube")
Expand Down Expand Up @@ -143,7 +158,9 @@ def descramble(self) -> None:
self.initialize_stream_objects(fmt)

# load the player_response object (contains subtitle information)
self.player_response = json.loads(self.player_config_args["player_response"])
self.player_response = json.loads(
self.player_config_args["player_response"]
)
del self.player_config_args["player_response"]
self.stream_monostate.title = self.title
self.stream_monostate.duration = self.length
Expand All @@ -164,7 +181,10 @@ def prefetch(self) -> None:
raise VideoUnavailable(video_id=self.video_id)
self.age_restricted = extract.is_age_restricted(self.watch_html)

if not self.age_restricted and "This video is private" in self.watch_html:
if (
not self.age_restricted
and "This video is private" in self.watch_html
):
raise VideoUnavailable(video_id=self.video_id)

if self.age_restricted:
Expand Down Expand Up @@ -282,7 +302,9 @@ def rating(self) -> float:
:rtype: float
"""
return self.player_response.get("videoDetails", {}).get("averageRating")
return self.player_response.get("videoDetails", {}).get(
"averageRating"
)

@property
def length(self) -> int:
Expand All @@ -293,7 +315,11 @@ def length(self) -> int:
"""
return int(
self.player_config_args.get("length_seconds")
or (self.player_response.get("videoDetails", {}).get("lengthSeconds"))
or (
self.player_response.get("videoDetails", {}).get(
"lengthSeconds"
)
)
)

@property
Expand All @@ -303,14 +329,18 @@ def views(self) -> int:
:rtype: str
"""
return int(self.player_response.get("videoDetails", {}).get("viewCount"))
return int(
self.player_response.get("videoDetails", {}).get("viewCount")
)

@property
def author(self) -> str:
"""Get the video author.
:rtype: str
"""
return self.player_response.get("videoDetails", {}).get("author", "unknown")
return self.player_response.get("videoDetails", {}).get(
"author", "unknown"
)

def register_on_progress_callback(self, func: OnProgress):
"""Register a download progress callback function post initialization.
Expand Down
9 changes: 6 additions & 3 deletions pytube/captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import os
import time
import xml.etree.ElementTree as ElementTree
from typing import Dict, Optional
from pytube import request
from html import unescape
from pytube.helpers import safe_filename, target_directory
from typing import Dict
from typing import Optional

from pytube import request
from pytube.helpers import safe_filename
from pytube.helpers import target_directory


class Caption:
Expand Down
Loading

0 comments on commit ee0deb6

Please sign in to comment.