Beispiel #1
0
 def get_url_data(self, url):
     parsed = urlparse.urlsplit(url)
     if (parsed.scheme in ('http', 'https')
             and parsed.netloc == 'video.google.com'
             and parsed.path == '/videoplay' and 'docid' in parsed.query):
         return {'url': url}
     raise UnhandledVideo(url)
Beispiel #2
0
    def get_video(self, url, fields=None, api_keys=None, require_loaders=True):
        """
        For each registered :mod:`suite <vidscraper.suites>`, calls
        :meth:`~BaseSuite.get_video` with the given ``url``, ``fields``, and
        ``api_keys``, until a suite returns a :class:`.Video` instance.

        :param require_loaders: Changes the behavior if no suite is found
                                which handles the given parameters. If
                                ``True`` (default), :exc:`.UnhandledVideo`
                                will be raised; otherwise, a video will 
                                returned with the given ``url`` and
                                ``fields``, but it will not be able to load
                                any additional data.
        :raises: :exc:`.UnhandledVideo` if ``require_loaders`` is ``True`` and
                 no registered suite returns a video for the given parameters.
        :returns: :class:`.Video` instance with no data loaded.

        """
        for suite in self.suites:
            try:
                return suite.get_video(url, fields=fields, api_keys=api_keys)
            except UnhandledVideo:
                pass

        if require_loaders:
            raise UnhandledVideo(url)

        return Video(url, fields=fields)
Beispiel #3
0
 def get_url_data(self, url):
     parsed_url = urlparse.urlsplit(url)
     if (parsed_url.scheme in ('http', 'https') and
         parsed_url.netloc in ('ustream.tv', 'www.ustream.tv')):
         match = self.path_re.match(parsed_url.path)
         if match:
             return match.groupdict()
     raise UnhandledVideo(url)
    def get_url_data(self, url):
        """
        Parses the url into data which can be used to construct a url this
        loader can use to get data.

        :raises: :exc:`.UnhandledVideo` if the url isn't handled by this
                 loader.

        """
        raise UnhandledVideo(url)
Beispiel #5
0
    def get_video(self, url, fields=None, api_keys=None):
        """
        Returns a video using this suite's loaders. This instance will not
        have data loaded.

        :param url: A video URL. Video website URLs generally work; more
                    obscure urls (like API urls) might work as well.
        :param fields: A list of fields to be fetched for the video. Limiting this
                       may decrease the number of HTTP requests required for
                       loading the video.

                       .. seealso:: :ref:`video-fields`
        :param api_keys: A dictionary of API keys for various services. Check
                         the documentation for each
                         :mod:`suite <vidscraper.suites>` to find what API
                         keys they may want or require.
        :raises: :exc:`.UnhandledVideo` if none of this suite's loaders can
                 handle the given url and api keys.

        """
        # Sanity-check the url.
        if not url:
            raise UnhandledVideo(url)

        loaders = []

        for cls in self.loader_classes:
            try:
                loader = cls(url, api_keys=api_keys)
            except UnhandledVideo:
                continue

            loaders.append(loader)
        if not loaders:
            raise UnhandledVideo(url)
        return Video(url, loaders=loaders, fields=fields)
Beispiel #6
0
 def get_url_data(self, url):
     parsed = urlparse.urlsplit(url)
     if parsed.scheme in ('http', 'https'):
         if (parsed.netloc in ('www.youtube.com', 'youtube.com')
                 and parsed.path in ('/watch', '/watch/')):
             qsd = urlparse.parse_qs(parsed.query)
             try:
                 return {'video_id': qsd['v'][0]}
             except (KeyError, IndexError):
                 pass
         elif parsed.netloc == 'youtu.be':
             match = self.short_path_re.match(parsed.path)
             if match:
                 return match.groupdict()
     raise UnhandledVideo(url)
Beispiel #7
0
 def get_url_data(self, url):
     match = self.path_re.match(url)
     if match:
         return match.groupdict()
     raise UnhandledVideo(url)
Beispiel #8
0
 def get_url_data(self, url):
     if 'ustream_key' not in self.api_keys:
         raise UnhandledVideo(url)
     data = super(ApiLoader, self).get_url_data(url)
     data.update(self.api_keys)
     return data
Beispiel #9
0
 def get_url_data(self, url):
     if not self.is_available():
         raise UnhandledVideo(url)
     return super(AdvancedLoader, self).get_url_data(url)
Beispiel #10
0
 def get_url_data(self, url):
     if not self.video_re.match(url):
         raise UnhandledVideo(url)
     return {'url': url}