fptplay.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import hashlib
  2. import time
  3. import urllib.parse
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. join_nonempty,
  8. strip_or_none,
  9. )
  10. class FptplayIE(InfoExtractor):
  11. _VALID_URL = r'https?://fptplay\.vn/xem-video/[^/]+\-(?P<id>\w+)(?:/tap-(?P<episode>\d+)?/?(?:[?#]|$)|)'
  12. _GEO_COUNTRIES = ['VN']
  13. IE_NAME = 'fptplay'
  14. IE_DESC = 'fptplay.vn'
  15. _TESTS = [{
  16. 'url': 'https://fptplay.vn/xem-video/nhan-duyen-dai-nhan-xin-dung-buoc-621a123016f369ebbde55945',
  17. 'md5': 'ca0ee9bc63446c0c3e9a90186f7d6b33',
  18. 'info_dict': {
  19. 'id': '621a123016f369ebbde55945',
  20. 'ext': 'mp4',
  21. 'title': 'Nhân Duyên Đại Nhân Xin Dừng Bước - Tập 1A',
  22. 'description': 'md5:23cf7d1ce0ade8e21e76ae482e6a8c6c',
  23. },
  24. }, {
  25. 'url': 'https://fptplay.vn/xem-video/ma-toi-la-dai-gia-61f3aa8a6b3b1d2e73c60eb5/tap-3',
  26. 'md5': 'b35be968c909b3e4e1e20ca45dd261b1',
  27. 'info_dict': {
  28. 'id': '61f3aa8a6b3b1d2e73c60eb5',
  29. 'ext': 'mp4',
  30. 'title': 'Má Tôi Là Đại Gia - Tập 3',
  31. 'description': 'md5:ff8ba62fb6e98ef8875c42edff641d1c',
  32. },
  33. }, {
  34. 'url': 'https://fptplay.vn/xem-video/lap-toi-do-giam-under-the-skin-6222d9684ec7230fa6e627a2/tap-4',
  35. 'md5': 'bcb06c55ec14786d7d4eda07fa1ccbb9',
  36. 'info_dict': {
  37. 'id': '6222d9684ec7230fa6e627a2',
  38. 'ext': 'mp4',
  39. 'title': 'Lạp Tội Đồ Giám - Tập 2B',
  40. 'description': 'md5:e5a47e9d35fbf7e9479ca8a77204908b',
  41. },
  42. }, {
  43. 'url': 'https://fptplay.vn/xem-video/nha-co-chuyen-hi-alls-well-ends-well-1997-6218995f6af792ee370459f0',
  44. 'only_matching': True,
  45. }]
  46. def _real_extract(self, url):
  47. video_id, slug_episode = self._match_valid_url(url).group('id', 'episode')
  48. webpage = self._download_webpage(url, video_id=video_id, fatal=False) or ''
  49. title = self._search_regex(
  50. r'(?s)<h4\s+class="mb-1 text-2xl text-white"[^>]*>(.+)</h4>', webpage, 'title', fatal=False)
  51. real_episode = slug_episode if not title else self._search_regex(
  52. r'<p.+title="(?P<episode>[^">]+)"\s+class="epi-title active"', webpage, 'episode', fatal=False)
  53. title = strip_or_none(title) or self._html_search_meta(('og:title', 'twitter:title'), webpage)
  54. info = self._download_json(
  55. self.get_api_with_st_token(video_id, int(slug_episode) - 1 if slug_episode else 0), video_id)
  56. formats, subtitles = self._extract_m3u8_formats_and_subtitles(info['data']['url'], video_id, 'mp4')
  57. return {
  58. 'id': video_id,
  59. 'title': join_nonempty(title, real_episode, delim=' - '),
  60. 'description': (
  61. clean_html(self._search_regex(r'<p\s+class="overflow-hidden"[^>]*>(.+)</p>', webpage, 'description'))
  62. or self._html_search_meta(('og:description', 'twitter:description'), webpage)),
  63. 'formats': formats,
  64. 'subtitles': subtitles,
  65. }
  66. def get_api_with_st_token(self, video_id, episode):
  67. path = f'/api/v6.2_w/stream/vod/{video_id}/{episode}/auto_vip'
  68. timestamp = int(time.time()) + 10800
  69. t = hashlib.md5(f'WEBv6Dkdsad90dasdjlALDDDS{timestamp}{path}'.encode()).hexdigest().upper()
  70. r = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  71. n = [int(f'0x{t[2 * o: 2 * o + 2]}', 16) for o in range(len(t) // 2)]
  72. def convert(e):
  73. t = ''
  74. n = 0
  75. i = [0, 0, 0]
  76. a = [0, 0, 0, 0]
  77. s = len(e)
  78. c = 0
  79. for _ in range(s, 0, -1):
  80. if n <= 3:
  81. i[n] = e[c]
  82. n += 1
  83. c += 1
  84. if 3 == n:
  85. a[0] = (252 & i[0]) >> 2
  86. a[1] = ((3 & i[0]) << 4) + ((240 & i[1]) >> 4)
  87. a[2] = ((15 & i[1]) << 2) + ((192 & i[2]) >> 6)
  88. a[3] = (63 & i[2])
  89. for v in range(4):
  90. t += r[a[v]]
  91. n = 0
  92. if n:
  93. for o in range(n, 3):
  94. i[o] = 0
  95. for o in range(n + 1):
  96. a[0] = (252 & i[0]) >> 2
  97. a[1] = ((3 & i[0]) << 4) + ((240 & i[1]) >> 4)
  98. a[2] = ((15 & i[1]) << 2) + ((192 & i[2]) >> 6)
  99. a[3] = (63 & i[2])
  100. t += r[a[o]]
  101. n += 1
  102. while n < 3:
  103. t += ''
  104. n += 1
  105. return t
  106. st_token = convert(n).replace('+', '-').replace('/', '_').replace('=', '')
  107. return f'https://api.fptplay.net{path}?{urllib.parse.urlencode({"st": st_token, "e": timestamp})}'