aboutsummaryrefslogtreecommitdiffhomepage
path: root/youtube_dl/extractor/filmweb.py
blob: a3d9f872ef06b42616ede3d311338ba1ea3e2c72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import unicode_literals

from .twentythreevideo import TwentyThreeVideoIE


class FilmwebIE(TwentyThreeVideoIE):
    IE_NAME = 'Filmweb'
    _VALID_URL = r'https?://(?:www\.)?filmweb\.no/trailere/article(?P<id>\d+).ece'
    _TEST = {
        'url': 'http://www.filmweb.no/trailere/article1264921.ece',
        'md5': 'e353f47df98e557d67edaceda9dece89',
        'info_dict': {
            'id': '1264921',
            'title': 'Det som en gang var',
            'ext': 'mp4',
            'description': 'Trailer: Scener fra et vennskap',
        }
    }

    _CLIENT_NAME = 'filmweb'
    _CLIENT_ID = '12732917'
    _EMBED_BASE_URL = 'http://www.filmweb.no/template/ajax/json_trailerEmbed.jsp?articleId=%s&autoplay=true'

    def _real_extract(self, url):
        article_id = self._match_id(url)
        webpage = self._download_webpage(url, article_id)

        title = self._search_regex(r'var\s+jsTitle\s*=\s*escape\("([^"]+)"\);',
            webpage, 'title', fatal=True)

        format_url = self._proto_relative_url(
            self._html_search_regex(r'"(//filmweb\.23video\.com/[^"]+)"',
                self._download_json(self._EMBED_BASE_URL % article_id,
                    article_id)['embedCode'], 'format url'))

        formats = self._extract_formats(format_url, self._CLIENT_ID)
        self._sort_formats(formats)

        return {
            'id': article_id,
            'title': title,
            'alt_title': self._og_search_title(webpage),
            'formats': formats,
            'description': self._og_search_description(webpage),
        }