Exemplo n.º 1
0
    def list(self, url, page):
        """ List all episodes for a series.
        https://www.npo.nl/media/series/VPWON_1247337/episodes?page=2&tilemapping=dedicated&tiletype=asset
        """

        raise download_npo.Error('Dit werkt momenteel niet. Sorry :-(')

        if url.startswith('http://') or url.startswith('https://'):
            series_id = re.search(r'([A-Z][A-Z_]{1,8}_\d{6,9})').groups()[1]
        else:
            series_id = url

        url = 'http://www.npo.nl/media/series/{}/episodes'.format(url)

        if not url.endswith('/episodes'):
            url += '/episodes'
        url += '?tilemapping=dedicated&tiletype=asset&page={}'.format(page)
        p = self.get_page(url)

        matches = re.findall(
            r'id=["\']([A-Z][A-Z_]{1,8}_\d{6,9})["\'].*?alt=["\'](.*?)["\'] onerror',
            p, re.DOTALL | re.MULTILINE)

        ret = []
        for m in matches:
            i = m[0].split('/').pop()
            ret.append((i, 'http://{}'.format(i, m[0]), m[1].strip()))
        return ret
Exemplo n.º 2
0
    def urlopen(self, url):  # pylint:disable=no-self-use
        """ Open a URI; return urllib.request.Request object """
        if download_npo.verbose:
            msg('urlopen: ' + url)

        headers = {
            'User-Agent':
            'Mozilla/5.0 (X11; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0',
            'Cookie': 'npo_cc=tmp; npo_cc_www.npogeschiedenis.nl=tmp',
        }
        req = urllib2.Request(url, headers=headers)
        try:
            return urllib2.urlopen(req)
        except urllib2.HTTPError:
            raise download_npo.Error(
                'De URL {} is niet gevonden (404 error)'.format(url))
Exemplo n.º 3
0
    def __init__(self, url):
        self.libmms = ctypes.cdll.LoadLibrary(ctypes.util.find_library('mms'))
        if self.libmms._name is None:  # pylint:disable=protected-access
            raise download_npo.Error(
                'Deze video is in het (oude) MMS/WMV formaat; om dit te'
                'downloaden heb je libmms nodig, welke niet is gevonden op je'
                'systeem. Zie: http://sourceforge.net/projects/libmms/')

        self._libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c'))

        mmsh_connect = self.libmms.mmsh_connect
        mmsh_connect.restype = ctypes.POINTER(mmsh_t)

        if sys.version_info[0] > 2:
            url = bytes(url, 'utf-8')

        self._mms = mmsh_connect(None, None, url, 128 * 1024)

        malloc = self._libc.malloc
        malloc.restype = ctypes.POINTER(ctypes.c_char)
        self.buf = malloc(8192)
Exemplo n.º 4
0
    def find_video(self, url, quality=0):
        """ Find video to download
        Returns (downloadurl, pagetitle, player_id, extension)"""
        if not (url.startswith('http://') or url.startswith('https://')):
            url = 'http://%s' % url

        page = self.get_page(url)
        try:
            jsurl = re.search(r'data-url="(.*?)"', page).groups()[0]
            player_id = re.search(r'sourceid_string:(\d+)', jsurl).groups()[0]
        except AttributeError:
            raise download_npo.Error('Kan player_id niet vinden')

        meta = self.meta(player_id)

        streams = meta['clipData']['assets']
        streams.sort(key=lambda v: int(v['bandwidth']), reverse=True)
        url = streams[0]['src']

        return self.urlopen(url), meta['clipData'].get(
            'title'), player_id, 'mp4'
Exemplo n.º 5
0
    def find_video(self, url, quality=0):
        """ Find video to download
            Returns (downloadurl, player_id, extension)"""

        if not (url.startswith('http://') or url.startswith('https://')):
            url = 'http://www.npostart.nl/{}'.format(url)

        page = self.get_page(url)
        page = unquote(page)

        if download_npo.verbose >= 3:
            msg('page: {}'.format(page))

        player_id = None
        find = re.search(self._playerid_regex, page)
        if download_npo.verbose >= 2:
            msg('player_id find: {}'.format(find))
        if find is not None and len(find.groups()) > 0:
            player_id = find.groups()[0]
        if player_id is None:
            raise download_npo.Error('Kan player_id niet vinden')
        if download_npo.verbose:
            msg('Using player_id {}'.format(player_id))

        # {"token":"h4i536f2104v7aepeonjm83s51"}
        try:
            token = json.loads(self.get_page('{}/auth'.format(
                self.base)))['token']
        except AttributeError:
            raise download_npo.Error('Kan token niet vinden')
        if download_npo.verbose:
            msg('Found token ' + token)

        meta = self.meta(player_id)
        if meta.get('error') and len(meta['error']) > 1:
            raise download_npo.Error(
                'Site geeft aan dat er iets fout is: {}'.format(meta['error']))

        ext = 'mp4'
        if meta.get('items') and isinstance(meta['items'][0][0], dict):
            # Radiouitendingen
            ext = (meta['items'][0][0].get('type')
                   or meta['items'][0][0].get('format') or 'mp4')

            # MMS / Windows Media Speler
            if meta['items'][0][0].get('formaat') == 'wmv':
                return self.find_video_MMS(player_id)

        # http://ida.omroep.nl/app.php/POW_03414349?adaptive=no&token=djo0nv08rdk46iq7kijrvtktr3
        streams = self.get_json('{}/{}?adaptive=no&token={}'.format(
            self.base, player_id, token))

        url = None
        errors = set()
        for q, stream in enumerate(streams['items'][0][quality:]):
            # Oudere afleveringen; zie #10
            if stream.get('contentType') in ('url', 'audio'):
                url = stream['url']
                if stream.get('format'):
                    ext = stream.get('format')
                break
            else:
                stream = self.get_json(stream['url'])
                if stream.get('errorstring'):
                    # Dit is vooral voor regionale afleveringen (lijkt het ...)
                    if meta.get('items') and len(meta['items'][0]) > 0:
                        url = meta['items'][0][0]['url']
                        break
                    else:
                        errors.add(stream.get('errorstring'))
                else:
                    url = stream['url']
                    break

        if url is None:
            raise download_npo.Error("Foutmelding van site:\n{}".format(
                '\n'.join(['\n'.join(textwrap.wrap(e)) for e in errors])))

        return (self.urlopen(url), player_id, ext)
Exemplo n.º 6
0
 def list(self, url, page):
     raise download_npo.Error('Dit is niet ondersteund voor deze site')
Exemplo n.º 7
0
 def subs(self, player_id):
     raise download_npo.Error('Deze site ondersteunt geen ondertitels')
Exemplo n.º 8
0
 def meta(self, player_id):
     raise download_npo.Error('Not implemented')
Exemplo n.º 9
0
 def find_video(self, url, quality=0):
     raise download_npo.Error('Not implemented')