Last active
May 27, 2021 07:25
-
-
Save Twoure/4c2c100169dfbab4c668 to your computer and use it in GitHub Desktop.
kissanime, kisscartoon, and kissasian have videos hosted on OneDrive. This code returns the raw mp4 file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Kissanime.to, Kisscartoon.me, and Kissasian.com have some videos hosted on OneDrive. | |
The URL's below are examples taken from there pages. | |
You will have to first parse the kiss site video page to get the embeded OneDrive URL. | |
""" | |
from lxml import html | |
import re | |
import json | |
import requests | |
# Star Wars Rebels S2E17 | |
URL='https://onedrive.live.com/prev?cid=6A49079FB0BBA03F&id=6A49079FB0BBA03F!120&authkey=!AOUVAnHG7Iwc-_g&parId=root&view=video&mode=interactiveEmbed' | |
page = requests.get(URL) | |
tree = html.fromstring(page.text) | |
# Pull out the GetItemsLoaderConfing and store info in data dictionary | |
for node in tree.xpath('//script[@type="text/javascript"]'): | |
match = re.search('(?s)GetItemsLoaderConfig\ \=\ (\{.*?\})\;', node.text_content()) | |
if match: | |
test = match.group(1).replace('\n\r', '').strip() | |
for i, s in enumerate(['cid', 'skyApiDomain', 'mkt', 'appId', 'canary', 'oauthToken', 'authKey', 'ticket', 'gb', 'rset']): | |
if i == 0: | |
data = {s: re.search('%s\:\ \'(.*)\'\,' %s, test).group(1)} | |
elif not s == 'rset': | |
data.update({s: re.search('%s\:\ \'(.*)\'\,' %s, test).group(1)}) | |
else: | |
data.update({s: re.search('%s\:\ \'(.*?)\'' %s, test).group(1)}) | |
break | |
# parse parameters in URL | |
uris = URL.split('&') | |
for i, s in enumerate(uris): | |
if i == 0: | |
bs = s.split('?')[1] | |
ss = bs.split('=') | |
a = {ss[0]: ss[1]} | |
else: | |
ns = s.split('=') | |
a.update({ns[0]: ns[1]}) | |
# create the request for the download url | |
dl_url = 'https://onedrive.live.com/GetDownloadUrl/?cid=' + a['cid'] + '&resid=' + a['id'] + '&authkey=' + data['authKey'].decode('unicode-escape') + '&canary=' | |
# setup headers for request | |
h = {'X-Requested-With': 'XMLHttpRequest', 'InvitationToken': data['authKey'].decode('unicode-escape'), 'AppId': data['appId'], 'Accept': 'application/json'} | |
# open download request and parse json data | |
page2 = requests.get(dl_url, headers=h) | |
dl_data = json.loads(page2.text) | |
# remove the download info after .mp4, that way the video will play instead of force downloading | |
PlayVideo = dl_data['DownloadUrl'].split('?')[0] | |
print 'PlayVideo URL = %s' %PlayVideo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment