2013-06-03, 18:35
Scratch that I read the trace wrong. What is the code in your show_names function?
(2013-06-03, 18:35)Bstrdsmkr Wrote: Scratch that I read the trace wrong. What is the code in your show_names function?
@plugin.route('/series/<stype>/<soption>')
def show_names(stype, soption):
page = 1
if soption == 'latest':
page = int(plugin.request.args.get('page', ['1'])[0])
names = scraper.get_latest(page, stype)
elif soption == 'orderby':
page = int(plugin.request.args.get('page', ['1'])[0])
names = scraper.get_orderby(page, stype)
items = []
if page > 1:
previous_page = str(page - 1)
items.append({
'label': '<< %s %s <<' % (_('page'), previous_page),
'thumbnail': scraper.PREV_IMG,
'path': plugin.url_for(
endpoint='show_names',
stype=stype,
soption=soption,
page=previous_page,
update='true'
)
})
next_page = str(page + 1)
items.append({
'label': '>> %s %s >>' % (_('page'), next_page),
'thumbnail': scraper.NEXT_IMG,
'path': plugin.url_for(
endpoint='show_names',
stype=stype,
soption=soption,
page=next_page,
update='true'
)
})
items.extend([{
'label': name['title']+' '+name['statusname']+' Update('+name['lastupdated']+')',
'thumbnail': name['thumb'],
'info': {
'count': i,
'genre': name['genre'],
'year': name['year'],
'episode': name['numberofep'],
'director': name['director'],
'plot': name['plot'],
'plotoutline': name['prodcom'],
'title': name['title'],
'studio': name['studio'],
'writer': name['writer'],
'tvshowtitle': name['title'],
'premiered': name['year'],
'status': name['statusname'],
'trailer': name['trailer']
},
'path': plugin.url_for(
endpoint='show_episodes',
stype=stype,
soption=soption,
name_id=name['id']
)
} for i, name in enumerate(names)])
plugin.set_content('tvshows')
return plugin.finish(items, update_listing=True)
def get_latest(page, stype):
usefull = __get_usefull(stype)
url = usefull['surl'] + '?type=serie&pid=%d&ps=20' % int(page-1)
return _get_names(url)
def _get_names(url):
tree, html = __get_tree(url)
names = []
for item in tree.findAll('item'):
if item.status.string == '0':
item.status.string = '[Soon]'
elif item.status.string == '1':
item.status.string = '[Airing]'
elif item.status.string == '2':
item.status.string = '[Completed]'
names.append({
'id': item.id.string,
'title': item.entitle.string,
'thumb': usefull['poster'] + item.picturename.string,
'genre': item.type.string,
'year': int(item.dateshowtime.string),
'numberofep': int(item.numberofpart.string),
'director': item.director.string,
'plot': item.abstract.string,
'prodcom': item.productioncompany.string,
'studio': item.stationonair.string,
'writer': item.written.string,
'statusname': item.status.string,
'trailer':item.trailer.string,
'lastupdated': item.lastupdated.string
})
log('_get_names got %d item' % len(names))
return names
def __get_tree(url):
log('__get_tree opening url: %s' % url)
req = urllib2.Request(url)
req.add_header('User-Agent', usefull['uagent'])
try:
html = urllib2.urlopen(req).read()
except urllib2.HTTPError, error:
raise NetworkError('HTTPError: %s' % error)
log('__get_tree got %d bytes' % len(html))
tree = BeautifulSoup(html, convertEntities=BeautifulSoup.XML_ENTITIES)
tree
return tree, html
def build_plugin_url(self, queries):
'''
Returns a ``plugin://`` URL which can be used to call the addon with
the specified queries.
Example:
>>> addon.build_plugin_url({'name': 'test', 'type': 'basic'})
'plugin://your.plugin.id/?name=test&type=basic'
Args:
queries (dict): A dctionary of keys/values to be added to the
``plugin://`` URL.
Retuns:
A string containing a fully formed ``plugin://`` URL.
'''
out_dict = {}
for k, v in queries.iteritems():
if isinstance(v, unicode):
v = v.encode('utf8')
elif isinstance(v, str):
# Must be encoded in UTF-8, otherwise, force an error
v.decode('utf8')
out_dict[k] = v
return self.url + '?' + urllib.urlencode(out_dict)
(2013-06-04, 01:01)Bstrdsmkr Wrote: Found it, it was in xbmcswift. Line 64 in urls.py, urllib2.quote_plus() isn't unicode friendly, so each value needs to be encoded to utf-8 (or most any other valid encoding), then the dict can be passed to urllib.urlencode() to get back a valid url query string. This is what I use:I'm very thank you for you adviser, but I didn't get that to use it
Code:def build_plugin_url(self, queries):
'''
Returns a ``plugin://`` URL which can be used to call the addon with
the specified queries.
Example:
>>> addon.build_plugin_url({'name': 'test', 'type': 'basic'})
'plugin://your.plugin.id/?name=test&type=basic'
Args:
queries (dict): A dctionary of keys/values to be added to the
``plugin://`` URL.
Retuns:
A string containing a fully formed ``plugin://`` URL.
'''
out_dict = {}
for k, v in queries.iteritems():
if isinstance(v, unicode):
v = v.encode('utf8')
elif isinstance(v, str):
# Must be encoded in UTF-8, otherwise, force an error
v.decode('utf8')
out_dict[k] = v
return self.url + '?' + urllib.urlencode(out_dict)
@iClosedz, when you pass something in plugin.url_for(), make sure it's encoded to utf-8 and you should be good
def build_plugin_url(self, queries):
out_dict = {}
for k, v in queries.iteritems():
if isinstance(v, unicode):
v = v.encode('utf8')
elif isinstance(v, str):
# Must be encoded in UTF-8, otherwise, force an error
v.decode('utf8')
out_dict[k] = v
return self.url + '?' + urllib.urlencode(out_dict)
def _get_names(url):
tree, html = __get_tree(url)
names = []
for item in tree.findAll('item'):
if item.status.string == '0':
item.status.string = '[Soon]'
elif item.status.string == '1':
item.status.string = '[Airing]'
elif item.status.string == '2':
item.status.string = '[Completed]'
names.append({
'id': item.id.string,
'title': item.entitle.string,
'thumb': usefull['poster'] + item.picturename.string,
'genre': item.type.string,
'year': int(item.dateshowtime.string),
'numberofep': int(item.numberofpart.string),
'director': item.director.string,
'plot': item.abstract.string,
'prodcom': item.productioncompany.string,
'studio': item.stationonair.string,
'writer': item.written.string,
'statusname': item.status.string,
'trailer':item.trailer.string,
'lastupdated': item.lastupdated.string
})
log('_get_names got %d item' % len(names))
return names
(2013-06-04, 14:07)Bstrdsmkr Wrote: Sorry, that function was for Sphere so I could explain what I was getting at. Just GI through your code and make sure any time you call plugin.url_for(), add .encode('utf-8') to the end of each parameter. This is a work around for a bug in Python
@plugin.route('/series/<stype>/<soption>')
def show_names(stype, soption):
page = 1
if soption == 'latest':
page = int(plugin.request.args.get('page', ['1'])[0])
names = scraper.get_latest(page, stype)
elif soption == 'orderby':
page = int(plugin.request.args.get('page', ['1'])[0])
names = scraper.get_orderby(page, stype)
items = []
if page > 1:
previous_page = str(page - 1)
items.append({
'label': '<< %s %s <<' % (_('page'), previous_page),
'thumbnail': scraper.PREV_IMG,
'path': plugin.url_for(
endpoint='show_names',
stype=stype,
soption=soption,
page=previous_page,
update='true'
).encode('utf-8')
})
next_page = str(page + 1)
items.append({
'label': '>> %s %s >>' % (_('page'), next_page),
'thumbnail': scraper.NEXT_IMG,
'path': plugin.url_for(
endpoint='show_names',
stype=stype,
soption=soption,
page=next_page,
update='true'
).encode('utf-8')
})
items.extend([{
'label': name['title']+' '+name['statusname']+' Update('+name['lastupdated']+')',
'thumbnail': name['thumb'],
'info': {
'count': i,
'genre': name['genre'],
'year': name['year'],
'episode': name['numberofep'],
'director': name['director'],
'plot': name['plot'],
'plotoutline': name['prodcom'],
'title': name['title'],
'studio': name['studio'],
'writer': name['writer'],
'tvshowtitle': name['title'],
'premiered': name['year'],
'status': name['statusname'],
'trailer': name['trailer']
},
'path': plugin.url_for(
endpoint='show_episodes',
stype=stype,
soption=soption,
name_id=name['id']
).encode('utf-8')
} for i, name in enumerate(names)])
plugin.set_content('tvshows')
return plugin.finish(items, update_listing=True)
'path': plugin.url_for(
endpoint='show_episodes',
stype=stype,
soption=soption,
name_id=name['id']
).encode('utf-8')
def get_episodes(name_id, stype):
usefull = __get_usefull(stype)
url = usefull['surl'] + '?type=serielink&ps=100&id=%d' % int(name_id)
tree, html = __get_tree(url)
pattern = re.compile("\<Link\>(?P<link>[^\<]*)\<\/Link\>\s*")
total = re.finditer(pattern,html)
bufferr = []
for i in total:
bufferr.append({'source' : i.group('link')})
episodes = []
for item in tree.findAll('item'):
episodes.append({
'title': item.seriename.string,
'part': item.partnumber.string,
'date': item.lastupdated.string
})
count = 0
for i in episodes:
i.update(bufferr[count])
count+=1
log('_get_episodes got %d item' % len(episodes))
print episodes
return episodes
def __get_tree(url):
log('__get_tree opening url: %s' % url)
req = urllib2.Request(url)
req.add_header('User-Agent', usefull['uagent'])
try:
html = urllib2.urlopen(req).read()
except urllib2.HTTPError, error:
raise NetworkError('HTTPError: %s' % error)
log('__get_tree got %d bytes' % len(html))
tree = BeautifulSoup(html, convertEntities=BeautifulSoup.XML_ENTITIES)
return tree, html
if page > 1:
previous_page = str(page - 1)
items.append({
'label': '<< %s %s <<' % (_('page'), previous_page),
'thumbnail': scraper.PREV_IMG,
'path': plugin.url_for(
endpoint='show_names',
stype=stype.encode('utf-8'),
soption=soption.encode('utf-8'),
page=previous_page.encode('utf-8'),
update='true'.encode('utf-8')
)
})
(2013-06-04, 20:05)Bstrdsmkr Wrote: The individual items need to be encoded, like this:
Code:if page > 1:
previous_page = str(page - 1)
items.append({
'label': '<< %s %s <<' % (_('page'), previous_page),
'thumbnail': scraper.PREV_IMG,
'path': plugin.url_for(
endpoint='show_names',
stype=stype.encode('utf-8'),
soption=soption.encode('utf-8'),
page=previous_page.encode('utf-8'),
update='true'.encode('utf-8')
)
})
That's assuming that all those parameters are unicode objects
(2013-06-05, 22:15)olivaar Wrote: i look into the code and into the xml-file that you load.
i think, its not a problem of your addon, its a problem of the xml-file,
because sometimes the first item has some special characters in the field <PartNumber>จบ</PartNumber>
the second and all following items have numbers as partnumber.
and just for joking: the จบ ist not very happy
(i dont know thai, but i search in google for a translation)