Update fptplay.py

This commit is contained in:
MrHulk 2024-09-12 13:58:34 +05:30 committed by GitHub
parent b36acfe977
commit 017bbfe491
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,13 +1,11 @@
import hashlib import hashlib
import time import time
import urllib.parse import urllib.parse
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
int_or_none, int_or_none,
) )
class FptplayIE(InfoExtractor): class FptplayIE(InfoExtractor):
_VALID_URL = r'https?://fptplay\.vn/xem-video/[^/]+\-(?P<id>[a-f0-9]+)' _VALID_URL = r'https?://fptplay\.vn/xem-video/[^/]+\-(?P<id>[a-f0-9]+)'
_GEO_COUNTRIES = ['VN'] _GEO_COUNTRIES = ['VN']
@ -37,7 +35,6 @@ class FptplayIE(InfoExtractor):
'duration': '2665', 'duration': '2665',
}, },
}] }]
def _real_extract(self, url): def _real_extract(self, url):
contentId = self._match_id(url) contentId = self._match_id(url)
# Need valid cookie with Bearer token, else it won't work # Need valid cookie with Bearer token, else it won't work
@ -63,16 +60,12 @@ class FptplayIE(InfoExtractor):
# playlist # playlist
entries = [] entries = []
for episode in res['result']['episodes']: for episode in res['result']['episodes']:
if episode['is_trailer'] == 1: if episode['is_trailer'] == 1:
continue continue
manifest = self._download_json(self.get_api_with_st_token(contentId, episode['_id']), episode['_id'], headers={'authorization': f'Bearer {token.value}'}, expected_status=406) manifest = self._download_json(self.get_api_with_st_token(contentId, episode['_id']), episode['_id'], headers={'authorization': f'Bearer {token.value}'}, expected_status=406)
if manifest.get('msg') != 'success': if manifest.get('msg') != 'success':
raise ExtractorError(f" - Got an error, response: {manifest.get('msg')}", expected=True) raise ExtractorError(f" - Got an error, response: {manifest.get('msg')}", expected=True)
formats, subtitles = self._extract_m3u8_formats_and_subtitles(manifest['data']['url'], episode['_id']) formats, subtitles = self._extract_m3u8_formats_and_subtitles(manifest['data']['url'], episode['_id'])
entry = { entry = {
'id': episode['ref_episode_id'], 'id': episode['ref_episode_id'],
'title': res['result']['title_origin'] if res['result']['title_origin'] else res['result']['title_vie'], 'title': res['result']['title_origin'] if res['result']['title_origin'] else res['result']['title_vie'],
@ -87,14 +80,12 @@ class FptplayIE(InfoExtractor):
'subtitles': subtitles, 'subtitles': subtitles,
} }
entries.append(entry) entries.append(entry)
return { return {
'_type': 'playlist', '_type': 'playlist',
'id': contentId, 'id': contentId,
'title': res['result']['title_origin'] if res['result']['title_origin'] else res['result']['title_vie'], 'title': res['result']['title_origin'] if res['result']['title_origin'] else res['result']['title_vie'],
'entries': entries, 'entries': entries,
} }
def get_api_with_st_token(self, video_id, episode=None): def get_api_with_st_token(self, video_id, episode=None):
if episode is not None: if episode is not None:
path = f'/api/v7.1_w/stream/vod/{video_id}/{0 if episode is None else episode}/adaptive_bitrate' path = f'/api/v7.1_w/stream/vod/{video_id}/{0 if episode is None else episode}/adaptive_bitrate'
@ -104,7 +95,6 @@ class FptplayIE(InfoExtractor):
t = hashlib.md5(f'6ea6d2a4e2d3a4bd5e275401aa086d{timestamp}{path}'.encode()).hexdigest().upper() t = hashlib.md5(f'6ea6d2a4e2d3a4bd5e275401aa086d{timestamp}{path}'.encode()).hexdigest().upper()
r = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' r = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
n = [int(f'0x{t[2 * o: 2 * o + 2]}', 16) for o in range(len(t) // 2)] n = [int(f'0x{t[2 * o: 2 * o + 2]}', 16) for o in range(len(t) // 2)]
def convert(e): def convert(e):
t = '' t = ''
n = 0 n = 0
@ -139,6 +129,5 @@ class FptplayIE(InfoExtractor):
t += '' t += ''
n += 1 n += 1
return t return t
st_token = convert(n).replace('+', '-').replace('/', '_').replace('=', '') st_token = convert(n).replace('+', '-').replace('/', '_').replace('=', '')
return f"https://api.fptplay.net{path}?{urllib.parse.urlencode({'st': st_token, 'e': timestamp})}" return f"https://api.fptplay.net{path}?{urllib.parse.urlencode({'st': st_token, 'e': timestamp})}"