From 7ca701dc492e3e99c3ad7a419ba1bafdf01f0932 Mon Sep 17 00:00:00 2001 From: MusterGit Date: Mon, 31 Oct 2011 15:12:41 +0100 Subject: [PATCH] Added plugin Stream2k Added test entries in default.py --- plugin.video.t0mm0.test/default.py | 10 +-- .../lib/urlresolver/plugins/stream2k.py | 70 +++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 script.module.urlresolver/lib/urlresolver/plugins/stream2k.py diff --git a/plugin.video.t0mm0.test/default.py b/plugin.video.t0mm0.test/default.py index 7eca787..b040107 100644 --- a/plugin.video.t0mm0.test/default.py +++ b/plugin.video.t0mm0.test/default.py @@ -46,13 +46,15 @@ urlresolver.display_settings() elif mode == 'test': + addon.add_video_item({'url': 'http://server4.stream2k.com/playerjw/vConfig56.php?vkey=1d8dc00940da661ffba9'}, + {'title': 'stream2k url'}) + addon.add_video_item({'host': 'stream2k', 'media_id': '1d8dc00940da661ffba9'}, + {'title': 'stream2k media id'}) addon.add_video_item({'url': 'http://www.ecostream.tv/stream/b83c3c5d07b1ab195fb8245576c27daa.html?' + 'width=679&height=365&bGetRedirectUrl=False&sFileName=Larry+Crowne'}, - {'title': 'ecostream url'} - ) + {'title': 'ecostream url'}) addon.add_video_item({'host': 'ecostream', 'media_id': 'b83c3c5d07b1ab195fb8245576c27daa'}, - {'title': 'ecostream media id'} - ) + {'title': 'ecostream media id'}) addon.add_video_item({'url': 'http://www.2gb-hosting.com/v/94fb733db6e9f984b07da3cb238eb277/2074fe10f41c7e1.flv.html'}, {'title': '2gbhosting url'}) addon.add_video_item({'host': '2gb-hosting.com', 'media_id': 'e1593e96e19f7ecced3778668e809c77/efc5d03968fbca6.avi.html'}, diff --git a/script.module.urlresolver/lib/urlresolver/plugins/stream2k.py b/script.module.urlresolver/lib/urlresolver/plugins/stream2k.py new file mode 100644 index 0000000..3d0e1f4 --- /dev/null +++ b/script.module.urlresolver/lib/urlresolver/plugins/stream2k.py @@ -0,0 +1,70 @@ +""" + urlresolver XBMC Addon + Copyright (C) 2011 t0mm0 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" + +from t0mm0.common.net import Net +from urlresolver.plugnplay.interfaces import UrlResolver +from urlresolver.plugnplay.interfaces import PluginSettings +from urlresolver.plugnplay import Plugin +import re +import random +import urllib2 +from urlresolver import common + +class Stream2kResolver(Plugin, UrlResolver, PluginSettings): + implements = [UrlResolver, PluginSettings] + name = "stream2k" + + def __init__(self): + p = self.get_setting('priority') or 100 + self.priority = int(p) + self.net = Net() + # e.g. http://server4.stream2k.com/playerjw/vConfig56.php?vkey=1d8dc00940da661ffba9 + self.pattern ='http://([^/]*stream2k.com)/[^"]+vkey=([0-9A-Za-z]+)' + + def get_media_url(self, host, media_id): + web_url = self.get_url(host, media_id) + + try: + html = self.net.http_GET(web_url).content + except urllib2.URLError, e: + common.addon.log_error(self.name + ': got http error %d fetching %s' % + (e.code, api_url)) + sPattern = "(.*?)" + + # get stream url + r = re.search(sPattern, html, re.DOTALL + re.IGNORECASE) + if r: + return r.group(1) + + return False + + def get_url(self, host, media_id): + serverNum = random.randint(2,15) + url = 'http://server' + str(serverNum) + \ + '.stream2k.com/playerjw/vConfig56.php?vkey=%s' % (media_id) + return url + + def get_host_and_id(self, url): + r = re.search(self.pattern, url) + if r: + return r.groups() + else: + return False + + def valid_url(self, url, host): + return re.match(self.pattern, url) or self.name in host