diff --git a/MyAnime.bundle/Contents/Code/__init__.py b/MyAnime.bundle/Contents/Code/__init__.py index 1f76410..430fe27 100644 --- a/MyAnime.bundle/Contents/Code/__init__.py +++ b/MyAnime.bundle/Contents/Code/__init__.py @@ -3,7 +3,8 @@ import os from lxml import etree import urllib2 - +import string +import re TITLE = 'My Anime' ART_DEFAULT = 'art-default.jpg' @@ -11,7 +12,7 @@ ICON_PREFS = 'Gear.png' ICON_SEARCH = 'Search.png' plexhost = 'http://127.0.0.1:32400' - +baseproxy = '/video/jmm/proxy' TokenUsers = { } @@ -97,27 +98,33 @@ def GetLimit(): #if JMMServer is at localhost, and Plex Home Theater or other client is outside, and need directplay, this will ensure it gets the right ip for streaming def RedirectUrlIfNeeeded(url): - host = Request.Headers.get('Host', '127.0.0.1:32400') + host = Request.Headers.get('Host', plexhost) host="http://"+host.split(':')[0:][0]+":" if ("http://192.168." in host) or ("http://10." in host) or ("http://172.16." in host) or ("http://172.17." in host) or ("http://172.18." in host) or ("http://172.19." in host) or ("http://172.20." in host) or ("http://172.21." in host) or ("http://172.22." in host) or ("http://172.23." in host) or ("http://172.24." in host) or ("http://172.25." in host) or ("http://172.26." in host) or ("http://172.27." in host) or ("http://172.28." in host) or ("http://172.29." in host) or ("http://172.30." in host) or ("http://172.31." in host): url=url.replace("http://127.0.0.1:",host) url=url.replace("http://localhost:",host) return url - +def GetHost(): + host = Request.Headers.get('Host', plexhost) + host="http://"+host.split(':')[0:][0]+":32400" + return host +def ReplaceBaseUrl(str): + fr = r'(\','') - return req.content + return req.content else: Log("My Anime Url: "+ GetServerUrl()+"api/Plex/Filters/"+user+" returns empty, check if the user has categories assigned"); oc = ObjectContainer(title2='My Anime') @@ -134,6 +141,7 @@ def MainMenu(): @route('/video/jmm/getsearchurl') def GetSearchUrl(): return GetServerUrl()+"api/Plex/Search/"+GetCurrentPlexUser()+"/"+GetLimit() + @route('/video/jmm/search') def Search(query): Log("Inside Search"+query) @@ -142,13 +150,20 @@ def Search(query): return req.content @route('/video/jmm/proxy/{url}', allow_sync=True) -def Proxy(url,includeExtras='0',includeRelated='0',includeRelatedCount='0',checkFiles='1',includeConcerts='1',includeOnDeck='1',includePopularLeaves='1',includeChapters='1',includeBandwidths='0'): +def Proxy(url,includeExtras='0',includeRelated='0',includeRelatedCount='0',checkFiles='0',includeConcerts='1',includeOnDeck='1',includePopularLeaves='1',includeChapters='1',includeBandwidths='0',offset='0'): url = url.decode("hex") Response.Headers['Content-type']="text/xml;charset=utf-8" - url = RedirectUrlIfNeeeded(url); - req = HTTP.Request(url=url,timeout=240) - return req.content - - + url = RedirectUrlIfNeeeded(url) + req = HTTP.Request(url=url,timeout=240) + plexproduct='none' + if "X-Plex-Product" in Request.Headers: + plexproduct = Request.Headers['X-Plex-Product'] + Log("Product: "+plexproduct) + if ((plexproduct.find("Web")) or (plexproduct.find("Android"))): + if (checkFiles=='1'): + return ReplaceBaseUrl(req.content) + return req.content; + return ReplaceBaseUrl(req.content) + ####################################################################################################