telewebion.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from .common import InfoExtractor
  2. class TelewebionIE(InfoExtractor):
  3. _VALID_URL = r'https?://(?:www\.)?telewebion\.com/#!/episode/(?P<id>\d+)'
  4. _TEST = {
  5. 'url': 'http://www.telewebion.com/#!/episode/1263668/',
  6. 'info_dict': {
  7. 'id': '1263668',
  8. 'ext': 'mp4',
  9. 'title': 'قرعه\u200cکشی لیگ قهرمانان اروپا',
  10. 'thumbnail': r're:^https?://.*\.jpg',
  11. 'view_count': int,
  12. },
  13. 'params': {
  14. # m3u8 download
  15. 'skip_download': True,
  16. },
  17. }
  18. def _real_extract(self, url):
  19. video_id = self._match_id(url)
  20. secure_token = self._download_webpage(
  21. 'http://m.s2.telewebion.com/op/op?action=getSecurityToken', video_id)
  22. episode_details = self._download_json(
  23. 'http://m.s2.telewebion.com/op/op', video_id,
  24. query={'action': 'getEpisodeDetails', 'episode_id': video_id})
  25. m3u8_url = 'http://m.s1.telewebion.com/smil/%s.m3u8?filepath=%s&m3u8=1&secure_token=%s' % (
  26. video_id, episode_details['file_path'], secure_token)
  27. formats = self._extract_m3u8_formats(
  28. m3u8_url, video_id, ext='mp4', m3u8_id='hls')
  29. picture_paths = [
  30. episode_details.get('picture_path'),
  31. episode_details.get('large_picture_path'),
  32. ]
  33. thumbnails = [{
  34. 'url': picture_path,
  35. 'preference': idx,
  36. } for idx, picture_path in enumerate(picture_paths) if picture_path is not None]
  37. return {
  38. 'id': video_id,
  39. 'title': episode_details['title'],
  40. 'formats': formats,
  41. 'thumbnails': thumbnails,
  42. 'view_count': episode_details.get('view_count'),
  43. }