logo

youtube-dl

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

gamestar.py (2624B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. remove_end,
  8. )
  9. class GameStarIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?game(?P<site>pro|star)\.de/videos/.*,(?P<id>[0-9]+)\.html'
  11. _TESTS = [{
  12. 'url': 'http://www.gamestar.de/videos/trailer,3/hobbit-3-die-schlacht-der-fuenf-heere,76110.html',
  13. 'md5': 'ee782f1f8050448c95c5cacd63bc851c',
  14. 'info_dict': {
  15. 'id': '76110',
  16. 'ext': 'mp4',
  17. 'title': 'Hobbit 3: Die Schlacht der Fünf Heere - Teaser-Trailer zum dritten Teil',
  18. 'description': 'Der Teaser-Trailer zu Hobbit 3: Die Schlacht der Fünf Heere zeigt einige Szenen aus dem dritten Teil der Saga und kündigt den...',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. 'timestamp': 1406542380,
  21. 'upload_date': '20140728',
  22. 'duration': 17,
  23. }
  24. }, {
  25. 'url': 'http://www.gamepro.de/videos/top-10-indie-spiele-fuer-nintendo-switch-video-tolle-nindies-games-zum-download,95316.html',
  26. 'only_matching': True,
  27. }, {
  28. 'url': 'http://www.gamestar.de/videos/top-10-indie-spiele-fuer-nintendo-switch-video-tolle-nindies-games-zum-download,95316.html',
  29. 'only_matching': True,
  30. }]
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. site = mobj.group('site')
  34. video_id = mobj.group('id')
  35. webpage = self._download_webpage(url, video_id)
  36. # TODO: there are multiple ld+json objects in the webpage,
  37. # while _search_json_ld finds only the first one
  38. json_ld = self._parse_json(self._search_regex(
  39. r'(?s)<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json_ld>[^<]+VideoObject[^<]+)</script>',
  40. webpage, 'JSON-LD', group='json_ld'), video_id)
  41. info_dict = self._json_ld(json_ld, video_id)
  42. info_dict['title'] = remove_end(
  43. info_dict['title'], ' - Game%s' % site.title())
  44. view_count = int_or_none(json_ld.get('interactionCount'))
  45. comment_count = int_or_none(self._html_search_regex(
  46. r'<span>Kommentare</span>\s*<span[^>]+class=["\']count[^>]+>\s*\(\s*([0-9]+)',
  47. webpage, 'comment count', fatal=False))
  48. info_dict.update({
  49. 'id': video_id,
  50. 'url': 'http://gamestar.de/_misc/videos/portal/getVideoUrl.cfm?premium=0&videoId=' + video_id,
  51. 'ext': 'mp4',
  52. 'view_count': view_count,
  53. 'comment_count': comment_count
  54. })
  55. return info_dict