Skip to content

Commit

Permalink
Add --cookies option for authenticating requests (#114)
Browse files Browse the repository at this point in the history
* Add `--cookies` option for authenticating requests

* Allow character "=" in command line option values
  • Loading branch information
pedromsilvapt committed Apr 19, 2023
1 parent 9ddd0ec commit 560598d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 10 additions & 1 deletion yark/archiver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Config:
comments: bool = False
format: Optional[str] = None
proxy: Optional[str] = None
cookies: Optional[str] = None
bind_host: Optional[str] = None
bind_port: int = 7667
headless: bool = False
Expand Down Expand Up @@ -99,6 +100,10 @@ def settings_dl(self, path: Path) -> YtDlpSettings:
if self.proxy is not None:
settings["proxy"] = self.proxy

# Cookies file to allow, for example, archiving private playlists
if self.cookies is not None:
settings["cookiefile"] = self.cookies

# Return
return settings

Expand All @@ -118,6 +123,10 @@ def settings_md(self) -> YtDlpSettings:
if self.proxy is not None:
settings["proxy"] = self.proxy

# Cookies file to allow, for example, archiving private playlists
if self.cookies is not None:
settings["cookiefile"] = self.cookies

# Return
return settings

Expand All @@ -140,4 +149,4 @@ def open_webbrowser(self, archive_name: Optional[str]):
"""Opens the webbrowser to optional archive_name or to the main page if not specified"""
url = self.browser_url(archive_name)

webbrowser.open(url)
webbrowser.open(url)
13 changes: 8 additions & 5 deletions yark/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _cli() -> None:
if len(args) > 2:

def parse_value(config_arg: str) -> str:
return config_arg.split("=")[1]
return config_arg.split("=", 1)[1]

def parse_maximum_int(config_arg: str) -> int:
"""Tries to parse a maximum integer input"""
Expand Down Expand Up @@ -146,6 +146,9 @@ def parse_maximum_int(config_arg: str) -> int:
elif config_arg.startswith("--proxy="):
config.proxy = parse_value(config_arg)

elif config_arg.startswith("--cookies="):
config.cookies = parse_value(config_arg)

# Unknown argument
else:
print(HELP, file=sys.stderr)
Expand Down Expand Up @@ -215,9 +218,9 @@ def launch(config: Config, archive_name: Optional[str]) -> None:
msg = f"Starting archive at {url} address"
if archive_name is not None:
msg += f" for {archive_name} archive"

print(msg)

app = viewer()
threading.Thread(target=lambda: app.run(port=config.bind_port, host=config.bind_host)).run()

Expand Down Expand Up @@ -271,8 +274,8 @@ def parse_port_int(config_arg: str) -> int:
# If config_idx is 1 (first parameter could be name of archive)
if config_idx == 1:
archive_name = config_arg
# If config_idx is not 1

# If config_idx is not 1
# (not the first parameter, wasn't parsed earlier, must be an invalid parameter)
else:
print(HELP, file=sys.stderr)
Expand Down

0 comments on commit 560598d

Please sign in to comment.