Skip to content

Commit

Permalink
Merge branch 'feat/custom-scraper-arguments' into v4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
THEGOLDENPRO committed Mar 23, 2024
2 parents 75bd77b + 1186d51 commit 2e56222
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion mov_cli/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def mov_cli(
return None

if len(query) > 0:
scrape_arguments = utils.steal_scraper_args(query)
# This allows passing arguments to scrapers like this:
# https://github.com/mov-cli/mov-cli-youtube/commit/b538d82745a743cd74a02530d6a3d476cd60b808#diff-4e5b064838aa74a5375265f4dfbd94024b655ee24a191290aacd3673abed921a

query: str = " ".join(query)

http_client = HTTPClient(config)

chosen_scraper = select_scraper(config.plugins, config.fzf_enabled, config.default_scraper)
Expand Down Expand Up @@ -115,7 +120,7 @@ def mov_cli(
return False

mov_cli_logger.info(f"Scrapping media for '{Colours.CLAY.apply(choice.title)}'...")
media = scraper.scrape(choice, episode)
media = scraper.scrape(choice, episode, **scrape_arguments)

if download:
dl = Download(config)
Expand Down
17 changes: 15 additions & 2 deletions mov_cli/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Literal, Tuple
from typing import Literal, Tuple, List, Dict

import random
import getpass
Expand All @@ -16,6 +16,7 @@
__all__ = (
"greetings",
"welcome_msg",
"steal_scraper_args"
)

def greetings() -> Tuple[Literal["Good Morning", "Good Afternoon", "Good Evening", "Good Night"], str]:
Expand Down Expand Up @@ -77,4 +78,16 @@ def welcome_msg(display_hint: bool = False, display_version: bool = False) -> st
if update_available():
text += f"\n\n {Colours.PURPLE}{Colours.ORANGE}An update is available! --> {Colours.RESET}pip install mov-cli -U"

return text + "\n"
return text + "\n"

def steal_scraper_args(query: List[str]) -> Dict[str, bool]:
scrape_arguments = [x for x in query if "--" in x]

mov_cli_logger.debug(f"Scraper args picked up on --> {scrape_arguments}")

for scrape_arg in scrape_arguments:
query.remove(scrape_arg)

return dict(
[(x.replace("--", ""), True) for x in scrape_arguments]
)

0 comments on commit 2e56222

Please sign in to comment.