2019-06-13 14:27:05 -07:00
|
|
|
import re
|
|
|
|
|
|
|
|
from anime_downloader.extractors.base_extractor import BaseExtractor
|
|
|
|
from anime_downloader.sites import helpers
|
|
|
|
|
|
|
|
|
|
|
|
class Trollvid(BaseExtractor):
|
|
|
|
def _get_data(self):
|
2020-10-03 02:06:56 -07:00
|
|
|
|
2019-06-13 14:27:05 -07:00
|
|
|
# TODO: Provide referer by source
|
|
|
|
referer = 'https://anistream.xyz'
|
|
|
|
|
2020-10-03 02:06:56 -07:00
|
|
|
# The token expires after ~1 minute, making caching error future requests.
|
|
|
|
req = helpers.get(self.url, referer=referer, cache=False)
|
2020-09-17 14:41:34 -07:00
|
|
|
source_regex = r'<source src="(.*?)"'
|
|
|
|
source = re.search(source_regex, req.text)
|
2019-06-13 14:27:05 -07:00
|
|
|
|
2020-09-17 14:41:34 -07:00
|
|
|
# Matches: token="eyJ0eXA"
|
|
|
|
token_regex = r"token\s*=\s*['\"|']([^\"']*)"
|
|
|
|
token = re.search(token_regex, req.text)
|
|
|
|
|
|
|
|
if source:
|
|
|
|
return {
|
|
|
|
'stream_url': source.group()
|
|
|
|
}
|
|
|
|
|
|
|
|
elif token:
|
|
|
|
token = token.group(1)
|
2021-03-25 07:00:39 -07:00
|
|
|
# something like: 084df78d215a
|
|
|
|
trollvid_id = self.url.split('/')[-1]
|
2020-09-17 14:41:34 -07:00
|
|
|
post = helpers.post(f'https://mp4.sh/v/{trollvid_id}',
|
|
|
|
data={'token': token},
|
|
|
|
referer=self.url,
|
|
|
|
).json()
|
|
|
|
|
|
|
|
# {'success':True} on success.
|
2021-03-25 07:00:39 -07:00
|
|
|
if post.get('success') and post.get('file'):
|
2020-09-17 14:41:34 -07:00
|
|
|
return {
|
2021-03-25 07:00:39 -07:00
|
|
|
'stream_url': post['file']
|
2020-09-17 14:41:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
# In case neither methods work.
|
|
|
|
return {'stream_url': ''}
|