Example #1
0
	def __init__(self, url='', title='', info='', hashid='', hashstring='', metadata=''):
		global profile_path
		self.url = url
		self.title = title
		self.info = info
		self.metadata=metadata
		print "Haststring %s" % hashstring
		if hashstring:
			hashid = self.gethash(hashstring)

		if not hashid:
			self.hashid = self.gethash(url)
		else:
			self.hashid = hashid

		db_file = os.path.join(xbmc.translatePath(profile_path), 'walter.db')
		sql_path = os.path.join(xbmc.translatePath(profile_path + '/resources/database'), '')
		self.DB = DatabaseClass(db_file, sql_path)
Example #2
0
	def __init__(self):
		global profile_path
		db_file = os.path.join(xbmc.translatePath(profile_path), 'walter.db')
		sql_path = os.path.join(xbmc.translatePath(profile_path + '/resources/database'), '')
		self.DB = DatabaseClass(db_file, sql_path)
Example #3
0
class QueueClass:
	def __init__(self):
		global profile_path
		db_file = os.path.join(xbmc.translatePath(profile_path), 'walter.db')
		sql_path = os.path.join(xbmc.translatePath(profile_path + '/resources/database'), '')
		self.DB = DatabaseClass(db_file, sql_path)

	def queue(self, name, url, src, media='', folder=''):
		print "Adding %s: %s to queue" % (media, name)
		try:
			number = self.DB.query("SELECT count(qid) + 1 FROM wt_download_queue WHERE status=0")
			self.DB.execute("INSERT INTO wt_download_queue(type, description, url, src, folder, num) VALUES(?,?,?,?,?,?)", [media, name, url, src, folder, number[0]])
			self.DB.commit()
			return True
		except:
			return False

	def Cancel(self, qid):
		# Implement Stop command here
		row = self.DB.query("SELECT uuid FROM wt_download_queue WHERE qid=?", [qid])
		uuid = row[0]
		abort_file = os.path.join(xbmc.translatePath(profile_path + 'cache/' + uuid), 'abort')
		fp = open(abort_file, 'w')
		fp.close()
		self.DB.execute("UPDATE wt_download_queue SET status=-1 WHERE qid=?", [qid])
		self.DB.commit()
		xbmc.executebuiltin("Container.Refresh")

	def clearFailed(self):
		self.DB.execute("DELETE FROM wt_download_queue WHERE status=3 or status=-1")
		self.DB.commit()
		return True

	def clearCompleted(self):
		self.DB.execute("UPDATE wt_download_queue SET status=4 WHERE status=2")
		self.DB.commit()
		return True

	def getQueue(self):
		rows = self.DB.query("SELECT * from wt_download_queue WHERE status > -1 AND status < 4 ORDER BY  status, num ASC", force_double_array=True)
		return rows

	def getStatus(self):
		global profile_path
		status = {}
		number = self.DB.query("SELECT count(qid) FROM wt_download_queue WHERE status=0")
		status['length'] = number[0]
		try:
			state_file = os.path.join(xbmc.translatePath(profile_path + 'cache'), 'state.cache')
			fp = open(state_file, 'r')
			data = fp.read().strip()
			fp.close()
			data = data.split('|')
			name = self.DB.query('SELECT * FROM wt_download_queue WHERE qid=?', [data[0]]) 
			status['name'] = name[2]
			
			status['cached'] = data[1]
			status['total'] = data[2]
			status['threads'] = data[3]
		except:
			pass

		return status
		
	def getQuickStatus(self):
		global profile_path
		status = {}
		state_file = os.path.join(xbmc.translatePath(profile_path + 'cache'), 'state.cache')
		fp = fp = open(state_file, 'r')
		data = fp.read().strip()
		fp.close()
		data = data.split('|')
		status['cached'] = int(data[1])
		status['total'] = int(data[2])
		status['percent'] = 100 * status['cached'] / status['total'] 
		return status
Example #4
0
class StreamClass:
	def __init__(self, url='', title='', info='', hashid='', hashstring='', metadata=''):
		global profile_path
		self.url = url
		self.title = title
		self.info = info
		self.metadata=metadata
		print "Haststring %s" % hashstring
		if hashstring:
			hashid = self.gethash(hashstring)

		if not hashid:
			self.hashid = self.gethash(url)
		else:
			self.hashid = hashid

		db_file = os.path.join(xbmc.translatePath(profile_path), 'walter.db')
		sql_path = os.path.join(xbmc.translatePath(profile_path + '/resources/database'), '')
		self.DB = DatabaseClass(db_file, sql_path)

	def gethash(self, string):
		print "Expected Haststring %s" % string
    		m = hashlib.md5()
    		m.update(string.encode('utf-8'))
    		return m.hexdigest()


	def play(self, strm=False):
		global cTime
		global tTime
		wp = WPlayer()
		seekTime = 0
		if not reg.getBoolSetting('enable-pre-caching'):
			try:
				test = self.DB.query("SELECT * FROM wt_player_state WHERE hash=?", [self.hashid])
				if test:
					import datetime, math
					cTime = float(test[2])
					resume = str(datetime.timedelta(seconds= math.floor(cTime)))
					dialog = xbmcgui.Dialog()
					if dialog.yesno("Resume playback?","Do you want to resume playback from: %s" % resume):
						seekTime = cTime	
			except:
				pass

		try:
			description = info['description']
		except:
			description = ''

		try:
			thumb = info['thumb']
		except:
			thumb = ''

		try:
			icon = info['icon']
		except:
			icon = ''
		
		listitem = xbmcgui.ListItem(self.title, iconImage=icon, thumbnailImage=thumb, path=str(self.url))

		listitem.setInfo('video', {'Title': self.title, 'plotoutline': description, 'plot': description, 'Genre': description})
		listitem.setThumbnailImage(thumb)
		listitem.setProperty("IsPlayable", "true")

		
		if reg.getBoolSetting('enable-pre-caching'):
			from mtstreaming import MTStreaming
			MTS = MTStreaming()
			cached_stream = MTS.getCachedStream(self.url)
			self.url = cached_stream
			strm=False	


		wp.play(self.url, listitem, seekTime, strm=strm, metadata=self.metadata)
		currentTime = 0
 		try:
        		tTime = wp.getTotalTime()
    		except Exception:
        		xbmc.sleep(2000)
        	try:
            		tTime = wp.getTotalTime()
        	except Exception, e:
            		print 'Error grabbing video time: %s' % e
            		return False

    		while(True):
        		try:
				tTime = wp.getTotalTime()
            			cTime = wp.getTime()
        		except Exception:
           			break
        		xbmc.sleep(1000)
		try:
    			percent = int(cTime * 100 / tTime )
		except:
			percent = 0
		if percent >= 97:
			self.DB.execute("DELETE FROM wt_player_state WHERE hash=?", [self.hashid])
		else:
			self.DB.execute("REPLACE INTO wt_player_state(hash, current, total, percent) VALUES(?,?,?,?)", [self.hashid, cTime, tTime, percent]) 
		self.DB.commit()