gamestar.py 2.5 KB

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