Example #1
0
	def guideDataDetails(self, data, idx, max_idx, url):
	
		# try to break, if we have to
		if self.IS_RUNNING == False:
			return
				
		if data:
			# a robot does not sleep, but we do, sometimes
			if not idx % 3:
				time.sleep(0.3)
			#time.sleep(0.1)
			
			msg_log = "[skyrecorder] get url {0} for idx {1}/{2}".format(url, idx + 1, max_idx + 1)
			print msg_log
			self.addLog(msg_log)
			
			my_db_dict = None
			my_db_dict = {}
			details = None
			#data = decodeHtml(data).encode('utf-8')
			details = json.loads(data)
			
			handlung = details['detailTxt'] or ""
			handlung = str(decodeHtml(str(handlung)))
			my_db_dict.update({"handlung":handlung})
			
			image = details['imageUrl'] or "/bin/EPGEvent/web/event_default.png"
			image = self.SKY_GO_BASE + str(image)
			my_db_dict.update({"image":image})
			
			# get the special infos, such as id_hd or is serie
			is_hd = details['techIcons']['hd'] or 0
			my_db_dict.update({"is_hd":is_hd})
			
			is_169 = 1 # no field: details['techIcons']['hd']
			my_db_dict.update({"is_169":is_169})
			
			is_dolby = details['techIcons']['sound'] or 0
			my_db_dict.update({"is_dolby":is_dolby})
			
			is_dualch = details['techIcons']['multiLang'] or 0
			my_db_dict.update({"is_dualch":is_dualch})
			
			is_serie = details['techIcons']['serie'] or 0
			my_db_dict.update({"is_serie":is_serie})
			
			if int(is_serie) == 1 and int(self.tv_guide_list[idx]["id_genre"]) == 49:
				self.tv_guide_list[idx].update({"id_genre":2})
			
			is_ut = details['techIcons']['ut'] or 0
			my_db_dict.update({"is_ut":is_ut})
			
			is_last = details['techIcons']['lastChance'] or 0
			my_db_dict.update({"is_last":is_last})
			
			is_3d = details['techIcons']['v3d'] or 0
			my_db_dict.update({"is_3d":is_3d})
			
			self.tv_guide_list[idx].update(my_db_dict)
			
			try:
				del(my_db_dict)
			except Exception:
				sys.exc_clear()
			
			# we are done? start database update for this entry
			self.addToDatabase(self.tv_guide_list[idx], idx, max_idx)
		
		# got this day, see if we want more
		if idx == max_idx:
			time.sleep(1)
			# debug me
			#with open("/tmp/tv_guide_list.txt" , "w") as f:
			#	for e in self.tv_guide_list:
			#		f.write(repr(e) + "\n")
			#self.callDatabaseUpdate()
			
			try:
				del(self.tv_guide_list)
			except Exception:
				sys.exc_clear()
			
			if self.cur_pagenr < self.maxpage:
				self.startGuideDownload()
			else:
				self.IS_RUNNING = False
				self.checkDone("Datenbank aktualisiert", set_stamp = True)
Example #2
0
	def guideData(self, data):
		
		#data = decodeHtml(data).encode('utf-8')
		info = json.loads(data)
		if not info:
			msg_log = "ERROR: could not get TV-Guide"
			print msg_log
			self.addLog(msg_log)
			self.IS_RUNNING = False
			return
		msg_log = "[skyrecorder] Daten erhalten"
		print msg_log
		self.addLog(msg_log)
		
		# debug me
		#with open("/tmp/guide_data_base.txt" , "w") as f:
		#	f.write(str(info))
		
		msg_log = "[skyrecorder] lade Tag {0} von {1}".format(self.cur_pagenr, self.maxpage)
		print msg_log
		self.addLog(msg_log)
		
		self.cur_channels = None
		self.cur_channels = 0
		self.max_channels = None
		self.max_channels = len(info)
		
		for channel_id in info:
			self.cur_channels += 1
			
			# try to break, if we want so
			if self.IS_RUNNING == False:
				return
			
			msg_log = "[skyrecorder] lade Sender {0} von {1}".format(self.cur_channels, self.max_channels)
			print msg_log
			self.addLog(msg_log)
		
			eventnumber = 0
			maxevents = len(info[channel_id])
			if maxevents == 0:
				continue 
			
			id_channel = None
			channel = None
			channel = self.SkyStations[int(channel_id)]
			if not channel or channel == "":
				continue
			id_channel = sql.getIdChannel(channel,stb=False)
			if not id_channel:
				msg_log = "[skyrecorder] channel not found: {0}".format(channel)
				print msg_log
				self.addLog(msg_log)
				continue
			msg_log = "[skyrecorder] trying channel: {0}".format(channel)
			print msg_log
			self.addLog(msg_log)
			
			if maxevents > 1:
				maxevents = maxevents-1
			for n in range(0, maxevents):
				eventnumber += 1
				
				msg_log = "[skyrecorder] lade Sendung {0} von {1}".format(eventnumber, maxevents)
				print msg_log
				self.addLog(msg_log)
				
				my_db_dict = None
				my_db_dict = {}
				
				my_db_dict.update({"id_channel":id_channel})
				
				title = info[channel_id][n]["title"] or ""
				if title == "":
					continue
				title = str(decodeHtml(str(title)))
				my_db_dict.update({"title":title})
				
				description = info[channel_id][n]["subtitle"] or ""
				description = str(decodeHtml(str(description)))
				my_db_dict.update({"description":description})
				
				is_new = info[channel_id][n]["isNew"] or 0
				if config.plugins.skyrecorder.only_new_events and config.plugins.skyrecorder.only_new_events.value:
					if int(is_new) == 0:
						# second check, because only the first broadcast termin isNew.
						# But what, if we want the others as well?
						if not self.tv_guide_list or len(self.tv_guide_list) < 1:
							check = None
						else:
							check = next((item for item in self.tv_guide_list if item["id_channel"] == id_channel and item["title"] == title and item["description"] == description), None)
						if not check:
							# not in this day dict, but mabye in our database?
							if not sql.existEventGuideIsNew(title, description, id_channel):
								continue
						# we got an item in our list of dicts - remark the current event as new
						is_new = 1
				my_db_dict.update({"is_new":is_new})
				
				id_genre = None
				if description and description != "":
					id_genre = sql.getIdGenre(description)
				if not id_genre:
					id_genre = 49 # 49 = - (Sonstige)
				my_db_dict.update({"id_genre":id_genre})
				
				datum = info[channel_id][n]["startDate"] #startDate = 06.03.2013
				datum = str(datum)
				my_db_dict.update({"datum":datum})
				#endDate = 06.03.2013
				
				live = info[channel_id][n]["live"] or 0
				my_db_dict.update({"live":live})
				#length = 115
				
				highlight = info[channel_id][n]["highlight"] or 0
				my_db_dict.update({"highlight":highlight})
				
				starttime = info[channel_id][n]["startTime"]
				starttime = str(starttime)
				my_db_dict.update({"starttime":starttime})
				
				
				endtime = info[channel_id][n]["endTime"]
				endtime = str(endtime)
				my_db_dict.update({"endtime":endtime})
				
				# check if we can skip this broadcast date
				tstamp_start = self.unixtime(datum, starttime)
				tstamp_end = self.unixtime(datum, endtime)
				skytime = self.skyTimeStamp(starttime, tstamp_start, tstamp_end)
				
				# we will check this later
				#if self.check_time > skytime[0]:
				#	continue
				
				sky_id = info[channel_id][n]["id"] or "0"
				sky_id = str(sky_id)
				my_db_dict.update({"sky_id":sky_id})
				
				if not sky_id or sky_id == "0":
					self.addLog("no sky id found")
					continue
				my_url = "http://www.skygo.sky.de/epgd/web/eventDetail/" + sky_id + "/" + str(channel_id) + "/"
				my_db_dict.update({"details_url":my_url})
				
				# update our guide list
				self.tv_guide_list.append(my_db_dict)
				
				try:
					del(my_db_dict)
				except Exception:
					sys.exc_clear()
		
		# now get the event details
		if self.tv_guide_list and len(self.tv_guide_list) != 0:
			self.getGuideDetails()
		else:
			self.startGuideDownload()