2019-02-11 05:03:32 -08:00
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
from anime_downloader.extractors.base_extractor import BaseExtractor
|
2019-03-22 06:47:00 -07:00
|
|
|
from anime_downloader.sites import helpers
|
2019-02-11 05:03:32 -08:00
|
|
|
|
2019-03-22 06:47:00 -07:00
|
|
|
logger = logging.getLogger(__name__)
|
2019-02-11 05:03:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
class Kwik(BaseExtractor):
|
2019-03-22 06:47:00 -07:00
|
|
|
'''Extracts video url from kwik pages, Kwik has some `security`
|
2019-02-11 05:03:32 -08:00
|
|
|
which allows to access kwik pages when only refered by something
|
2019-03-22 06:47:00 -07:00
|
|
|
and the kwik video stream when refered through the corresponding
|
2019-02-11 05:03:32 -08:00
|
|
|
kwik video page.
|
|
|
|
'''
|
2019-03-22 06:47:00 -07:00
|
|
|
|
2019-02-11 05:03:32 -08:00
|
|
|
def _get_data(self):
|
|
|
|
|
2019-03-22 06:47:00 -07:00
|
|
|
# Need a javascript deobsufication api/python, so someone smarter
|
|
|
|
# than me can work on that for now I will add the pattern I observed
|
|
|
|
|
|
|
|
# alternatively you can pattern match on `src` for stream_url part
|
2019-02-14 12:25:08 -08:00
|
|
|
source_parts_re = re.compile(r'action=\"([^"]+)\".*value=\"([^"]+)\".*Click Here to Download',
|
2019-03-22 06:47:00 -07:00
|
|
|
re.DOTALL)
|
|
|
|
|
|
|
|
# Kwik servers don't have direct link access you need to be referred
|
|
|
|
# from somewhere, I will just use the url itself.
|
|
|
|
|
|
|
|
download_url = self.url.replace('kwik.cx/e/', 'kwik.cx/f/')
|
|
|
|
|
|
|
|
kwik_text = helpers.get(download_url, referer=download_url).text
|
|
|
|
post_url, token = source_parts_re.search(kwik_text).group(1, 2)
|
|
|
|
|
|
|
|
stream_url = helpers.post(post_url,
|
|
|
|
referer=download_url,
|
|
|
|
data={'_token': token},
|
|
|
|
allow_redirects=False).headers['Location']
|
|
|
|
|
|
|
|
title = stream_url.rsplit('/', 1)[-1].rsplit('.', 1)[0]
|
|
|
|
|
|
|
|
logger.debug('Stream URL: %s' % stream_url)
|
2019-02-11 05:03:32 -08:00
|
|
|
return {
|
|
|
|
'stream_url': stream_url,
|
|
|
|
'meta': {
|
|
|
|
'title': title,
|
|
|
|
'thumbnail': ''
|
|
|
|
},
|
2019-02-14 12:25:08 -08:00
|
|
|
'referer': None
|
2019-02-11 05:03:32 -08:00
|
|
|
}
|