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.

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