mirror of
https://github.com/anonymousx97/social-dl.git
synced 2025-02-20 11:13:19 +08:00
Fixes: • Sender Now shows Correct name while downloading replied media. • Clean up code for YoutubeDL. • Format code according to PEP. Added: • .cancel to cancel a command/media download execution. • switch to @cached_property decorator and clean up message.py • Parse replied message using custom message class. • Rename tools to dev_tools and move loader to it. • self-destructing responses.
34 lines
996 B
Python
34 lines
996 B
Python
import os
|
|
from urllib.parse import urlparse
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
from app.core import aiohttp_tools
|
|
from app.core.scraper_config import ScraperConfig
|
|
|
|
|
|
class Threads(ScraperConfig):
|
|
def __init__(self, url):
|
|
super().__init__()
|
|
self.url = url
|
|
|
|
async def download_or_extract(self):
|
|
shortcode = os.path.basename(urlparse(self.url).path.rstrip("/"))
|
|
|
|
response = await (
|
|
await aiohttp_tools.SESSION.get(
|
|
f"https://www.threads.net/t/{shortcode}/embed/"
|
|
)
|
|
).text()
|
|
|
|
soup = BeautifulSoup(response, "html.parser")
|
|
|
|
if div := soup.find("div", {"class": "SingleInnerMediaContainer"}):
|
|
if video := div.find("video"):
|
|
self.link = video.find("source").get("src")
|
|
self.video = self.success = True
|
|
|
|
elif image := div.find("img", {"class": "img"}):
|
|
self.link = image.get("src")
|
|
self.photo = self.success = True
|