Skip to content

Commit

Permalink
feat, fix: typer issue, streaming in lower quality
Browse files Browse the repository at this point in the history
  • Loading branch information
r3tr0ananas committed Apr 5, 2024
1 parent 8c6ab4a commit 5f7cb58
Show file tree
Hide file tree
Showing 9 changed files with 34 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 @@ -4,4 +4,4 @@
from .scraper import *
from .download import *

__version__ = "4.2.10"
__version__ = "4.2.11"
3 changes: 1 addition & 2 deletions mov_cli/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,4 @@ def mov_cli(
)

def app():
uwu_app.command()(mov_cli)
uwu_app() # Wait whaaaaa.
typer.run(mov_cli)
13 changes: 9 additions & 4 deletions mov_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from . import players, utils
from .logger import mov_cli_logger

__all__ = ("Config",)
__all__ = ("Config", )

@final
class ConfigUIData(TypedDict):
Expand Down Expand Up @@ -46,6 +46,7 @@ class ConfigData(TypedDict):
downloads: ConfigDownloadsData
scrapers: ScrapersData
plugins: Dict[str, str]


logger = LoggerAdapter(mov_cli_logger, prefix = "Config")

Expand Down Expand Up @@ -82,9 +83,9 @@ def player(self) -> Player:
platform = utils.what_platform()

if value.lower() == "mpv":
return players.MPV(platform)
return players.MPV(platform, self)
elif value.lower() == "vlc":
return players.VLC(platform)
return players.VLC(platform, self)

return players.CustomPlayer(value)

Expand Down Expand Up @@ -157,6 +158,10 @@ def http_headers(self) -> dict:
}

return self.data.get("http", {}).get("headers", default_headers)

@property
def resolution(self) -> int:
return self.data.get("quality", {}).get("resolution", {})

def __get_config_file(self) -> Path:
"""Function that returns the path to the config file with multi platform support."""
Expand Down Expand Up @@ -199,4 +204,4 @@ def __get_config_file(self) -> Path:
config_file.close()
logger.info(f"Config created at '{config_path}'.")

return config_path
return config_path
3 changes: 3 additions & 0 deletions mov_cli/config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ test = "mov-cli-test"

# [mov-cli.downloads] # Do not use backslashes use forward slashes
# save_path = "~/Downloads"

# [mov-cli.quality]
# resolution = 720
6 changes: 2 additions & 4 deletions mov_cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .config import Config
from .media import Series, Movie

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

Expand All @@ -19,11 +19,9 @@ def download(self, media: Series | Movie, subtitles: str = None) -> subprocess.P

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

args = [
args = [ # TODO: Check if url is a m3u8 if not use aria2
"ffmpeg",
"-n",
"-thread_queue_size",
"4096",
"-headers",
f"Referer: {media.referrer}",
"-i",
Expand Down
10 changes: 9 additions & 1 deletion mov_cli/players/mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
if TYPE_CHECKING:
from typing import Optional
from ..media import Media
from .. import Config
from ..utils.platform import SUPPORTED_PLATFORMS

import subprocess
Expand All @@ -18,8 +19,9 @@
logger = LoggerAdapter(mov_cli_logger, prefix = Colours.PURPLE.apply("MPV"))

class MPV(Player):
def __init__(self, platform: SUPPORTED_PLATFORMS, **kwargs) -> None:
def __init__(self, platform: SUPPORTED_PLATFORMS, config: Config, **kwargs) -> None:
self.platform = platform
self.config = config

super().__init__(**kwargs)

Expand Down Expand Up @@ -54,6 +56,9 @@ def play(self, media: Media) -> Optional[subprocess.Popen]:
if media.referrer is not None:
args.append(f"--referrer={media.referrer}")

if self.config.resolution:
args.append(f"--hls-bitrate={self.config.resolution}") # NOTE: This only works when the file is a m3u8

return subprocess.Popen(args)

elif self.platform == "Darwin":
Expand All @@ -68,6 +73,9 @@ def play(self, media: Media) -> Optional[subprocess.Popen]:
if media.referrer is not None:
args.append(f"--mpv-referrer={media.referrer}")

if self.config.resolution:
args.append(f"--mpv-hls-bitrate={self.config.resolution}") # NOTE: This only works when the file is a m3u8

return subprocess.Popen(args)

except ModuleNotFoundError:
Expand Down
7 changes: 6 additions & 1 deletion mov_cli/players/vlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional

from ..media import Media
from .. import Config
from ..utils.platform import SUPPORTED_PLATFORMS

import subprocess
Expand All @@ -19,8 +20,9 @@
logger = LoggerAdapter(mov_cli_logger, prefix = Colours.ORANGE.apply("VLC"))

class VLC(Player):
def __init__(self, platform: SUPPORTED_PLATFORMS, **kwargs) -> None:
def __init__(self, platform: SUPPORTED_PLATFORMS, config: Config, **kwargs) -> None:
self.platform = platform
self.config = config

super().__init__(**kwargs)

Expand Down Expand Up @@ -64,6 +66,9 @@ def play(self, media: Media) -> Optional[subprocess.Popen]:
if media.referrer is not None:
args.append(f'--http-referrer="{media.referrer}"')

if self.config.resolution:
args.append(f"--adaptive-maxwidth={self.config.resolution}") # NOTE: I don't really know if that works ~ Ananas

return subprocess.Popen(args)

except ModuleNotFoundError:
Expand Down
19 changes: 2 additions & 17 deletions mov_cli/utils/scraper/the_movie_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from ...media import Metadata, MetadataType, ExtraMetadata, AiringType
from base64 import b64decode
from thefuzz import fuzz

__all__ = ("TheMovieDB",)

Expand Down Expand Up @@ -62,12 +61,7 @@ def search(self, query: str, limit: int = 10) -> Generator[Metadata, Any, None]:

serial_list.append(item)

sorted_list: List[TMDbSerial] = self.__sort(serial_list, query)[:limit]
# Is there are point in fuzzy sorting? The search api (tmdb) should do that for us and fzf exists for that reason. ~ Goldy

# Also yield won't actually do anything performance wise if we've already appended the items into a list.
# Actually in this case we can't really take advantage of yield as the api returns all results at once. ~ Goldy
for item in sorted_list:
for item in serial_list:
yield Metadata(
id = item.id,
title = item.title,
Expand Down Expand Up @@ -139,13 +133,4 @@ def __extra_metadata(self, serial: TMDbSerial) -> ExtraMetadata: # This API is d
alternate_titles = alternate_titles,
genres = genres,
airing = airing
)

def __sort_key(self, query):
def similarity_score(item: TMDbSerial):
return fuzz.ratio(item.title, query)
return similarity_score

def __sort(self, unsorted, query):
sorted_list = sorted(unsorted, key=self.__sort_key(query), reverse=True)
return sorted_list
)
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ dependencies = [
"importlib-metadata; python_version<'3.8'",
"toml",
"devgoldyutils>=2.5.7",
"typer[all]==0.10.0",
"typer[all]>=0.10.0",
"inquirer",
"beautifulsoup4",
"Unidecode",
"thefuzz",
"deprecation",
"packaging",

Expand Down

0 comments on commit 5f7cb58

Please sign in to comment.