Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
Working again :)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpiva committed Dec 27, 2017
1 parent 35e7a78 commit f27d46f
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions MyAnime.bundle/Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import os
from lxml import etree
import urllib2

import string
import re

TITLE = 'My Anime'
ART_DEFAULT = 'art-default.jpg'
ICON_DEFAULT = 'icon-default.png'
ICON_PREFS = 'Gear.png'
ICON_SEARCH = 'Search.png'
plexhost = 'http://127.0.0.1:32400'

baseproxy = '/video/jmm/proxy'
TokenUsers = { }


Expand Down Expand Up @@ -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'(\<Video.*?\skey=\")(.*?)jmm'
tr = r'\1'+GetHost()+r'\2jmm'
str = re.sub(fr,tr,str)
return str

@handler('/video/jmm', TITLE, art=ART_DEFAULT, thumb=ICON_DEFAULT)
def MainMenu():
try:
if "X-Plex-Product" in Request.Headers:
HTTP.Headers['X-Plex-Product'] = Request.Headers['X-Plex-Product']

HTTP.Headers['Accept'] = 'application/xml'

HTTP.Headers['Accept'] = 'application/xml'
user=GetCurrentPlexUser()
req = HTTP.Request(url= GetServerUrl()+"api/Plex/Filters/"+user,timeout=10)
if req.content:
Response.Headers['Content-type']="text/xml;charset=utf-8"
#return req.content.replace('</MediaContainer>','<Directory prompt="Search" thumb="'+R(ICON_SEARCH)+'" art="'+R(ICON_SEARCH)+'" key="/video/jmm/search" title="Search" search="1"/><Directory title="Preferences" thumb="'+R(ICON_PREFS)+'" art="'+R(ICON_PREFS)+'" key="/:/plugins/com.plexapp.plugins.myanime/prefs" settings="1"/></MediaContainer>')
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')
Expand All @@ -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)
Expand All @@ -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)


####################################################################################################

0 comments on commit f27d46f

Please sign in to comment.