islamchannel.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import traverse_obj, urljoin
  4. class IslamChannelIE(InfoExtractor):
  5. _VALID_URL = r'https?://watch\.islamchannel\.tv/watch/(?P<id>\d+)'
  6. _TESTS = [{
  7. 'url': 'https://watch.islamchannel.tv/watch/38604310',
  8. 'info_dict': {
  9. 'id': '38604310',
  10. 'title': 'Omar - Young Omar',
  11. 'description': 'md5:5cc7ddecef064ea7afe52eb5e0e33b55',
  12. 'thumbnail': r're:https?://.+',
  13. 'ext': 'mp4',
  14. },
  15. }]
  16. def _real_extract(self, url):
  17. video_id = self._match_id(url)
  18. webpage = self._download_webpage(url, video_id)
  19. thumbnail = self._search_regex(
  20. r'data-poster="([^"]+)"', webpage, 'data poster', fatal=False) or \
  21. self._html_search_meta(('og:image', 'twitter:image'), webpage)
  22. headers = {
  23. 'Token': self._search_regex(r'data-token="([^"]+)"', webpage, 'data token'),
  24. 'Token-Expiry': self._search_regex(r'data-expiry="([^"]+)"', webpage, 'data expiry'),
  25. 'Uvid': video_id,
  26. }
  27. show_stream = self._download_json(
  28. f'https://v2-streams-elb.simplestreamcdn.com/api/show/stream/{video_id}', video_id,
  29. query={
  30. 'key': self._search_regex(r'data-key="([^"]+)"', webpage, 'data key'),
  31. 'platform': 'chrome',
  32. }, headers=headers)
  33. # TODO: show_stream['stream'] and show_stream['drm'] may contain something interesting
  34. streams = self._download_json(
  35. traverse_obj(show_stream, ('response', 'tokenization', 'url')), video_id,
  36. headers=headers)
  37. formats, subs = self._extract_m3u8_formats_and_subtitles(traverse_obj(streams, ('Streams', 'Adaptive')), video_id, 'mp4')
  38. return {
  39. 'id': video_id,
  40. 'title': self._html_search_meta(('og:title', 'twitter:title'), webpage),
  41. 'description': self._html_search_meta(('og:description', 'twitter:description', 'description'), webpage),
  42. 'formats': formats,
  43. 'subtitles': subs,
  44. 'thumbnails': [{
  45. 'id': 'unscaled',
  46. 'url': thumbnail.split('?')[0],
  47. 'ext': 'jpg',
  48. 'preference': 2,
  49. }, {
  50. 'id': 'orig',
  51. 'url': thumbnail,
  52. 'ext': 'jpg',
  53. 'preference': 1,
  54. }] if thumbnail else None,
  55. }
  56. class IslamChannelSeriesIE(InfoExtractor):
  57. _VALID_URL = r'https?://watch\.islamchannel\.tv/series/(?P<id>[a-f\d-]+)'
  58. _TESTS = [{
  59. 'url': 'https://watch.islamchannel.tv/series/a6cccef3-3ef1-11eb-bc19-06b69c2357cd',
  60. 'info_dict': {
  61. 'id': 'a6cccef3-3ef1-11eb-bc19-06b69c2357cd',
  62. },
  63. 'playlist_mincount': 31,
  64. }]
  65. def _real_extract(self, url):
  66. pl_id = self._match_id(url)
  67. webpage = self._download_webpage(url, pl_id)
  68. return self.playlist_from_matches(
  69. re.finditer(r'<a\s+href="(/watch/\d+)"[^>]+?data-video-type="show">', webpage),
  70. pl_id, getter=lambda x: urljoin(url, x.group(1)), ie=IslamChannelIE)