logo

youtube-dl

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

giga.py (3820B)


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