[Update - CR] Added Subtitle Tracks.

master
ToonsHub 2024-03-06 18:24:53 +01:00
parent c5b197b093
commit cb45e8aa3f
1 changed files with 14 additions and 21 deletions

View File

@ -21,7 +21,7 @@ from devine.core.console import console
from devine.core.constants import AnyTrack
from devine.core.credential import Credential
from devine.core.titles import Title_T, Titles_T
from devine.core.tracks import Chapters, Tracks
from devine.core.tracks import Video, Audio, Subtitle, Chapter, Chapters, Tracks
from devine.core.utilities import get_ip_info
from devine.core.manifests import HLS, DASH
@ -60,25 +60,6 @@ class CR(Service):
# Overriding the constructor
super().__init__(ctx)
# Define function to get a session for service
@staticmethod
def get_session() -> requests.Session:
# Start a session
session = requests.Session()
# Set the headers
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
}
# Update the headers for the session
session.headers.update(headers)
# return the session
return session
# Defining an authinticate function
def authenticate(self, cookies: Optional[CookieJar], credential: Optional[Credential] = None):
@ -248,9 +229,21 @@ class CR(Service):
# Get the MPD URL
mpd_url = mpd_info.json()['data'][0]['drm_adaptive_dash']['']['url']
mpd_lang = mpd_info.json()['meta']['audio_locale']
# Grab the tracks from the MPD
tracks = DASH.from_url(url=mpd_url).to_tracks(language="en")
tracks = DASH.from_url(url=mpd_url).to_tracks(language=mpd_lang)
# Get subtitles
for _, sub in mpd_info.json()['meta']['subtitles'].items():
tracks.add(
Subtitle(
url=sub['url'],
codec=Subtitle.Codec.from_mime(sub['format']),
language=sub['locale'],
forced=(sub['locale'] == mpd_lang), # If audio language matches subtitle language, it's Forced.
)
)
# Return the tracks
return tracks