You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import float_or_none
  6. from ..utils import int_or_none
  7. from ..utils import js_to_json
  8. from ..utils import unified_strdate
  9. class GaskrankIE(InfoExtractor):
  10. """InfoExtractor for gaskrank.tv"""
  11. _VALID_URL = r'https?://(?:www\.)?gaskrank\.tv/tv/(?P<categories>[^/]+)/(?P<id>[^/]+)\.html?'
  12. _TESTS = [
  13. {
  14. 'url': 'http://www.gaskrank.tv/tv/motorrad-fun/strike-einparken-durch-anfaenger-crash-mit-groesserem-flurschaden.htm',
  15. 'md5': '1ae88dbac97887d85ebd1157a95fc4f9',
  16. 'info_dict': {
  17. 'id': '201601/26955',
  18. 'ext': 'mp4',
  19. 'title': 'Strike! Einparken können nur Männer - Flurschaden hält sich in Grenzen *lol*',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'categories': ['motorrad-fun'],
  22. 'display_id': 'strike-einparken-durch-anfaenger-crash-mit-groesserem-flurschaden',
  23. 'uploader_id': 'Bikefun',
  24. 'upload_date': '20170110',
  25. 'uploader_url': None,
  26. }
  27. },
  28. {
  29. 'url': 'http://www.gaskrank.tv/tv/racing/isle-of-man-tt-2011-michael-du-15920.htm',
  30. 'md5': 'c33ee32c711bc6c8224bfcbe62b23095',
  31. 'info_dict': {
  32. 'id': '201106/15920',
  33. 'ext': 'mp4',
  34. 'title': 'Isle of Man - Michael Dunlop vs Guy Martin - schwindelig kucken',
  35. 'thumbnail': r're:^https?://.*\.jpg$',
  36. 'categories': ['racing'],
  37. 'display_id': 'isle-of-man-tt-2011-michael-du-15920',
  38. 'uploader_id': 'IOM',
  39. 'upload_date': '20160506',
  40. 'uploader_url': 'www.iomtt.com',
  41. }
  42. }
  43. ]
  44. def _real_extract(self, url):
  45. """extract information from gaskrank.tv"""
  46. def fix_json(code):
  47. """Removes trailing comma in json: {{},} --> {{}}"""
  48. return re.sub(r',\s*}', r'}', js_to_json(code))
  49. display_id = self._match_id(url)
  50. webpage = self._download_webpage(url, display_id)
  51. categories = [re.match(self._VALID_URL, url).group('categories')]
  52. title = self._search_regex(
  53. r'movieName\s*:\s*\'([^\']*)\'',
  54. webpage, 'title')
  55. thumbnail = self._search_regex(
  56. r'poster\s*:\s*\'([^\']*)\'',
  57. webpage, 'thumbnail', default=None)
  58. mobj = re.search(
  59. r'Video von:\s*(?P<uploader_id>[^|]*?)\s*\|\s*vom:\s*(?P<upload_date>[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9])',
  60. webpage)
  61. if mobj is not None:
  62. uploader_id = mobj.groupdict().get('uploader_id')
  63. upload_date = unified_strdate(mobj.groupdict().get('upload_date'))
  64. uploader_url = self._search_regex(
  65. r'Homepage:\s*<[^>]*>(?P<uploader_url>[^<]*)',
  66. webpage, 'uploader_url', default=None)
  67. tags = re.findall(
  68. r'/tv/tags/[^/]+/"\s*>(?P<tag>[^<]*?)<',
  69. webpage)
  70. view_count = self._search_regex(
  71. r'class\s*=\s*"gkRight"(?:[^>]*>\s*<[^>]*)*icon-eye-open(?:[^>]*>\s*<[^>]*)*>\s*(?P<view_count>[0-9\.]*)',
  72. webpage, 'view_count', default=None)
  73. if view_count:
  74. view_count = int_or_none(view_count.replace('.', ''))
  75. average_rating = self._search_regex(
  76. r'itemprop\s*=\s*"ratingValue"[^>]*>\s*(?P<average_rating>[0-9,]+)',
  77. webpage, 'average_rating')
  78. if average_rating:
  79. average_rating = float_or_none(average_rating.replace(',', '.'))
  80. playlist = self._parse_json(
  81. self._search_regex(
  82. r'playlist\s*:\s*\[([^\]]*)\]',
  83. webpage, 'playlist', default='{}'),
  84. display_id, transform_source=fix_json, fatal=False)
  85. video_id = self._search_regex(
  86. r'https?://movies\.gaskrank\.tv/([^-]*?)(-[^\.]*)?\.mp4',
  87. playlist.get('0').get('src'), 'video id')
  88. formats = []
  89. for key in playlist:
  90. formats.append({
  91. 'url': playlist[key]['src'],
  92. 'format_id': key,
  93. 'quality': playlist[key].get('quality')})
  94. self._sort_formats(formats, field_preference=['format_id'])
  95. return {
  96. 'id': video_id,
  97. 'title': title,
  98. 'formats': formats,
  99. 'thumbnail': thumbnail,
  100. 'categories': categories,
  101. 'display_id': display_id,
  102. 'uploader_id': uploader_id,
  103. 'upload_date': upload_date,
  104. 'uploader_url': uploader_url,
  105. 'tags': tags,
  106. 'view_count': view_count,
  107. 'average_rating': average_rating,
  108. }