Пример #1
0
 def __init__(self, with_urlresolver=True):
     self.started = False
     self.urlresolver = False
     lib = os.path.join(home, 'xbmc')
     if os.path.exists(lib):
         if lib in sys.path:
             sys.path.remove(lib)
         sys.path.insert(1, lib)
     try:
         import xbmcinit, xbmc
         __builtin__.xbmcinit = xbmcinit
         __builtin__.xbmc = xbmc
         scrapers.append(self)
     except:
         if self in scrapers: scrapers.remove(self)
         sys.stderr.write('unable to open xbmc\n')
         traceback.print_exc()
     if with_urlresolver:
         try:
             addondir = os.path.join(_special['home'], 'addons',
                                     'script.module.urlresolver')
             id = xbmcinit.read_addon(dir=addondir, full=True)
             sys.path.extend(
                 [p for p in _info[id]['_pythonpath'] if p not in sys.path])
             sys.stderr.write('%s version %s\n' %
                              (_info[id]['name'], _info[id]['version']))
             self.urlresolver = True
         except:
             sys.stderr.write('unable to start xbmc-urlresolver\n')
             traceback.print_exc()
Пример #2
0
	def __init__(self, id=None):
		xid = xbmcinit.read_addon(id)
		if xid is not None:
			self._id = xid
		elif id is None and 'addon_id' in os.environ:
			self._id = xbmcinit.read_addon(os.environ['addon_id'])
		elif id is not None:
			self._id = id
			_info[self._id] = {}
			_settings[self._id] = {}
			_strings[self._id] = {}
		else:
			self._id = _settings[u'_mainid']
		self.info = _info[self._id]
		self.settings = _settings[self._id]
		self.strings = _strings[self._id]
Пример #3
0
	def __init__(self, with_urlresolver=True):
		self.started = False
		self.urlresolver = False
		lib = os.path.join(home, 'xbmc')
		if os.path.exists(lib):
			if lib in sys.path:
				sys.path.remove(lib)
			sys.path.insert(1, lib)
		try:
			import xbmcinit, xbmc
			__builtin__.xbmcinit = xbmcinit
			__builtin__.xbmc = xbmc
			scrapers.append(self)
		except:
			if self in scrapers: scrapers.remove(self)
			sys.stderr.write('unable to open xbmc\n')
			traceback.print_exc()
		if with_urlresolver:
			try:
				addondir = os.path.join(_special['home'], 'addons', 'script.module.urlresolver')
				id = xbmcinit.read_addon(dir=addondir, full=True)
				sys.path.extend([p for p in _info[id]['_pythonpath'] if p not in sys.path])
				sys.stderr.write('%s version %s\n' % (_info[id]['name'], _info[id]['version']))
				self.urlresolver = True
			except:
				sys.stderr.write('unable to start xbmc-urlresolver\n')
				traceback.print_exc()
Пример #4
0
 def __init__(self, id=None):
     xid = xbmcinit.read_addon(id)
     if xid is not None:
         self._id = xid
     elif id is not None:
         self._id = id
         _info[self._id] = {}
         _settings[self._id] = {}
         _strings[self._id] = {}
     else:
         self._id = _settings[u'_mainid']
     self.info = _info[self._id]
     self.settings = _settings[self._id]
     self.strings = _strings[self._id]
Пример #5
0
def addDirectoryItem(handle, url, listitem, isFolder=False, totalItems=None):
	"""Callback function to pass directory contents back to XBMC."""
	if not url:
		return False
	script = argv0
	state = 0
	id = None
	if not isFolder:
		if url.startswith('plugin://'):
			id = xbmcinit.read_addon(urlparse(url).netloc)
			script = os.path.join(_info[id]['path'], _info[id]['_script'])
			state = PMS_UNRESOLVED
		else:
			listitem.setProperty('path', url)
			setResolvedUrl(handle, True, listitem, 0)
			return True
	print "*** addDirectoryItem ***"
	mediatype, name, thumb, mediainfo = resolve(url, listitem, isFolder)
	if id and id in force_resolve:
		mediatype = PMS_FOLDER
	pms.addItem(state|mediatype, pms.esc(name), [script, url], thumb, mediainfo)
	return True
Пример #6
0
def addDirectoryItem(handle, url, listitem, isFolder=False, totalItems=None):
    """Callback function to pass directory contents back to XBMC."""
    if not url:
        return False
    script = argv0
    state = 0
    id = None
    if not isFolder:
        if url.startswith('plugin://'):
            id = xbmcinit.read_addon(urlparse(url).netloc)
            script = os.path.join(_info[id]['path'], _info[id]['_script'])
            state = PMS_UNRESOLVED
        else:
            listitem.setProperty('path', url)
            setResolvedUrl(handle, True, listitem, 0)
            return True
    print "*** addDirectoryItem ***"
    mediatype, name, thumb, mediainfo = resolve(url, listitem, isFolder)
    if id and id in force_resolve:
        mediatype = PMS_FOLDER
    pms.addItem(state | mediatype, pms.esc(name), [script, url], thumb,
                mediainfo)
    return True
Пример #7
0
def setResolvedUrl(handle, succeeded, listitem, stack=-1):
	"""Callback function to tell XBMC that the file plugin has been resolved to a url"""
	if not succeeded:
		return
	
	url = listitem.getProperty('path')
	
	# see xbmc/filesystem/StackDirectory.cpp
	if url.startswith('stack://'):
		ct = 0
		for url in url[8:].split(' , '):
			listitem.setProperty('path', url.replace(',,', ','))
			setResolvedUrl(handle, succeeded, listitem, ct)
			ct += 1
		sys.exit(0)

	name = listitem.getLabel()
	if name == "" or name == None: name = "Item"
	name = name + "" if stack < 1 else " %d" % stack
	
	if url.startswith('rtmp'):
		sargs = []
		args = []
		tups = re.findall(r' ([-\w]+)=(".*?"|\S+)', ' -r=' + url)
		# see xbmc/cores/dvdplayer/DVDInputStreams/DVDInputStreamRTMP.cpp:120
		for key,tag in [
				( "SWFPlayer", "swfUrl"),
				( "PageURL",   "pageUrl"),
				( "PlayPath",  "playpath"),
				( "TcUrl",     "tcUrl"),
				( "IsLive",    "live")
			]:
				try:
					tups.append((tag, listitem.getProperty(key)))
				except KeyError:
					pass
		swfVfy = True if url.lower().replace('=1', '=true').find(" swfvfy=true") > -1 else False
		opts = {
			'swfurl'    : '-W' if swfVfy else '-s',
			'playpath'  : '-y',
			'app'       : '-a',
			'pageurl'   : '-p',
			'tcurl'     : '-t',
			'subscribe' : '-d',
			'live'      : '-v',
			'playlist'  : '-Y'
		}
		for key,val in tups:
			if key.lower() in opts:
				key = opts[key.lower()]
			if val == '1' or val.lower() == 'true':
				if key.lower() != 'swfvfy':
					sargs.append(key)
			else:
				args.append((key,val))
		url = "rtmpdump://rtmp2pms?" + urllib.urlencode(args) + (('&' + '&'.join(sargs)) if len(sargs) else '')
		cmd = "rtmpdump " + ' '.join('%s "%s"' % arg for arg in args) + ' ' + ' '.join(sargs)
		print "test cmd: %s\n" %  cmd

	else:
		url = url.split(' | ')[0]
	
	if url.startswith('plugin://'):
		dir = os.path.dirname(xbmc.translatePath(url.split('?')[0]))
		id, name, script, thumb, path = xbmcinit.read_addon(dir)
		pms.setPath(path)
		url = [script, url]
		media = PMS_UNRESOLVED
	else:
		media = getMediaType(listitem)

	pms.addItem(media, name, url, fullPath(url, listitem.getProperty('thumbnailImage')))
	print "*** setResolvedUrl ***"
	print "raw : %s" % listitem.getProperty('path')
	print "name: %s" % name
	print "type: %d" % media
	print "url :",url

	if stack < 0:
		sys.exit(0)