summaryrefslogtreecommitdiff
path: root/plugin.video.daserstemediathek/default.py
blob: 0193eaaed481ed6371512936d72b15583c36d778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -*- coding: utf-8 -*-
#"""
import libdaserste

libdaserste.list()
"""


import libDasErste
import utils
import json
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import libMediathek2
__settings__ = xbmcaddon.Addon()
CACHEFILE = xbmc.validatePath(xbmc.translatePath(__settings__.getAddonInfo('profile')+"cache.json"))


def main():
	xbmc.log('#####Main')
	#"#""
	if utils.f_check_existance(CACHEFILE) and 'mode' in params:
		xbmc.log('stub')
		return True
	elif utils.f_check_existance(CACHEFILE):
	"#""
	if utils.f_check_existance(CACHEFILE):
		sub = True
		xbmc.log(str(params))
		#if 'id' in params:
		#	#parsedicts(dProxy)
		#	return play()
		
		dProxy = retrive()
		xbmc.log('retive')
		videoList = dProxy['videoList']
		url = dProxy['next']['url']
		i = len(videoList)# + 1
	else:
		sub = False
		xbmc.log('new')
		url = 'http://www.daserste.de/dasersteapp/app/index~series_serial-beckmannHashtag_types-sendung,sendebeitrag_pageNumber-0.json'
		dProxy = {}
		n = {}
		dProxy['next'] = n
		videoList = []
		i = 0
		
	lvidlist = len(videoList)
		
	l = libDasErste.getVideo(url)
	xbmc.log(str(l))
	for d in l:
		if d['type'] == 'nextPage':
			dProxy['next']['url'] = 'http://www.daserste.de/dasersteapp/app/index~series_serial-beckmannHashtag_types-sendung,sendebeitrag_pageNumber-1.json'
		else:
			d2 = {}
			d2['_name'] = d['name']
			d2['_plot'] = d['plot']
			d2['_thumb'] = d['thumb']
			xbmc.log(d['url'])
			d2['url'] = d['url']
			d2['mode'] = 'play'
			#d2['mode'] = 'main'
			d2['_type'] = 'video'
			#d2['id'] = str(i)
			i += 1
			videoList.append(d2)
	dProxy['next']['url'] = 'http://www.daserste.de/dasersteapp/app/index~series_serial-beckmannHashtag_types-sendung,sendebeitrag_pageNumber-1.json'
	dProxy['videoList'] = videoList
	parsedicts(dProxy)
	write(dProxy)
	return sub,lvidlist
	
"""
"""
def play():
	dProxy = retrive()
	xbmc.log('###########ids')
	xbmc.log(str(len(dProxy['videoList'])))
	xbmc.log(params['id'])
	if len(dProxy['videoList']) < int(params['id']) + 1:
		xbmc.log('#####videostub')
		xbmcplugin.endOfDirectory(int(sys.argv[1]),succeeded=False)	
		#listitem = xbmcgui.ListItem()
		#xbmcplugin.setResolvedUrl(pluginhandle, False, listitem)
		return True"""
"""
def play():
	#dProxy = retrive()
	xbmc.log('##########################play')
	xbmc.log(params['url'])
	vidUrl = libDasErste.getVideoUrl(params['url'])
	#listitem = xbmcgui.ListItem(label='HORRIBLEHACK',path=vidUrl)
	#xbmc.Player().play(vidUrl, listitem)
	#xbmcplugin.endOfDirectory(int(sys.argv[1]),succeeded=False)
	#vidUrl = libDasErste.getVideoUrl(dProxy['videoList'][int(params['id'])]['_url'])
	listitem = xbmcgui.ListItem(path=vidUrl)
	xbmcplugin.setResolvedUrl(pluginhandle, True, listitem)
	return False,False
def parsedicts(dProxy):
	libMediathek2.addEntries(dProxy['videoList'])
	libMediathek2.addEntries([{'_name':'next','_type':'dir','id':str(len(dProxy['videoList'])),'mode':'main'}])
	
def stub():
	l = libDasErste.getVideo('http://www.daserste.de/dasersteapp/app/index~series_serial-beckmannHashtag_types-sendung,sendebeitrag_pageNumber-0.json')
	#xbmc.log()
	
def write(dProxy):
	data = json.dumps(dProxy)
	utils.f_write(CACHEFILE,data)
def add(l):
	l2 = json.loads(utils.f_open(CACHEFILE))
	l = l + l2
	data = json.dumps(l)
	utils.f_write(CACHEFILE,data)
def retrive():
	return json.loads(utils.f_open(CACHEFILE))
	
def list():	
	xbmc.log("xbmc.getInfoLabel('System.CurrentControl')")
	xbmc.log(xbmc.getInfoLabel('System.CurrentControl'))
	modes = {
	'play':play
	}
	global params
	params = libMediathek2.get_params()
	global pluginhandle
	pluginhandle = int(sys.argv[1])
	
	if not params.has_key('mode'):
		isSubfolder,lvidlist = main()
	else:
		isSubfolder,lvidlist = modes.get(params['mode'],main)()
	if isSubfolder:
		xbmcplugin.endOfDirectory(int(sys.argv[1]),updateListing=True,cacheToDisc=True)
	else:
		xbmcplugin.endOfDirectory(int(sys.argv[1]))	
	xbmc.log('##########wnd')
	#wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
	#p = wnd.getControl(wnd.getFocusId()).getSelectedPosition()
	#xbmc.log(str(p)+'#')
	#xbmc.log(xbmc.getInfoLabel('System.CurrentControl'))
	try:
		wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
		wnd.getControl(wnd.getFocusId()).selectItem(0)
		wnd.getControl(wnd.getFocusId()).selectItem(lvidlist+1)
	except: pass
list()
#"""