Nowy addon dla TVP VOD

1 wpis / 0 new
ksox
Offline
Dołączył: 28/12/2020 - 14:18
Wpisy: 1
Nowy addon dla TVP VOD

Dear sd-xbmc developers,

Thank you very much for the plugins. It is really good and useful. Unfortunately the current version of do not show all series avaliable. See for example http://sd-xbmc.org/pl/comment/6189#comment-6189

Some small changes in the file and it can show all the series that available.

Thank you!

# -*- coding: utf-8 -*-
import sdLog, sdParser, sdCommon, sdNavigation, sdErrors
import xbmcplugin, xbmcgui, xbmcaddon, xbmc, traceback
import os, sys, urllib, re, math, time

if sys.version_info >= (2,7): import json as _json
else: import simplejson as _json

scriptID = sys.modules[ "__main__" ].scriptID
scriptname = sys.modules[ "__main__" ].scriptname
ptv = xbmcaddon.Addon(scriptID)

log = sdLog.pLog()
urlList = 'http://www.api.v3.tvp.pl/shared/listing.php?dump=json&direct=true&parent...{parent_id}&count={count}&page={page}'
urlCategoryList = 'http://www.api.v3.tvp.pl/shared/listing.php?dump=json&direct=true&count=...

urlAudycje = 'http://www.api.v3.tvp.pl/shared/listing.php?dump=json&direct=true&count=...
urlRecommended = 'http://www.api.v3.tvp.pl/shared/listing.php?parent_id=%d&direct=false&co...
#urlEpisodesList = 'http://www.api.v3.tvp.pl/shared/listing.php?parent_id=%d&direct=false&co...
urlEpisodesList = 'http://www.api.v3.tvp.pl/shared/listing.php?parent_id=%d&count=%d&page=%d'

#urlVideo = 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%d&mime_type=video/mp4'
#urlVideo = 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%d'
urlVideo = 'http://www.tvp.pl/shared/cdn/tokenizer_v2.php?object_id=%d'
urlImage = 'http://s.v3.tvp.pl/images/%s/%s/%s/uid_%s_width_%d_gs_0.jpg'

USER_AGENT = 'Apache-HttpClient/UNAVAILABLE (java 1.4)'
VOD_ID = 6442748
VOD_LIST_ID = 2919829
FORMATS = {"video/mp4":"mp4"}

VOD_START_ID = 1785454
PAGE_MOVIES = 100
CAT_NAMES = {"directory_series", "website", "directory_video"}
VID_NAMES = {"video"}
#ptv.getSetting('tvp_perpage')
proxy = ptv.getSetting('tvp_proxy')
videoQuality = ptv.getSetting('tvp_quality')

HANDLE = int(sys.argv[1])

class tvpvod:
mode = 0
__settings__ = xbmcaddon.Addon(sys.modules[ "__main__" ].scriptID)

def __init__(self):
log.info("Starting TVP.VOD")
self.cm = sdCommon.common()
self.proxy = sdCommon.proxy()
self.parser = sdParser.Parser()
self.exception = sdErrors.Exception()
self.gui = sdNavigation.sdGUI()

def listsVOD(self, id, page):
url = urlList.format(parent_id = int(id), count=int(PAGE_MOVIES), page=page)
log.info(url)
result = _json.loads(self.getRequest(url))
items = result.get('items', {})
totalCount = result.get('total_count')

if totalCount == 0:
return

xbmcplugin.setContent(HANDLE, 'videos')
itemsCount = len(items)
items.sort(key=lambda x: x.get("position", -1000))
for item in items:
if "video" in item.get("types",[]):
self.parseVideo(item, itemsCount)
elif item.get("object_type") in CAT_NAMES:
self.parseCategory(item, itemsCount)

if totalCount > page*PAGE_MOVIES:
self.addNextPage(page)
xbmcplugin.endOfDirectory(HANDLE)

def addDir(self,name,action,actionId,iconimage):
u = sys.argv[0]+"?mode="+self.mode+"&name="+urllib.quote_plus(name)+"&category="+urllib.quote_plus(self.category)+"&action="+urllib.quote_plus(action)+"&actionid="+urllib.quote_plus(str(actionId))
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setProperty( "Folder", "true" )
ok=xbmcplugin.addDirectoryItem(handle=HANDLE,url=u,listitem=liz,isFolder=True)
return ok

def addVideoLink(self,prop,url,iconimage,listsize=0):
ok=True
if not 'description' in prop:
prop['description'] = ''
if not 'time' in prop:
prop['time'] = 0
if not 'aired' in prop:
prop['aired'] = ''
if not 'overlay' in prop:
prop['overlay'] = 0
if not 'TVShowTitle' in prop:
prop['TVShowTitle'] = ''
if not 'episode' in prop:
prop['episode'] = 0

liz=xbmcgui.ListItem(prop['title'], iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setProperty("IsPlayable", "true")
liz.setInfo( type="Video", infoLabels={
"Title": prop['title'],
"Plot": prop['description'],
"Duration": str(prop['time']),
"Premiered": prop['aired'],
"Overlay": prop['overlay'],
"TVShowTitle" : prop['TVShowTitle'],
"Episode" : int(prop['episode'])
} )

u = sys.argv[0]+"?mode="+self.mode+"&name="+urllib.quote_plus(prop['title'])+"&category="+urllib.quote_plus(self.category)+"&page="+str(self.page)+"&action=play_video&videoid="+urllib.quote_plus(url)
ok=xbmcplugin.addDirectoryItem(handle=HANDLE,url=u,listitem=liz,isFolder=False,totalItems=listsize)
return ok

def addNextPage(self, page):
if not page:
page = 0

u = sys.argv[0]+"?mode="+self.mode+"&name="+urllib.quote_plus(self.name)+"&category="+urllib.quote_plus(self.category)+"&page="+str(page+1)+"&action="+urllib.quote_plus(self.action)+"&actionid="+urllib.quote_plus(str(self.actionid))
ok=True
image = os.path.join( self.__settings__.getAddonInfo('path'), "images/" ) + "dalej.png"

liz=xbmcgui.ListItem("Następna", iconImage="DefaultFolder.png", thumbnailImage=image)
liz.setProperty( "Folder", "true" )
ok=xbmcplugin.addDirectoryItem(handle=HANDLE,url=u,listitem=liz,isFolder=True)
return ok

def getRequest(self, url):
try:
log.info('URL: ' + url)
result = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
except Exception, exception:
traceback.print_exc()
self.exception.getError(str(exception))
exit()
return result

def getVideoUrl(self, id):
result = self.getRequest(urlVideo % (int(id)))
videoInfo = _json.loads(result)
return videoInfo['video_url']

def getVideoLink(self, asset_id):
url = 'http://www.tvp.pl/shared/cdn/tokenizer_v2.php?object_id=' + asset_id
if proxy == 'true':
url = self.proxy.useProxy(url)
try:
data = self.cm.getURLRequestData({ 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
except Exception, exception:
traceback.print_exc()
self.exception.getError(str(exception))
exit()
videoTab = []
data = _json.loads( data )

if (isinstance(data['formats'],list)):
for item in data['formats']:
if item['mimeType'] == 'unknown':
return item['url']
if item['mimeType'] in FORMATS.keys():
videoTab.append( {'bitrate': str(item['totalBitrate']), 'url' : item['url'].encode('utf-8') })
videoTab.sort(key = lambda x: int(x['bitrate']), reverse=True)
videoUrl = videoTab[0]['url']

if videoQuality == 'Niska': videoUrl = videoTab[-1]['url']
if videoQuality == 'Wysoka': videoUrl = videoTab[0]['url']
if videoQuality == 'Średnia':
length = len(videoTab)
i = int(math.ceil(float(length/2)))
videoUrl = videoTab[i]['url']
else:
videoUrl = data['formats']['url']

if proxy == 'true':
try:
data = self.cm.getURLRequestData({ 'url': self.proxy.useProxy(videoUrl), 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True })
except Exception, exception:
traceback.print_exc()
self.exception.getError(str(exception))
exit()
videoUrl = data

return videoUrl

def playVideo(self, id):
videoUrl = self.getVideoLink(id)
#if proxy == 'true':
# videoUrl = self.getRequest(self.proxy.useProxy(videoUrl))
self.gui.LOAD_AND_PLAY_VIDEO(videoUrl, self.name)

def parseVideo(self, item,itemsCount):
playMode = 0
if "play_mode" in item:
playMode = item["play_mode"]

if not playMode:
return

if "paymethod" in item: # filter out paid content ( 208 = ABO )
payMethod = item["paymethod"]
if payMethod != 0:
return

prop = {
'title' : '',
'TVShowTitle': self.name,
'episode': 0,
'description': '',
'time': 0,
'aired': item['release_date_dt'].encode('utf-8'),
'overlay' : 0,
}

if 'title_root' in item:
prop['title'] = item['title_root'].encode('utf-8')
else:
prop['title'] = item['website_title'].encode('utf-8') + " " + item['title'].encode('utf-8')

if 'duration' in item and int(item['duration']):
prop['time'] = int(item['duration'])/60
if 'duration_min' in item and int(item['duration_min']):
prop['time'] = int(item['duration_min'])
if 'description_root' in item:
prop['description'] = item['description_root'].encode('utf-8')
iconUrl = self.getImageUrl(item)
self.addVideoLink(prop,str(item['_id']),iconUrl,itemsCount)

def parseCategory(self, item, itemsCount):
iconUrl = self.getImageUrl(item)
self.addDir(item["title"].encode('utf-8'),"list_category",item["asset_id"],iconUrl)

def getImageUrl(self, item):
iconUrl = ""

if 'image' in item:
iconFile = item['image'][0]['file_name'].encode('utf-8')
iconWidth = item['image'][0]['width']
if iconWidth > 0:
iconUrl = urlImage %(iconFile[0],iconFile[1],iconFile[2],iconFile[:-4],iconWidth)

if iconUrl == '' and 'image_4x3' in item:
iconFile = item['image_4x3'][0]['file_name'].encode('utf-8')
iconWidth = item['image_4x3'][0]['width']
if iconWidth > 0:
iconUrl = urlImage %(iconFile[0],iconFile[1],iconFile[2],iconFile[:-4],iconWidth)

if iconUrl == '' and 'image_ns644' in item:
iconFile = item['image_ns644'][0]['file_name'].encode('utf-8')
iconWidth = item['image_ns644'][0]['width']
if iconWidth > 0:
iconUrl = urlImage %(iconFile[0],iconFile[1],iconFile[2],iconFile[:-4],iconWidth)

if iconUrl == '' and 'image_ns954' in item:
iconFile = item['image_ns954'][0]['file_name'].encode('utf-8')
iconWidth = item['image_ns954'][0]['width']
if iconWidth > 0:
iconUrl = urlImage %(iconFile[0],iconFile[1],iconFile[2],iconFile[:-4],iconWidth)
return iconUrl

def handleService(self):
params = self.parser.getParams()
self.name = str(self.parser.getParam(params, "name"))
self.title = str(self.parser.getParam(params, "title"))
self.category = str(self.parser.getParam(params, "category"))
self.url = str(self.parser.getParam(params, "url"))
self.mode = str(self.parser.getParam(params, "mode"))
self.page = self.parser.getParam(params, "page")
self.action = str(self.parser.getParam(params, "action"))
self.videoid = str(self.parser.getParam(params, "videoid"))
self.actionid = str(self.parser.getParam(params, "actionid"))

if not self.page:
self.page = 1
else:
self.page = int(self.page)

if self.action == 'None':
log.info("VOD Categories")
self.listsVOD(VOD_START_ID, self.page)
elif self.action == 'list_category' and self.actionid != '':
self.listsVOD(self.actionid, self.page)
elif self.action == 'play_video' and self.videoid != '':
log.info("Play video: " + self.videoid)
self.playVideo(self.videoid)

Aktywne serwisy


 
to wyjątkowy zbiór filmów dokumentalnych, fabularnych, seriali i audycji telewizyjnych w internecie
internetowa aplikacja telewizyjna Ipla należąca do Cyfrowego Polsatu
Przegapiłeś swój ulubiony program na antenie TVN, TVN Style czy TVN Turbo? W tvn player nie zabraknie najpopularniejszych programów i show z kanałów

WSPÓŁPRACA

mods-kodi.pl

Informacje

Copyright © 2013 – 2021 SD-XBMC
All rights reserved www.sd-xbmc.org