#!/usr/bin/env python
# coding=utf8
#
# This file is part of PlayStream - enigma2 plugin to play video streams from various sources
# Copyright (c) 2016 ivars777 (ivars777@gmail.com)
# Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
#
try:
import json
except:
import simplejson as json
import urllib2, urllib
import datetime, re, sys,os
import ConfigParser
from collections import OrderedDict
from SourceBase import SourceBase
import resolver
try:
import util
except:
sys.path.insert(0,'..')
import util
headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
import HTMLParser
h = HTMLParser.HTMLParser()
class Source(SourceBase):
def __init__(self, country=""):
self.name = "movieplace"
self.title = "MoviePlace.lv"
self.img = "http://movieplace.lv/images/logo.png"
self.desc = "Movieplace.lv - filmas latviesu valodā"
self.headers = headers2dict("""
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
""")
self.headers2 = headers2dict("""
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
X-Requested-With: XMLHttpRequest
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
""")
self.url = "http://movieplace.lv/"
######### Entry point ########
def get_content(self, data):
print "[movieplace] get_content:", data
source, data, path, plist, clist, params, qs = self.parse_data(data)
content = []
content.append(("..return", "back","","Return back"))
if clist=="home":
content.extend([
("Meklēt", "movieplace::search/?q={0}","","Meklēt"),
("Jaunākās filmas", "movieplace::load/?page1","","Visu žanru jaunākās filmas"),
("Jaunākie seriāli", "movieplace::dir/?page1","","Visu žanru jaunākās filmas"),
#("Top50 filmas", "movieplace::index/top_50_filmas/0-4","","Top 50 filmas"),
])
r = self.call("load/")
#i = r.find('
Meklēt pēc žanriem
')
#if i<=0:
# return content
i = 0
for item in re.findall('([^>]+)', r[i:]):
title = item[1]
data2 = item[0]+"-1"
img = self.img
desc = title
content.append((title,self.name+"::"+data2,img,desc))
return content
elif clist=="search":
# TODO
r=self.call(data)
result = re.findall(' (.+?) .+?> (.+?)', r, re.DOTALL)
for item in result:
title = item[1].replace("","").replace("","")
data2 = item[0].replace("http://movieplace.lv/","")
img = self.img
desc = item[2].replace("","").replace("","")
content.append((title,self.name+"::"+data2,img,desc))
if '»' in r:
m = re.search("p=(\d+)",data)
if m:
page = int(m.group(1))+1
data2 = re.sub(r"p=\d+", r"p=%s"%page, data)
content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
return content
# Filmu saraksti ##
elif clist in ["load","dir"] and len(plist)<=3:
if clist == "jaunakas":
r = self.call("")
else:
r = self.call(data)
#r = r.decode("cp1251").encode("utf8")
if clist == "load":
result = re.findall(r' .+?([^<]+)
\s+([^<]+)
', r, re.DOTALL)
else:
result = re.findall(r' .+?([^<]+)\s*([^<]+)
', r, re.IGNORECASE | re.DOTALL)
for item in result:
title = item[1]+" [%s]"%item[4] if clist=="load" else item[1]+" / %s [%s]"%(item[3],item[4])
img = "http://movieplace.lv/"+item[2]
data2 = item[0]
desc = "%s\n%s"%(title,item[5]) if clist=="load" else title
content.append((title,self.name+"::"+data2,img,desc))
m = re.search('<[ab] class="swchItemA*1"( href="/([^"]+)" onclick="[^"]+")*>([^<]+)[ab]> ', r, re.DOTALL)
if m:
if m.group(1):
page = int(re.search("\d+$",data).group())
page = page+1
data2 = re.sub("\d$","%s"%page,data)
content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
return content
### Seriāls ###
elif clist=="dir" and len(plist)==4:
r = self.call(path)
title0 = re.search('(.+?)
', r, re.DOTALL).group(1)
m = re.search(r'VALODA: ([^<]+)\s+?SEZONA: ([^<]+)
', r, re.IGNORECASE | re.DOTALL)
if m:
title0 = "%s / Season %s [%s]"%(title0,m.group(2),m.group(1))
desc0 = title0
img0 = "http://movieplace.lv" + re.search('', r, re.DOTALL).group(1)
#TODO
result = re.findall(r'([^<]+)