Skip to content

Commit

Permalink
Merge pull request #32 from SheepYY039/download_m3u8
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
jyyyeung authored Jul 24, 2023
2 parents 7eb44ec + 386ba19 commit b0f0158
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 87 deletions.
Binary file not shown.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## v1.1.0 (2023-07-24)

### Feat

- set source simplified or traditional search_query for automatic translation
- create general series directory if not exist in base
- **config**: created basic config setup

### Refactor

- Cleanup code

## v1.0.1 (2023-07-12)

### Refactor
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespaces = false # to disable scanning PEP 420 namespaces (true by default)
[tool.commitizen]
name = "cz_conventional_commits"
version_scheme = "pep440"
version = "1.0.1"
version = "1.1.0"
tag_format = "v$version"
version_files = [
"VERSION",
Expand Down
61 changes: 50 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,56 +1,95 @@
appdirs==1.4.4
argcomplete==3.1.1
bandit==1.7.5
beautifulsoup4==4.12.2
black==23.7.0
bs4==0.0.1
build==0.10.0
certifi==2023.5.7
cffi==1.15.1
cfgv==3.3.1
charset-normalizer==3.2.0
chinese-converter==1.0.2
click==8.1.4
cloudscraper==1.2.71
colorama==0.4.6
commitizen==3.5.0
cryptography==41.0.2
cssselect==1.2.0
decli==0.6.1
distlib==0.3.6
fake-useragent==1.1.3
filelock==3.12.2
ghp-import==2.1.0
gitdb==4.0.10
GitPython==3.1.31
griffe==0.31.0
identify==2.5.24
idna==3.4
importlib-metadata==6.8.0
iso8601==2.0.0
Jinja2==3.1.2
lxml==4.9.3
m3u8==3.5.0
m3u8-To-MP4==0.1.11
Markdown==3.3.7
markdown-it-py==3.0.0
MarkupSafe==2.1.3
mdurl==0.1.2
mergedeep==1.3.4
mkdocs==1.4.3
mkdocs-autorefs==0.4.1
mkdocs-material==9.1.18
mkdocs-material-extensions==1.1.1
mkdocstrings==0.22.0
mkdocstrings-python==1.1.2
multipledispatch==1.0.0
mypy-extensions==1.0.0
ndg-httpsclient==0.5.1
nodeenv==1.8.0
overloading==0.5.0
packaging==23.1
parse==1.19.1
pathspec==0.11.1
pbr==5.11.1
pip-tools==6.14.0
platformdirs==3.8.1
pre-commit==3.3.3
prompt-toolkit==3.0.39
pyasn1==0.5.0
pycparser==2.21
pycryptodome==3.18.0
pyee==8.2.2
Pygments==2.15.1
pymdown-extensions==10.0.1
pyOpenSSL==23.2.0
pyparsing==3.1.0
pyppeteer==1.0.2
pyproject_hooks==1.0.0
pyquery==2.0.0
python-dateutil==2.8.2
python-dotenv==1.0.0
PyYAML==6.0
pyyaml_env_tag==0.1
questionary==1.10.0
regex==2023.6.3
requests==2.31.0
requests-html==0.10.0
requests-toolbelt==1.0.0
rich==13.4.2
six==1.16.0
smmap==5.0.0
soupsieve==2.4.1
stevedore==5.1.0
termcolor==2.3.0
tomlkit==0.11.8
tqdm==4.65.0
typer==0.9.0
typing_extensions==4.7.1
urllib3==1.26.16
virtualenv==20.23.1
w3lib==2.1.1
websockets~=10.0
watchdog==3.0.0
wcwidth==0.2.6
websockets==10.4
zipp==3.16.0

mkdocstrings==0.22.0
mkdocs==1.4.3
mkdocs-material==9.1.18
mkdocstrings[python]~=0.22.0

black==23.7.0
commitizen==3.5.0
pip-tools==6.14.0
pre-commit==3.3.3
8 changes: 8 additions & 0 deletions tvsd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
__app_name__ = "tvsd"
__version__ = "1.0.0-a.1"

import os
from typer import Typer


app = Typer(name=__app_name__, rich_markup_mode="rich")
state = {"verbose": False}
current_dir = os.getcwd()


(
SUCCESS,
Expand Down
11 changes: 6 additions & 5 deletions tvsd/actions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
import logging
import sys
from tvsd.config import BASE_PATH, TEMP_BASE_PATH

from tvsd.download import Download
from tvsd.search import SearchQuery
from tvsd.utils import check_dir_mounted, LOGGER
from tvsd.utils import check_dir_mounted


def search_media_and_download(query: str):
Expand All @@ -13,14 +14,14 @@ def search_media_and_download(query: str):
Args:
query (str): query string
"""
LOGGER.info(f"Checking if {BASE_PATH} is mounted...")
logging.info(f"Checking if {BASE_PATH} is mounted...")
if not check_dir_mounted(path=BASE_PATH):
sys.exit()
LOGGER.debug("Base path: %s", BASE_PATH)
logging.debug("Base path: %s", BASE_PATH)

# Search
query_instance = SearchQuery(query)
LOGGER.info(f"Searching for {query}...")
logging.info(f"Searching for {query}...")
query_instance.find_show(BASE_PATH)

# Download
Expand All @@ -29,5 +30,5 @@ def search_media_and_download(query: str):
base_path=BASE_PATH,
temp_path=TEMP_BASE_PATH,
)
LOGGER.info(f"Starting {query_instance.chosen_show.title} guided download...")
logging.info(f"Starting {query_instance.chosen_show.title} guided download...")
download_instance.guided_download()
37 changes: 22 additions & 15 deletions tvsd/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
from pathlib import Path
import shutil
Expand All @@ -6,20 +7,11 @@
import typer
from rich import print

from tvsd import ERRORS, __app_name__, __version__, database
from tvsd import ERRORS, __app_name__, __version__, database, app, state
from tvsd.actions import search_media_and_download
from tvsd.config import init_app, TEMP_BASE_PATH, validate_config_file


app = typer.Typer()


def _version_callback(value: bool) -> None:
if value:
typer.echo(f"{__app_name__} v{__version__}")
raise typer.Exit()


@app.command()
def init(
db_path: str = typer.Option(
Expand Down Expand Up @@ -48,18 +40,33 @@ def init(
typer.secho(f"The TVSD database is {db_path}", fg=typer.colors.GREEN)


def _version_callback(value: bool) -> None:
if value:
typer.echo(f"{__app_name__} v{__version__}")
raise typer.Exit()


@app.callback()
def main(
version: Optional[bool] = typer.Option(
_: Optional[bool] = typer.Option(
None,
"--version",
"-v",
help="Show the application's version and exit.",
callback=_version_callback,
is_eager=True,
)
),
verbose: Optional[bool] = False,
) -> None:
return
"""
Options to update state of the application.
"""
if verbose:
print("Will write verbose output")
state["verbose"] = True
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)


@app.command()
Expand Down Expand Up @@ -93,6 +100,6 @@ def clean_temp():
if confirm.capitalize() == "Y":
shutil.rmtree(TEMP_BASE_PATH, ignore_errors=True)
os.mkdir(TEMP_BASE_PATH)
print("All files deleted")
logging.info("All files deleted")
except FileNotFoundError:
print(f"Temp directory {TEMP_BASE_PATH} does not exist")
logging.info(f"Temp directory {TEMP_BASE_PATH} does not exist")
3 changes: 2 additions & 1 deletion tvsd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

class Config:
def __init__(self):
print(CONFIG_FILE_PATH)
config_parser.read(CONFIG_FILE_PATH)

@classmethod
Expand Down Expand Up @@ -50,7 +51,7 @@ def validate_config_file(self) -> None:
if not config_parser.has_section("General"):
config_parser["General"] = {
"base_path": "/Volumes/Viewable",
"temp_base_path": "~/Movies/temp-parts",
"temp_base_path": f"{os.path.expanduser('~')}/Movies/temp-parts",
"series_dir": "TV Series",
"specials_dir": "Specials",
}
Expand Down
9 changes: 5 additions & 4 deletions tvsd/download.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import shutil
from typing import Literal
Expand All @@ -11,7 +12,7 @@
from tvsd.show import Show
from tvsd.season import Season
from tvsd.episode import Episode
from tvsd.utils import LOGGER, mkdir_if_no
from tvsd.utils import mkdir_if_no


class Download:
Expand Down Expand Up @@ -68,14 +69,14 @@ def choose_download(self, season: "Season"):
@dispatch(Show)
def download_all(self, show: Show):
"""Download all episodes in a show"""
LOGGER.debug("Downloading all episodes in show")
logging.debug("Downloading all episodes in show")
for season in show.seasons:
self.download_all(season)

@dispatch(Season)
def download_all(self, season: Literal["Season"]):
"""Download all episodes in a season"""
LOGGER.info("Downloading all episodes in season")
logging.info("Downloading all episodes in season")

# reset episode index
self._specials_index = 1
Expand Down Expand Up @@ -132,7 +133,7 @@ def download_episode(self, episode: "Episode"):
absolute_dest_dir = os.path.join(
self._base_path, episode.relative_destination_dir
)
LOGGER.info(absolute_dest_dir)
logging.info(absolute_dest_dir)
mkdir_if_no(absolute_dest_dir)

if episode.file_exists_locally:
Expand Down
8 changes: 4 additions & 4 deletions tvsd/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from difflib import SequenceMatcher
import inspect
import logging
import os
import sys
from typing import TYPE_CHECKING, Any, Literal, Union, List
Expand All @@ -14,7 +15,6 @@
from tvsd import sources
from tvsd.source import Source

from tvsd.utils import LOGGER

if TYPE_CHECKING:
from tvsd.season import Season
Expand Down Expand Up @@ -85,10 +85,10 @@ def find_shows_online(self):
query_results: List[Literal["Season"]] = []
# TODO: Search in db first / or put db results first

LOGGER.debug("Searching for %s", self._query)
logging.debug("Searching for %s", self._query)

for file in dir(sources):
LOGGER.debug(f"Found {file}...")
logging.debug(f"Found {file}...")
if not file.startswith("__"):
for cls_name, cls_obj in inspect.getmembers(
sys.modules[f"tvsd.sources.{file}"]
Expand All @@ -100,7 +100,7 @@ def find_shows_online(self):
and issubclass(cls_obj, Source)
and cls_obj().__status__ == "active"
):
LOGGER.info(f"Searching {cls_name}...")
logging.info(f"Searching {cls_name}...")
query_results += cls_obj().query_from_source(self._query)

table = Table("index", "Title", "Source", "Note")
Expand Down
7 changes: 4 additions & 3 deletions tvsd/season.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
from typing import List, Callable, TYPE_CHECKING, Union
from bs4 import Tag
Expand All @@ -8,7 +9,6 @@

from tvsd.show import Show
from tvsd.episode import Episode
from tvsd.utils import LOGGER


if TYPE_CHECKING:
Expand Down Expand Up @@ -152,7 +152,7 @@ def season_index(self) -> int:
if self._index is None:
self.determine_season_index(self._title)

return self._index
return self._index or 1

@property
def relative_season_dir(self) -> str:
Expand Down Expand Up @@ -182,6 +182,7 @@ def determine_show_begin_year(self) -> str:
Returns:
int: Begin year of the show
"""
print(self.year)
season_year = int(self.year)
show_year = season_year

Expand All @@ -203,7 +204,7 @@ def year(self) -> str:
Returns:
str: year of the season
"""
LOGGER.info(self)
logging.info(self)
return self._year

@property
Expand Down
Loading

0 comments on commit b0f0158

Please sign in to comment.