gamestar.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. remove_end,
  7. )
  8. class GameStarIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?game(?:pro|star)\.de/videos/.*,(?P<id>[0-9]+)\.html'
  10. _TESTS = [
  11. {
  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. {
  26. 'url': 'http://www.gamepro.de/videos/top-10-indie-spiele-fuer-nintendo-switch-video-tolle-nindies-games-zum-download,95316.html',
  27. 'only_matching': True,
  28. },
  29. ]
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. url = 'http://gamestar.de/_misc/videos/portal/getVideoUrl.cfm?premium=0&videoId=' + video_id
  34. # TODO: there are multiple ld+json objects in the webpage,
  35. # while _search_json_ld finds only the first one
  36. json_ld = self._parse_json(self._search_regex(
  37. r'(?s)<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json_ld>[^<]+VideoObject[^<]+)</script>',
  38. webpage, 'JSON-LD', group='json_ld'), video_id)
  39. info_dict = self._json_ld(json_ld, video_id)
  40. info_dict['title'] = remove_end(info_dict['title'], ' - GameStar')
  41. info_dict['title'] = remove_end(info_dict['title'], ' - GamePro')
  42. view_count = int_or_none(json_ld.get('interactionCount'))
  43. comment_count = int_or_none(self._html_search_regex(
  44. r'<span>Kommentare</span><span class="count">\(([0-9]+)\)</span>',
  45. webpage, 'comment_count', fatal=False))
  46. info_dict.update({
  47. 'id': video_id,
  48. 'url': url,
  49. 'ext': 'mp4',
  50. 'view_count': view_count,
  51. 'comment_count': comment_count
  52. })
  53. return info_dict