2012-10-14, 15:35
hi i am trying to learn python/xbmc programming so i'm trying to modify this onion news addon i made (located here: http://hyper.homeftp.net/xbmc/ ) so it scrapes academic earth.
this code provides a list of web url's. when i clik on one it only gives a '..' in the subdirectory.
i think i want to call urlopen().read, re.finditer(), and addDirectoryItem() for all the courses returned on the selected page but i dont understand how to call those functions in this code.
can someone please provide some pointers ?
Code:
xbmc@XBMCLive:~$ cat /live/image/dotXBMC/addons/schneidz-ae/default.py
'''This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import re
import urllib2
import xbmcgui, xbmcplugin
plugin_handle = int(sys.argv[1])
def parse_subjects(url, infolabels, img=''):
listitem = xbmcgui.ListItem(infolabels['title'], iconImage=img,
thumbnailImage=img)
listitem.setInfo('video', infolabels)
listitem.setProperty('IsPlayable', 'false')
xbmcplugin.addDirectoryItem(plugin_handle, url, listitem, isFolder=True)
html = urllib2.urlopen('http://www.academicearth.org/subjects/engineering/page:1/sort:title/direction:asc/show:500').read()
for v in re.finditer('<a href="(\/courses\/.+?)"><h3>(.+?)<\/h3><\/a>', html):
course, title = v.groups()
if course:
s1 = "http://www.academicearth.org" + course + "/page:1/show:500"
if title:
s2 = title
# print "s1 = ", s1, " s2 = ", s2 #, " date = ", date , " y = ", y, " m = ", m, " d = ", d
parse_subjects('%s' % (s1), {'title': '%s' % (s2), 'aired': '11-11-2010'}, 'http://o.onionstatic.com/img/onn/podcast_300300.jpg')
print " sys.argv[0] = " + sys.argv[0]
print " sys.argv[1] = " + sys.argv[1]
print " sys.argv[2] = " + sys.argv[2]
xbmcplugin.endOfDirectory(plugin_handle)
i think i want to call urlopen().read, re.finditer(), and addDirectoryItem() for all the courses returned on the selected page but i dont understand how to call those functions in this code.
can someone please provide some pointers ?