Skip to content

Commit

Permalink
Merge pull request #14 from code-yeongyu/code-yeongyu/fix-domain-error
Browse files Browse the repository at this point in the history
Fix domain errors
  • Loading branch information
code-yeongyu authored Oct 15, 2023
2 parents c0f77f6 + 3311a6a commit 08f81bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions twtvt/utils/cookie_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
from http.cookiejar import CookieJar
from typing import Callable, Optional
from typing import Callable, Optional, cast

import browser_cookie3

Expand All @@ -18,35 +18,35 @@ class SupportedBrowser(Enum):
SAFARI = 'safari'


def get_cookie_loader(browser_name: Optional[SupportedBrowser]) -> Callable[[str], CookieJar]:
def get_cookie_loader(browser_name: Optional[SupportedBrowser]) -> Callable[[None], CookieJar]:

def wrapper(domain: str) -> CookieJar:
def wrapper() -> CookieJar:
if browser_name == SupportedBrowser.CHROME:
return browser_cookie3.chrome(domain)
return browser_cookie3.chrome()
if browser_name == SupportedBrowser.FIREFOX:
return browser_cookie3.firefox(domain)
return browser_cookie3.firefox()
if browser_name == SupportedBrowser.OPERA:
return browser_cookie3.opera(domain)
return browser_cookie3.opera()
if browser_name == SupportedBrowser.OPERA_GX:
return browser_cookie3.opera_gx(domain)
return browser_cookie3.opera_gx()
if browser_name == SupportedBrowser.EDGE:
return browser_cookie3.edge(domain)
return browser_cookie3.edge()
if browser_name == SupportedBrowser.CHROMIUM:
return browser_cookie3.chromium(domain)
return browser_cookie3.chromium()
if browser_name == SupportedBrowser.BRAVE:
return browser_cookie3.brave(domain)
return browser_cookie3.brave()
if browser_name == SupportedBrowser.VIVALDI:
return browser_cookie3.vivaldi(domain)
return browser_cookie3.vivaldi()
if browser_name == SupportedBrowser.SAFARI:
return browser_cookie3.safari(domain)
return browser_cookie3.load(domain)
return browser_cookie3.safari()
return browser_cookie3.load()

return wrapper


def load_cookies(browser_name: Optional[SupportedBrowser] = None, domain: str = '') -> CookieJar:
cookie_loader = get_cookie_loader(browser_name=browser_name)
all_cookies = cookie_loader(domain)
all_cookies = cast(CookieJar, cookie_loader())
if not domain:
return all_cookies

Expand Down
2 changes: 1 addition & 1 deletion twtvt/utils/download_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _extract_from_twitter_links(
twitter_parser = TwitterParser(page)
if cookiejar:
twitter_parser.login_with_cookiejar(cookiejar)
if username and password:
elif username and password:
twitter_parser.login(username, password)
else:
raise ValueError('Username and password, or cookies_from_browser is required for twitter links.')
Expand Down

0 comments on commit 08f81bd

Please sign in to comment.