logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

telewebion.py (1946B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. int_or_none,
  7. url_or_none,
  8. )
  9. class TelewebionIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?telewebion\.com/(episode|clip)/(?P<id>[a-zA-Z0-9]+)'
  11. _TEST = {
  12. 'url': 'http://www.telewebion.com/episode/0x1b3139c/',
  13. 'info_dict': {
  14. 'id': '0x1b3139c',
  15. 'ext': 'mp4',
  16. 'title': 'قرعه\u200cکشی لیگ قهرمانان اروپا',
  17. 'thumbnail': r're:^https?://static\.telewebion\.com/episodeImages/.*/default',
  18. 'view_count': int,
  19. },
  20. 'params': {
  21. # m3u8 download
  22. 'skip_download': True,
  23. },
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. episode_details = self._download_json('https://gateway.telewebion.ir/kandoo/episode/getEpisodeDetail/?EpisodeId={0}'.format(video_id), video_id)
  28. episode_details = episode_details['body']['queryEpisode'][0]
  29. channel_id = episode_details['channel']['descriptor']
  30. episode_image_id = episode_details.get('image')
  31. episode_image = 'https://static.telewebion.com/episodeImages/{0}/default'.format(episode_image_id) if episode_image_id else None
  32. m3u8_url = 'https://cdna.telewebion.com/{0}/episode/{1}/playlist.m3u8'.format(channel_id, video_id)
  33. formats = self._extract_m3u8_formats(
  34. m3u8_url, video_id, ext='mp4', m3u8_id='hls',
  35. entry_protocol='m3u8_native')
  36. self._sort_formats(formats)
  37. return {
  38. 'id': video_id,
  39. 'title': episode_details['title'],
  40. 'formats': formats,
  41. 'thumbnail': url_or_none(episode_image),
  42. 'view_count': int_or_none(episode_details.get('view_count')),
  43. 'duration': float_or_none(episode_details.get('duration')),
  44. }