♻️ (DROP/__init__.py): reformat long lines for better readability and maintainability

This commit is contained in:
Sp4rk.y 2024-09-07 20:33:40 -06:00
parent dffcd199cd
commit 0c7115dda2

View File

@ -26,7 +26,9 @@ class DROP(Service):
TITLE_RE = r"^(?:https?://(?:www\.)?dropout\.tv/)([^/]+)(?:/.*)?$"
SERIES_RE = r"https?://(?:www\.)?dropout\.tv/([^/]+)(?:/season:(\d+))?/?$"
EPISODE_RE = r"https?://(?:www\.)?dropout\.tv/([^/]+)/season:(\d+)/videos/([^/]+)/?$"
EPISODE_RE = (
r"https?://(?:www\.)?dropout\.tv/([^/]+)/season:(\d+)/videos/([^/]+)/?$"
)
LOGIN_URL = "https://www.dropout.tv/login"
@ -58,7 +60,9 @@ class DROP(Service):
"utf8": "true",
}
response = self.session.post(self.LOGIN_URL, data=login_data, allow_redirects=False)
response = self.session.post(
self.LOGIN_URL, data=login_data, allow_redirects=False
)
if '<div id="watch-unauthorized"' in response.text:
self.log.error("Login failed")
@ -66,7 +70,9 @@ class DROP(Service):
else:
self.log.info("Login successful")
else:
self.log.info("No login credentials provided, proceeding without authentication")
self.log.info(
"No login credentials provided, proceeding without authentication"
)
def _get_authenticity_token(self):
signin_page = self.session.get(self.LOGIN_URL).text
@ -106,14 +112,20 @@ class DROP(Service):
episode_link = item.find("a", class_="browse-item-link")
if episode_link:
episode_url = episode_link["href"]
episode_data = json.loads(episode_link["data-track-event-properties"])
episode_data = json.loads(
episode_link["data-track-event-properties"]
)
episode_id = episode_data["id"]
episode_title = episode_data["label"]
episode_number_elem = item.find("span", class_="media-identifier media-episode")
episode_number_elem = item.find(
"span", class_="media-identifier media-episode"
)
if episode_number_elem:
episode_number_match = re.search(r"Episode (\d+)", episode_number_elem.text)
episode_number_match = re.search(
r"Episode (\d+)", episode_number_elem.text
)
if episode_number_match:
episode_number = int(episode_number_match.group(1))
else:
@ -169,21 +181,13 @@ class DROP(Service):
cdn = cdns.get(default_cdn) or next(iter(cdns.values()))
mpd_url = cdn["avc_url"].replace("playlist.json", "playlist.mpd")
tracks = HLS.from_url(url=mpd_url).to_tracks(language="en")
# Extract thumbnail URL from config_data
thumbnail_base_url = config_data["video"]["thumbs"]["base"]
thumbnail_url = f"{thumbnail_base_url}"
# Download the thumbnail
thumbnail_response = self.session.get(thumbnail_url)
if thumbnail_response.status_code == 200:
thumbnail_filename = f"{title.id}_thumbnail.jpg"
thumbnail_path = config.directories.temp / thumbnail_filename
# Ensure the directory exists
os.makedirs(config.directories.temp, exist_ok=True)
# Save the thumbnail file
with open(thumbnail_path, "wb") as f:
f.write(thumbnail_response.content)
@ -192,10 +196,9 @@ class DROP(Service):
path=thumbnail_path,
name=thumbnail_filename,
mime_type="image/jpeg",
description="Thumbnail"
description="Thumbnail",
)
# Add the attachment to the tracks
tracks.attachments.append(thumbnail_attachment)
return tracks