]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gaskrank.py
debian/copyright: Update my copyright years.
[youtubedl] / youtube_dl / extractor / gaskrank.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 from .common import InfoExtractor
6 from ..utils import (
7 float_or_none,
8 int_or_none,
9 unified_strdate,
10 )
11
12
13 class GaskrankIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?gaskrank\.tv/tv/(?P<categories>[^/]+)/(?P<id>[^/]+)\.htm'
15 _TESTS = [{
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 'url': 'http://www.gaskrank.tv/tv/racing/isle-of-man-tt-2011-michael-du-15920.htm',
31 'md5': 'c33ee32c711bc6c8224bfcbe62b23095',
32 'info_dict': {
33 'id': '201106/15920',
34 'ext': 'mp4',
35 'title': 'Isle of Man - Michael Dunlop vs Guy Martin - schwindelig kucken',
36 'thumbnail': r're:^https?://.*\.jpg$',
37 'categories': ['racing'],
38 'display_id': 'isle-of-man-tt-2011-michael-du-15920',
39 'uploader_id': 'IOM',
40 'upload_date': '20170523',
41 'uploader_url': 'www.iomtt.com',
42 }
43 }]
44
45 def _real_extract(self, url):
46 display_id = self._match_id(url)
47
48 webpage = self._download_webpage(url, display_id)
49
50 title = self._og_search_title(
51 webpage, default=None) or self._html_search_meta(
52 'title', webpage, fatal=True)
53
54 categories = [re.match(self._VALID_URL, url).group('categories')]
55
56 mobj = re.search(
57 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])',
58 webpage)
59 if mobj is not None:
60 uploader_id = mobj.groupdict().get('uploader_id')
61 upload_date = unified_strdate(mobj.groupdict().get('upload_date'))
62
63 uploader_url = self._search_regex(
64 r'Homepage:\s*<[^>]*>(?P<uploader_url>[^<]*)',
65 webpage, 'uploader_url', default=None)
66 tags = re.findall(
67 r'/tv/tags/[^/]+/"\s*>(?P<tag>[^<]*?)<',
68 webpage)
69
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
76 average_rating = self._search_regex(
77 r'itemprop\s*=\s*"ratingValue"[^>]*>\s*(?P<average_rating>[0-9,]+)',
78 webpage, 'average_rating')
79 if average_rating:
80 average_rating = float_or_none(average_rating.replace(',', '.'))
81
82 video_id = self._search_regex(
83 r'https?://movies\.gaskrank\.tv/([^-]*?)(-[^\.]*)?\.mp4',
84 webpage, 'video id', default=display_id)
85
86 entry = self._parse_html5_media_entries(url, webpage, video_id)[0]
87 entry.update({
88 'id': video_id,
89 'title': title,
90 'categories': categories,
91 'display_id': display_id,
92 'uploader_id': uploader_id,
93 'upload_date': upload_date,
94 'uploader_url': uploader_url,
95 'tags': tags,
96 'view_count': view_count,
97 'average_rating': average_rating,
98 })
99 self._sort_formats(entry['formats'])
100
101 return entry