def deserialize(cls, data, api_keys=None): """ Given a data dictionary such as would be provided by :meth:`serialize` and, optionally, api keys, constructs a :class:`Video` instance for the url and fields in the data, with field values prepopulated from the dictionary. :param data: A dictionary as would be provided by :meth:`serialize`. :param api_keys: ``None``, or a dictionary of API keys to instantiate the deserialized video with. """ from vidscraper.suites import registry video = registry.get_video(data['url'], fields=data['fields'], api_keys=api_keys, require_loaders=False) dt = data.get('publish_datetime') if dt is not None: data['publish_datetime'] = _isoformat_to_datetime(dt) files = data.get('files') if files is not None: data['files'] = [VideoFile.deserialize(f) for f in files] video._apply(data) return video
def _page_videos(self, response, page_max=None): # Avoid circular imports. from vidscraper.suites import registry items = self.get_response_items(response) self._page_videos_count = 0 for item in items: try: data = self.get_video_data(item) except InvalidVideo: continue url = data['link'] video = registry.get_video(url, fields=self.video_fields, api_keys=self.api_keys, require_loaders=False) video._apply(data) self._page_videos_count += 1 yield video if (page_max is not None and self._page_videos_count >= page_max): break
def auto_scrape(url, fields=None, api_keys=None): """ Returns a :class:`.Video` instance with 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 no :mod:`suite <vidscraper.suites>` can be found which handles the video. """ video = registry.get_video(url, fields=fields, api_keys=api_keys) video.load() return video