giga.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import itertools
  2. from .common import InfoExtractor
  3. from ..compat import compat_str
  4. from ..utils import parse_duration, parse_iso8601, qualities, str_to_int
  5. class GigaIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?giga\.de/(?:[^/]+/)*(?P<id>[^/]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.giga.de/filme/anime-awesome/trailer/anime-awesome-chihiros-reise-ins-zauberland-das-beste-kommt-zum-schluss/',
  9. 'md5': '6bc5535e945e724640664632055a584f',
  10. 'info_dict': {
  11. 'id': '2622086',
  12. 'display_id': 'anime-awesome-chihiros-reise-ins-zauberland-das-beste-kommt-zum-schluss',
  13. 'ext': 'mp4',
  14. 'title': 'Anime Awesome: Chihiros Reise ins Zauberland – Das Beste kommt zum Schluss',
  15. 'description': 'md5:afdf5862241aded4718a30dff6a57baf',
  16. 'thumbnail': r're:^https?://.*\.jpg$',
  17. 'duration': 578,
  18. 'timestamp': 1414749706,
  19. 'upload_date': '20141031',
  20. 'uploader': 'Robin Schweiger',
  21. 'view_count': int,
  22. },
  23. }, {
  24. 'url': 'http://www.giga.de/games/channel/giga-top-montag/giga-topmontag-die-besten-serien-2014/',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'http://www.giga.de/extra/netzkultur/videos/giga-games-tom-mats-robin-werden-eigene-wege-gehen-eine-ankuendigung/',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'http://www.giga.de/tv/jonas-liest-spieletitel-eingedeutscht-episode-2/',
  31. 'only_matching': True,
  32. }]
  33. def _real_extract(self, url):
  34. display_id = self._match_id(url)
  35. webpage = self._download_webpage(url, display_id)
  36. video_id = self._search_regex(
  37. [r'data-video-id="(\d+)"', r'/api/video/jwplayer/#v=(\d+)'],
  38. webpage, 'video id')
  39. playlist = self._download_json(
  40. 'http://www.giga.de/api/syndication/video/video_id/%s/playlist.json?content=syndication/key/368b5f151da4ae05ced7fa296bdff65a/'
  41. % video_id, video_id)[0]
  42. quality = qualities(['normal', 'hd720'])
  43. formats = []
  44. for format_id in itertools.count(0):
  45. fmt = playlist.get(compat_str(format_id))
  46. if not fmt:
  47. break
  48. formats.append({
  49. 'url': fmt['src'],
  50. 'format_id': '%s-%s' % (fmt['quality'], fmt['type'].split('/')[-1]),
  51. 'quality': quality(fmt['quality']),
  52. })
  53. title = self._html_search_meta(
  54. 'title', webpage, 'title', fatal=True)
  55. description = self._html_search_meta(
  56. 'description', webpage, 'description')
  57. thumbnail = self._og_search_thumbnail(webpage)
  58. duration = parse_duration(self._search_regex(
  59. r'(?s)(?:data-video-id="{0}"|data-video="[^"]*/api/video/jwplayer/#v={0}[^"]*")[^>]*>.+?<span class="duration">([^<]+)</span>'.format(video_id),
  60. webpage, 'duration', fatal=False))
  61. timestamp = parse_iso8601(self._search_regex(
  62. r'datetime="([^"]+)"', webpage, 'upload date', fatal=False))
  63. uploader = self._search_regex(
  64. r'class="author">([^<]+)</a>', webpage, 'uploader', fatal=False)
  65. view_count = str_to_int(self._search_regex(
  66. r'<span class="views"><strong>([\d.,]+)</strong>',
  67. webpage, 'view count', fatal=False))
  68. return {
  69. 'id': video_id,
  70. 'display_id': display_id,
  71. 'title': title,
  72. 'description': description,
  73. 'thumbnail': thumbnail,
  74. 'duration': duration,
  75. 'timestamp': timestamp,
  76. 'uploader': uploader,
  77. 'view_count': view_count,
  78. 'formats': formats,
  79. }