Naar inhoud springen

CampusSearch XBOX Plugin: verschil tussen versies

Uit CampusWiki
Verwijderde inhoud Toegevoegde inhoud
Jase (overleg | bijdragen)
Jase (overleg | bijdragen)
Geen bewerkingssamenvatting
Regel 6: Regel 6:
** Getest op Build 30682 (06-10-2010), nieuwste builds zijn [http://sshcs.com/xbmc/ hier] verkrijgbar.
** Getest op Build 30682 (06-10-2010), nieuwste builds zijn [http://sshcs.com/xbmc/ hier] verkrijgbar.
* FTP access
* FTP access
== Plugin ==
== Installatie ==
De volgende code moet in een file "default.py" gesaved worden. Vervolgens wordt in het sub directory plugins/video/ van XBMC de map "CampusSearch" aangemakt en de default.py daar opgeslagen.
De volgende code moet in een file "default.py" gesaved worden. Vervolgens wordt in het sub directory plugins/video/ van XBMC de map "CampusSearch" aangemakt en de default.py daar opgeslagen.
Op onze xbox ziet het als volgt ui:
Op onze xbox ziet het als volgt eruit:
<pre>E/apps/xbmc/plugins/video/CampusSearch/default.py</pre>
<pre>E/apps/xbmc/plugins/video/CampusSearch/default.py</pre>
== default.py ==
Laatste wijziging''' 07-10-2010 17:31'''
<pre>
import urllib,re,xbmc,xbmcplugin,xbmcgui,os,sys
from xml.dom.minidom import parse

__language__ = xbmc.Language( os.getcwd() ).getLocalizedString

def getResults(film):
notWantedKeywords = ["720p", "1080p", "1080i", "HDDVD", "Bluray", "Blueray"]
unwantedKeywordFound = 0
found = 0
film = film.replace(" ", "+")
filmUrl = "http://search.student.utwente.nl/api/search?q=" + film + "&page=0&dirsonly=no&n=100"
try:
feed = urllib.urlopen(filmUrl)
dom = parse(feed)
except Exception:
message("Could not reach CampusSearch!")
#check through all the <result>
for node in dom.getElementsByTagName('result'):
#only take those which are online!
if node.getElementsByTagName('online')[0].firstChild.nodeValue == 'yes':
# we dont want bluray or any orther HD movie, the xbox cannot play it!
for keyword in notWantedKeywords:
if node.getElementsByTagName('full_path')[0].firstChild.nodeValue.find(keyword) != -1 or node.getElementsByTagName('name')[0].firstChild.nodeValue.find(keyword) != -1:
unwantedKeywordFound = 1
if unwantedKeywordFound == 0:
# okay, everything seems clear, now lets get rid of the directories, we only want the files!
#if node.getElementsByTagName('full_path')[0].firstChild.nodeValue.endswith(".avi") or node.getElementsByTagName('full_path')[0].firstChild.nodeValue.endswith(".mp4"):
addDir(node.getElementsByTagName('name')[0].firstChild.nodeValue, node.getElementsByTagName('full_path')[0].firstChild.nodeValue, '')
found = 1
unwantedKeywordFound = 0;
xbmcplugin.endOfDirectory(int(sys.argv[1]), 1)
if found != 1:
message("nothing found!")

#search for something
def GUIEditExportName(name):
exit = True
while (exit):
kb = xbmc.Keyboard('default', 'heading', True)
kb.setDefault(name)
kb.setHeading(__language__(33223))
kb.setHiddenInput(False)
kb.doModal()
if (kb.isConfirmed()):
name_confirmed = kb.getText()
name = name_confirmed
exit = False
else:
message("nothing entered!")
return(name)
def message(text):
dialog = xbmcgui.Dialog()
dialog.ok("Error", text)

def addDir(name,path,iconimage):
#root level, we only want the files or directories from the search results, not what is inside the folders
if name != '':
isDir = os.path.isdir(path)
liz=xbmcgui.ListItem(name,'')
#os.path.isdir does apparently not work for samba shares, so dirty hack has to be applied :)
#if isDir:
if path[len(path) - 4] != ".":
url = sys.argv[0] + "?path=" + path + "/"
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir)
else:
xbmcplugin.addDirectoryItem(int(sys.argv[1]),path,liz)
else:
# os.listdir also does not work with samba shares, using xbmc httpapi as a workaround
#folderContents = os.listdir(path)
response = xbmc.executehttpapi("GetDirectory(" + path + ")")
# remove <li> tags
response = response.replace("<li>", "")
# we only want the directories and files, so remove the absolute network path
response = response.replace(path, "")
# also "dir/" has to be just "dir"
response = response.replace("/", "")
# first token is a newline, we do not want that
response = response.replace("\n", "", 1)
# we split at each newline, so that we have a list of dirs & files
folderContents = response.split('\n')
for entries in folderContents:
url = os.path.join(path,entries)
#url = path + entries
isDir = os.path.isdir(url)
liz=xbmcgui.ListItem(entries,'')
if isDir:
url = sys.argv[0] + "?path=" + url + "/"
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir)
else:
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz)
xbmcplugin.endOfDirectory(int(sys.argv[1]), 1)
return (0)

#this if will only be true if we want to see the content of a subfolder
if cmp (sys.argv[2][0:6],"?path=") == 0:
addDir('', sys.argv[2][6:], '')
else:
requestedMovie = ""
requestedMovie = GUIEditExportName(requestedMovie)
getResults(requestedMovie)
</pre>

Versie van 7 okt 2010 15:32

Dankzij het CampusSearch XML interface is er nu ook voor een xbox plugin gemaakt, met die je makkelijk vanuit je xbox films kunt zoeken en toevoegen.

Requirements

  • modded xbox
  • XBMC installatie (het XBMC team ondersteunt de xbox niet meer. gelukkig maakt XBMC4XBOX nog verder met het project.
    • Getest op Build 30682 (06-10-2010), nieuwste builds zijn hier verkrijgbar.
  • FTP access

Installatie

De volgende code moet in een file "default.py" gesaved worden. Vervolgens wordt in het sub directory plugins/video/ van XBMC de map "CampusSearch" aangemakt en de default.py daar opgeslagen. Op onze xbox ziet het als volgt eruit:

E/apps/xbmc/plugins/video/CampusSearch/default.py

default.py

Laatste wijziging 07-10-2010 17:31

import urllib,re,xbmc,xbmcplugin,xbmcgui,os,sys
from xml.dom.minidom import parse

__language__ = xbmc.Language( os.getcwd() ).getLocalizedString

def getResults(film):
	notWantedKeywords = ["720p", "1080p", "1080i", "HDDVD", "Bluray", "Blueray"]
	unwantedKeywordFound = 0
	found = 0
	
	film  = film.replace(" ", "+")
	filmUrl = "http://search.student.utwente.nl/api/search?q=" + film + "&page=0&dirsonly=no&n=100"
	try:
		feed = urllib.urlopen(filmUrl)
		dom = parse(feed)	
	except Exception:
		message("Could not reach CampusSearch!")
	#check through all the <result>	
	for node in dom.getElementsByTagName('result'):
		#only take those which are online!
		if node.getElementsByTagName('online')[0].firstChild.nodeValue == 'yes':
			# we dont want bluray or any orther HD movie, the xbox cannot play it!
			for keyword in notWantedKeywords:
				if node.getElementsByTagName('full_path')[0].firstChild.nodeValue.find(keyword) != -1 or node.getElementsByTagName('name')[0].firstChild.nodeValue.find(keyword) != -1:
					unwantedKeywordFound = 1		
			if unwantedKeywordFound == 0:       
				# okay, everything seems clear, now lets get rid of the directories, we only want the files!
				#if node.getElementsByTagName('full_path')[0].firstChild.nodeValue.endswith(".avi") or node.getElementsByTagName('full_path')[0].firstChild.nodeValue.endswith(".mp4"):
				addDir(node.getElementsByTagName('name')[0].firstChild.nodeValue, node.getElementsByTagName('full_path')[0].firstChild.nodeValue, '')
				found = 1
			unwantedKeywordFound = 0;
	xbmcplugin.endOfDirectory(int(sys.argv[1]), 1)			
	if found != 1:
		message("nothing found!")		

#search for something
def GUIEditExportName(name):
	exit = True 
	while (exit):
		kb = xbmc.Keyboard('default', 'heading', True)
		kb.setDefault(name)
		kb.setHeading(__language__(33223))
		kb.setHiddenInput(False)
		kb.doModal()
		if (kb.isConfirmed()):
			name_confirmed  = kb.getText()
			name = name_confirmed
			exit = False
		else:
			message("nothing entered!") 
	return(name)
	
def message(text):
	dialog = xbmcgui.Dialog()
	dialog.ok("Error", text)

def addDir(name,path,iconimage):
	#root level, we only want the files or directories from the search results, not what is inside the folders
	if name != '':
		isDir = os.path.isdir(path)
		liz=xbmcgui.ListItem(name,'')
		#os.path.isdir does apparently not work for samba shares, so dirty hack has to be applied :)
		#if isDir:
		if path[len(path) - 4] != ".":
			url = sys.argv[0] + "?path=" + path + "/"
			xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir)
		else:
			xbmcplugin.addDirectoryItem(int(sys.argv[1]),path,liz)
	else:
		# os.listdir also does not work with samba shares, using xbmc httpapi as a workaround
		#folderContents = os.listdir(path)
		response = xbmc.executehttpapi("GetDirectory(" + path + ")")
		# remove <li> tags
		response = response.replace("<li>", "")
		# we only want the directories and files, so remove the absolute network path
		response = response.replace(path, "")
		# also "dir/" has to be just "dir"
		response = response.replace("/", "")
		# first token is a newline, we do not want that
		response = response.replace("\n", "", 1)
		# we split at each newline, so that we have a list of dirs & files
		folderContents = response.split('\n')
		for entries in folderContents:
			url = os.path.join(path,entries)
			#url = path + entries
			isDir = os.path.isdir(url)
			liz=xbmcgui.ListItem(entries,'')
			if isDir:
				url = sys.argv[0] + "?path=" + url + "/"
				xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir)
			else:
				xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz)
		xbmcplugin.endOfDirectory(int(sys.argv[1]), 1)	
	return (0)

#this if will only be true if we want to see the content of a subfolder
if cmp (sys.argv[2][0:6],"?path=") == 0:
	addDir('', sys.argv[2][6:], '')
else:
	requestedMovie = ""
	requestedMovie = GUIEditExportName(requestedMovie)
	getResults(requestedMovie)