Skip to content

Commit

Permalink
add title support to twitter
Browse files Browse the repository at this point in the history
also raise for status on the response now, should have done that before ngl...
  • Loading branch information
kytpbs committed Aug 27, 2024
1 parent ef6b507 commit 6e0ce53
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _get_highest_quality_url_list(response: requests.Response) -> list[str]:

def _get_title(response: requests.Response) -> str:
data = bs4.BeautifulSoup(response.text, "html.parser")
title = data.find("title")
title = data.find("p", class_="m-2")

if not isinstance(title, bs4.element.Tag):
logging.warning("No title found in URL: %s", response.url)
Expand Down Expand Up @@ -95,6 +95,7 @@ async def download_video_from_link(

try:
response = requests.get(API_URL_START + url, timeout=30)
response.raise_for_status()
except requests.exceptions.RequestException as e:
logging.warning(
"Downloading from 3'rd party failed due to error: %s, trying with alternative downloader",
Expand All @@ -110,8 +111,11 @@ async def download_video_from_link(
return attachment_list

download_urls = _get_highest_quality_url_list(response)
title = _get_title(response)
downloaded_file_paths = await cls._download_links(download_urls, path, tweet_id)

attachment_list = [VideoFile(path) for path in downloaded_file_paths]
attachment_list[0]._title = title


return attachment_list

0 comments on commit 6e0ce53

Please sign in to comment.