Last active
January 19, 2022 06:05
-
-
Save zhu327/987f3fc288ca55939e73 to your computer and use it in GitHub Desktop.
XBMC 迅雷云播: 直接通过下载地址推送迅雷云播地址到XBMC上
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 | |
# -*- coding: utf-8 -*- | |
import urllib, urllib2, json | |
RPC_URL = 'http://192.168.1.2/jsonrpc' | |
def pushStream(stream, rpc=RPC_URL): | |
''' | |
Push stream URL to XBMC jsonrpc api, XBMC play the streaming. | |
''' | |
data = { | |
'jsonrpc': '2.0', | |
'method': 'Player.Open', | |
'params':{ | |
'item': { | |
'file': stream | |
} | |
}, | |
'id': '1' | |
} | |
r = urllib2.Request(rpc) | |
r.add_header('Content-type', 'application/json') | |
r.add_data(json.dumps(data)) | |
response = urllib2.urlopen(r) | |
msg = json.loads(response.read()) | |
if msg.get('error'): | |
print "Failed to push %s to XBMC, Message: %s" % (stream, msg.get('error').get('message')) | |
elif msg.get('result') == 'OK': | |
print 'Success to push %s to XBMC.' % stream | |
else: | |
print 'Unknown message %s.' % msg | |
def getStream(url): | |
''' | |
Get xunlei streaming from download url. | |
''' | |
data = urllib.urlencode(dict(url=url)) | |
l = data.split('=') | |
data = '='.join([urllib.quote(x) for x in l]) | |
r = 'http://vod.dychao.com/i/posturl1' | |
response = urllib2.urlopen(r, data) | |
re = response.read().strip() | |
if 'null' in re: | |
raise IOError('No response, check the url.') | |
else: | |
return urllib.unquote(re) | |
if __name__ == '__main__': | |
import sys | |
if len(sys.argv) == 2: | |
url = getStream(sys.argv[1]) | |
pushStream(url) | |
else: | |
print 'Example: python player.py magnet:?xt=...' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment