def _format_style(self, style_element): attrs = style_element._data.attrib.copy() for (k, v) in iteritems(attrs): # wikipedia suggests that v4 uses b10, while v4+ uses b16 if v.startswith('&H'): attrs[k] = int(v[2:], 16) return self.STYLE_FORMAT.format(**attrs)
def _get_base_params(self): """Get the params that will be included with every request """ base_params = { 'locale': self._get_locale(), 'device_id': ANDROID.DEVICE_ID, 'device_type': ANDROID.APP_PACKAGE, 'access_token': ANDROID.ACCESS_TOKEN, 'version': ANDROID.APP_CODE, } base_params.update(dict((k, v) \ for k, v in iteritems(self._state_params) \ if v is not None)) return base_params
def _get_base_params(self): """ """ base_params = { # these two are required for every request 'device_type': ANDROID_MANGA.DEVICE_TYPE, 'api_ver': ANDROID_MANGA.API_VER, # these are only used for starting the session and should probably # not be in this list 'device_id': ANDROID_MANGA.DEVICE_ID, 'access_token': ANDROID_MANGA.ACCESS_TOKEN, } base_params.update(dict((k, v) \ for k, v in iteritems(self._state_params) \ if v is not None)) return base_params
def get_media_formats(self, media_id): """CR doesn't seem to provide the video_format and video_quality params through any of the APIs so we have to scrape the video page """ url = (SCRAPER.API_URL + 'media-' + media_id).format( protocol=SCRAPER.PROTOCOL_INSECURE) format_pattern = re.compile(SCRAPER.VIDEO.FORMAT_PATTERN) formats = {} for format, param in iteritems(SCRAPER.VIDEO.FORMAT_PARAMS): resp = self._connector.get(url, params={param: '1'}) if not resp.ok: continue try: match = format_pattern.search(resp.content) except TypeError: match = format_pattern.search(resp.text) if match: formats[format] = (int(match.group(1)), int(match.group(2))) return formats
def get_media_formats(self, media_id): """CR doesn't seem to provide the video_format and video_quality params through any of the APIs so we have to scrape the video page """ url = (SCRAPER.API_URL + 'media-' + media_id).format(protocol=SCRAPER.PROTOCOL_INSECURE) format_pattern = re.compile(SCRAPER.VIDEO.FORMAT_PATTERN) formats = {} for format, param in iteritems(SCRAPER.VIDEO.FORMAT_PARAMS): resp = self._connector.get(url, params={param: '1'}) if not resp.ok: continue try: match = format_pattern.search(resp.content) except TypeError: match = format_pattern.search(resp.text) if match: formats[format] = (int(match.group(1)), int(match.group(2))) return formats