Skip to content

Commit

Permalink
feat, fix: add -d for download, Library is now being created, iOS and…
Browse files Browse the repository at this point in the history
… MacOS use there respective editors
  • Loading branch information
r3tr0ananas committed Mar 16, 2024
1 parent 94c46da commit 519b6b4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion mov_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .scraper import *
from .download import *

__version__ = "4.0.4"
__version__ = "4.0.5"
15 changes: 12 additions & 3 deletions mov_cli/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ..media import MetadataType
from ..logger import mov_cli_logger
from ..http_client import HTTPClient
from ..download import Download

__all__ = ("mov_cli",)

Expand All @@ -28,7 +29,8 @@ def mov_cli(
episode: Optional[str] = typer.Option(None, "--episode", "-ep", help = "Episode and season you wanna scrape. E.g {episode}:{season} like -> 26:3"),

version: bool = typer.Option(False, "--version", help = "Display what version mov-cli is currently on."),
edit: bool = typer.Option(False, "--edit", "-e", help = "Opens the mov-cli config with your respective editor."),
edit: bool = typer.Option(False, "--edit", "-e", help = "Opens the mov-cli config with your respective editor."),
download: bool = typer.Option(False, "--download", "-d", help = "Downloads the media instead of playing"),
):
config = Config()

Expand Down Expand Up @@ -98,8 +100,15 @@ def mov_cli(
mov_cli_logger.info(f"Scrapping media for '{Colours.CLAY.apply(choice.title)}'...")
media = scraper.scrape(choice, episode)

popen = config.player.play(media)
mov_cli_logger.debug(f"Streaming with this url -> '{media.url}'")
if not download:
popen = config.player.play(media)
mov_cli_logger.debug(f"Streaming with this url -> '{media.url}'")

else:
dl = Download(config)
mov_cli_logger.debug(f"Downloading with this url -> '{media.url}'")

popen = dl.download(media)

popen.wait()

Expand Down
6 changes: 3 additions & 3 deletions mov_cli/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ def open_config_file(config: Config):

if platform == "Windows":
editor = "notepad"
elif platform == "Darwin": # TODO: Implement MacOS and iOS.
...
elif platform == "Darwin":
editor = "nano" # NOTE: https://support.apple.com/guide/terminal/use-command-line-text-editors-apdb02f1133-25af-4c65-8976-159609f99817/mac
elif platform == "iOS":
...
editor = "vi"
elif platform == "Linux" or platform == "Android":
editor = "nano"

Expand Down
7 changes: 3 additions & 4 deletions mov_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ def parser(self) -> SUPPORTED_PARSERS | Any:
@property
def download_location(self) -> str:
"""Returns download location. Defaults to OS's download location."""
# TODO: Replace with custom paths class.
# default_location = platformdirs.user_downloads_dir()
default_location = None # TODO: Remove this when default_location equals the path from the paths class.
return self.data.get("downloads", {}).get("save_path", default_location)
return self.data.get("downloads", {}).get("save_path", os.getcwd())

@property
def debug(self) -> bool:
Expand Down Expand Up @@ -176,6 +173,8 @@ def __get_config_file(self) -> Path:
user_profile = Path(os.getenv("HOME"))
appdata_dir = user_profile.joinpath("Library")

appdata_dir.mkdir(exist_ok = True)

elif platform == "Linux" or platform == "Android":
user_profile = Path(os.getenv("HOME"))
appdata_dir = user_profile.joinpath(".config")
Expand Down
2 changes: 1 addition & 1 deletion mov_cli/config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ test = "mov-cli-test"
# [mov-cli.http] # Don't mess with it if you don't know what you are doing!
# headers = { User-Agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0" }

# [mov-cli.downloads]
# [mov-cli.downloads] # Do not use backslashes use forward slashes
# save_path = "~/Downloads"
25 changes: 8 additions & 17 deletions mov_cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
from typing import TYPE_CHECKING
import subprocess
import unicodedata
import os

__all__ = ("Download",)

if TYPE_CHECKING:
from .config import Config
from .media import LiveTV, Series, Movie
from .media import Series, Movie

class Download():
def __init__(self, config: Config) -> None:
self.config = config

def download(self, media: LiveTV | Series | Movie, subtitles: str = None):
title = unicodedata.normalize('NFKD', media.title).encode('ascii', 'ignore').decode('ascii')
episode = media.episode
season = media.season
def download(self, media: Series | Movie, subtitles: str = None) -> subprocess.Popen:
title = unicodedata.normalize('NFKD', media.title).encode('ascii', 'ignore').decode('ascii') # normalize title

if season is not None:
title += f" S{season}"
if hasattr(media, "episode"):
title += f" S{media.episode.season}E{media.episode.episode}"

if episode is not None:
title += f" E{episode}"

file = self.config.download_location + title + ".mp4"
file = os.path.join(self.config.download_location, title + ".mp4")

args = [
"ffmpeg",
Expand All @@ -44,9 +40,4 @@ def download(self, media: LiveTV | Series | Movie, subtitles: str = None):

args.append(file)

try:
ffmpeg = subprocess.Popen(args)
ffmpeg.wait()
return True
except Exception:
return False
return subprocess.Popen(args)
2 changes: 0 additions & 2 deletions mov_cli/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ def get(

raise e

# NOTE: Are we even using post requests, like will they be used in the future? ~ Goldy
# NOTE: We likely need it at some point, when adding new providers ~ Ananas
def post(self, url: str, data: dict = None, json: dict = None, **kwargs) -> Response:
"""Performs a POST request and returns httpx.Response."""
self.logger.debug(Colours.ORANGE.apply("POST") + f": {url}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classifiers = [
'Operating System :: Microsoft :: Windows :: Windows 11',
'Operating System :: Microsoft :: Windows :: Windows 10',
'Operating System :: POSIX :: Linux',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
Expand Down

0 comments on commit 519b6b4

Please sign in to comment.