Exemplo n.º 1
0
def recordings_dir():


	# First check if the recording list is refreshed within two minutes and load it only if it's not
	if int(time.time())- last_refresh > (listagelimit *60):
		dnatv = DNATVSession(username, password, servicename)
		if dnatv.login():
			recordings = dnatv.getrecordings()
			if recordings is None:
				xbmc.executebuiltin('XBMC.Notification(' + settings.getLocalizedString(30055) + ', )')
				sys.exit()
			settings.setSetting( id='lastRecordingsRefresh', value=str(int(time.time())))
			settings.setSetting( id='recordingList', value=json.dumps(recordings))

	else:
		recordings = json.loads(settings.getSetting( id='recordingList'))

	seriescandidates = []
	recordtitles = []
	serieslist = []
	title_re = re.compile('[:(]')
	
	for recording in recordings:
		short_title = title_re.split(recording['title'])[0].strip()
		try:
			if not recording['recordings'][0]['status'] == 'RECORDED':
				continue
		except IndexError:
			continue
		if short_title in serieslist:
			continue
		if short_title in recordtitles:
			serieslist.append(short_title)
			continue
		else:
			recordtitles.append(short_title)
			seriescandidates.append(recording)

	serieslist.sort()
	settings.setSetting( id='seriestitles', value=json.dumps(serieslist))
	existingfolders = []
	series = False

	for recording in seriescandidates:
		series = False
		for seriestitle in serieslist:
			if re.match(seriestitle + r'\b',recording['title']):
					if not seriestitle in existingfolders:
						existingfolders.append(seriestitle)
						url = build_url({'foldername': serieslist.index(seriestitle)})
						li = build_li(recording, True, seriestitle)
						xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)
					series = True
					break
#			if re.match(seriestitle + r'\s',recording['title']):
#					if not seriestitle in existingfolders:
#						existingfolders.append(seriestitle)
#						url = build_url({'foldername': serieslist.index(seriestitle)})
#						li = build_li(recording, True, seriestitle)
#						xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)
#					series = True
#					break

		if not series:
			url = build_url({'mode': 'watch', 'videoUrl': recording['recordings'][1]['stream']['streamUrl']})
			li = build_li(recording, False)
			xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=False)

	xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
	xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
	xbmcplugin.endOfDirectory(addon_handle)
Exemplo n.º 2
0
def recordings_dir():

	# First check if the recording list is refreshed within two minutes and load it only if it's not
	isnewlist = False

	if int(time.time())- last_refresh > 120:
		isnewlist = True
		dnatv = DNATVSession(username, password, servicename)
		if dnatv.login():
			recordings = dnatv.getrecordings()
			settings.setSetting( id='lastRecordingsRefresh', value=str(int(time.time())))
			settings.setSetting( id='recordingList', value=json.dumps(recordings))

	else:
		recordings = json.loads(settings.getSetting( id='recordingList'))

	recordtitles = []
	serieslist = []
	title_re = re.compile('[:(]')
	
	for recording in recordings:
		short_title = title_re.split(recording['title'])[0].strip()
		if short_title in serieslist:
			continue
		if short_title in recordtitles:
			serieslist.append(short_title)
		else:
			recordtitles.append(short_title)
	serieslist = set(serieslist)
	removable = set()
	for i in serieslist:
		for j in serieslist:
			if j.startswith(i+' ') and (i != j):
				removable.add(j)

	serieslist = list(serieslist.difference(removable))
	existingfolders = []

	settings.setSetting( id='seriestitles', value=json.dumps(serieslist))
	for recording in recordings:
		try:
			if not recording['recordings'][0]['status'] == 'RECORDED':
				continue
		except IndexError:
			continue
		groupmember = False
		for seriestitle in serieslist:
			myregex = seriestitle + r'\b'
			if re.match(myregex,recording['title']):

				if not seriestitle in existingfolders:
					existingfolders.append(seriestitle)
					url = build_url({'foldername': serieslist.index(seriestitle)})
					li = build_li(recording, True, seriestitle)
					xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)
				recording['series'] = seriestitle
				groupmember = True
		if groupmember:
			continue
		url = build_url({'mode': 'watch', 'videoUrl': recording['recordings'][1]['stream']['streamUrl']})
		li = build_li(recording, False)
		xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=False)

	if isnewlist:
		settings.setSetting( id='recordingList', value=json.dumps(recordings))
	xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
	xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
	xbmcplugin.endOfDirectory(addon_handle)