1010}
1111
1212
13- def fetch_web_content (
14- translations : dict [str , str ], url : str , stream : bool = True
15- ) -> requests .Response :
13+ def fetch_web_content (url : str , stream : bool = True ) -> requests .Response :
1614 """Fetch the web content from the given URL.
1715
1816 Args:
19- translations (dict[str, str]): A dictionary containing translation strings.
2017 url (str): The URL to fetch the content from.
21- stream (bool, optional ): Whether to stream the content or not. Defaults to True.
18+ stream (bool): Whether to stream the content or not. Defaults to True.
2219
2320 Returns:
2421 requests.Response: The response object.
25-
26- Raises:
27- requests.exceptions.RequestException: If there is an error during the request.
2822 """
29- try :
30- scraper : cloudscraper .CloudScraper = cloudscraper .create_scraper ()
23+ logger .debug ("Fetching web content from URL: %s" , url )
3124
32- headers [ "Referer" ] = url
25+ scraper : cloudscraper . CloudScraper = cloudscraper . create_scraper ()
3326
34- response : requests .Response = scraper .get (url , headers = headers , stream = stream )
35- response .raise_for_status ()
27+ headers ["Referer" ] = url
3628
37- print ( translations [ "success_message" ]. format ( str ( response . status_code )) )
38- return response
29+ response : requests . Response = scraper . get ( url , headers = headers , stream = stream )
30+ response . raise_for_status ()
3931
40- except requests .exceptions .RequestException as e :
41- print (translations ["failure_message" ].format (str (e )))
42- logger .error (e )
43- raise
32+ return response
4433
4534
46- def extract_video_info (translations : dict [ str , str ], html : str ) -> tuple [str , str ]:
35+ def extract_video_info (html : str ) -> tuple [str , str ]:
4736 """
4837 Extract video information from the HTML content.
4938
5039 Args:
51- translations (dict[str, str]): A dictionary containing translation strings.
5240 html (str): The HTML content to extract information from.
5341
5442 Returns:
@@ -57,18 +45,15 @@ def extract_video_info(translations: dict[str, str], html: str) -> tuple[str, st
5745 Raises:
5846 Exception: If the video information cannot be extracted.
5947 """
60- try :
61- result : re .Match [str ] | None = re .search (
62- '<video.*?src="(.*?)".*?>.*?</video>' , html , re .S
63- )
64- src : str = result .group (1 )
65- result2 : re .Match [str ] | None = re .search (
66- "<title.*?>Watch(.*?) - .*?</title.*?>" , html , re .S
67- )
68- title : str = result2 .group (1 )
69-
70- return title , src
71- except Exception as e :
72- print (translations ["video_not_found" ], e )
73- logger .error (e )
74- raise
48+ logger .debug ("Extracting video information from HTML content" )
49+
50+ result : re .Match [str ] | None = re .search (
51+ '<video.*?src="(.*?)".*?>.*?</video>' , html , re .S
52+ )
53+ src : str = result .group (1 )
54+ result2 : re .Match [str ] | None = re .search (
55+ "<title.*?>Watch(.*?) - .*?</title.*?>" , html , re .S
56+ )
57+ title : str = result2 .group (1 ).strip ()
58+
59+ return title , src
0 commit comments