[youtube] Fix extraction.
[youtube-dl] / youtube_dl / extractor / biobiochiletv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     ExtractorError,
7     remove_end,
8 )
9
10
11 class BioBioChileTVIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:tv|www)\.biobiochile\.cl/(?:notas|noticias)/(?:[^/]+/)+(?P<id>[^/]+)\.shtml'
13
14     _TESTS = [{
15         'url': 'http://tv.biobiochile.cl/notas/2015/10/21/sobre-camaras-y-camarillas-parlamentarias.shtml',
16         'md5': '26f51f03cf580265defefb4518faec09',
17         'info_dict': {
18             'id': 'sobre-camaras-y-camarillas-parlamentarias',
19             'ext': 'mp4',
20             'title': 'Sobre Cámaras y camarillas parlamentarias',
21             'thumbnail': r're:^https?://.*\.jpg$',
22             'uploader': 'Fernando Atria',
23         },
24         'skip': 'URL expired and redirected to http://www.biobiochile.cl/portada/bbtv/index.html',
25     }, {
26         # different uploader layout
27         'url': 'http://tv.biobiochile.cl/notas/2016/03/18/natalia-valdebenito-repasa-a-diputado-hasbun-paso-a-la-categoria-de-hablar-brutalidades.shtml',
28         'md5': 'edc2e6b58974c46d5b047dea3c539ff3',
29         'info_dict': {
30             'id': 'natalia-valdebenito-repasa-a-diputado-hasbun-paso-a-la-categoria-de-hablar-brutalidades',
31             'ext': 'mp4',
32             'title': 'Natalia Valdebenito repasa a diputado Hasbún: Pasó a la categoría de hablar brutalidades',
33             'thumbnail': r're:^https?://.*\.jpg$',
34             'uploader': 'Piangella Obrador',
35         },
36         'params': {
37             'skip_download': True,
38         },
39         'skip': 'URL expired and redirected to http://www.biobiochile.cl/portada/bbtv/index.html',
40     }, {
41         'url': 'http://www.biobiochile.cl/noticias/bbtv/comentarios-bio-bio/2016/07/08/edecanes-del-congreso-figuras-decorativas-que-le-cuestan-muy-caro-a-los-chilenos.shtml',
42         'info_dict': {
43             'id': 'b4xd0LK3SK',
44             'ext': 'mp4',
45             # TODO: fix url_transparent information overriding
46             # 'uploader': 'Juan Pablo Echenique',
47             'title': 'Comentario Oscar Cáceres',
48         },
49         'params': {
50             # empty m3u8 manifest
51             'skip_download': True,
52         },
53     }, {
54         'url': 'http://tv.biobiochile.cl/notas/2015/10/22/ninos-transexuales-de-quien-es-la-decision.shtml',
55         'only_matching': True,
56     }, {
57         'url': 'http://tv.biobiochile.cl/notas/2015/10/21/exclusivo-hector-pinto-formador-de-chupete-revela-version-del-ex-delantero-albo.shtml',
58         'only_matching': True,
59     }]
60
61     def _real_extract(self, url):
62         video_id = self._match_id(url)
63
64         webpage = self._download_webpage(url, video_id)
65
66         rudo_url = self._search_regex(
67             r'<iframe[^>]+src=(?P<q1>[\'"])(?P<url>(?:https?:)?//rudo\.video/vod/[0-9a-zA-Z]+)(?P=q1)',
68             webpage, 'embed URL', None, group='url')
69         if not rudo_url:
70             raise ExtractorError('No videos found')
71
72         title = remove_end(self._og_search_title(webpage), ' - BioBioChile TV')
73
74         thumbnail = self._og_search_thumbnail(webpage)
75         uploader = self._html_search_regex(
76             r'<a[^>]+href=["\'](?:https?://(?:busca|www)\.biobiochile\.cl)?/(?:lista/)?(?:author|autor)[^>]+>(.+?)</a>',
77             webpage, 'uploader', fatal=False)
78
79         return {
80             '_type': 'url_transparent',
81             'url': rudo_url,
82             'id': video_id,
83             'title': title,
84             'thumbnail': thumbnail,
85             'uploader': uploader,
86         }