View Full Version : stickam plugin - help wanted
u=sys.argv[0]+"?mode=2&name="+urllib.quote_plus('get_cat')+"&url="+urll
ib.quote_plus(query)+"&thumb="+urllib.quote_plus(os.path.join(THUMBNAIL
_PATH, 'search_users.png'))
xbmcplugin.addDirectoryItem(int(sys.argv[1]),u,li,False)
def removeB(name,url):
type = 'presets_' + url
presets = xbmcplugin.getSetting( type )
save = presets.split( " | " )
del save[save.index(name)]
sets = ''
x=0
for item in save:
if x == 0:
sets = sets + item
else:
sets = sets + ' | ' + item
x=x+1
xbmcplugin.setSetting(type, sets)
xbmc.executebuiltin( "Container.Refresh" )
def editB(name,url):
type = 'presets_' + url
presets = xbmcplugin.getSetting( type )
save = presets.split( " | " )
del save[save.index(name)]
x=0
for item in save:
if x == 0:
sets = item
else:
sets = sets + ' | ' + item
x=x+1
searchStr = name
keyboard = xbmc.Keyboard(searchStr, "Edit user name")
keyboard.doModal()
if (keyboard.isConfirmed() == False):
return
searchstring = keyboard.getText()
newStr = searchstring
if len(newStr) == 0:
return
if len(save) == 0:
sets = newStr
else:
sets = sets + ' | ' + newStr
xbmcplugin.setSetting(type, sets)
xbmc.executebuiltin( "Container.Refresh" )
def runKeyboard3():
searchStr = ''
keyboard = xbmc.Keyboard(searchStr, "Enter the exact user
name")
keyboard.doModal()
if (keyboard.isConfirmed() == False):
return
searchstring = keyboard.getText()
newStr = searchstring.replace(' ','+')
if len(newStr) == 0:
return
presets = xbmcplugin.getSetting( "presets_users" )
if presets == '':
save_str = newStr
else:
save_str = presets + " | " + newStr
xbmcplugin.setSetting("presets_users", save_str)
if len(newStr) != 0:
thumb = xbmc.getInfoImage( "ListItem.Thumb" )
playVideo(newStr, 'get_cat', thumb)
def get_thumbnail(thumbnail_url):
try:
filename = xbmc.getCacheThumbName( thumbnail_url )
filepath =xbmc.translatePath( os.path.join(
BASE_CACHE_PATH, filename[ 0 ], filename ) )
if not os.path.isfile( filepath ):
info = urlretrieve( thumbnail_url, filepath )
urlcleanup()
return filepath
except:
print "Error: get_thumbnail()"
return thumbnail_url
def playVideo(url, name, thumb):
vid='http://www.stickam.com/liveStream.do?filter=popularity&category=al
l' + url + '.xml'
print vid
try:
req = urllib2.Request(vid)
req.add_header('User-Agent', HEADER)
f=urllib2.urlopen(req)
except HTTPError, e:
dialog = xbmcgui.Dialog()
ok = dialog.ok('Stickam_Live_Cams', 'Error: Invalid
user or not a live feed.')
xbmc.executebuiltin( "Container.Refresh" )
return
a=f.read()
f.close()
data=re.compile('<play>(.+?)</play><connect>(.+?)</connect>').findall(a
)
if len(data) == 0:
dialog = xbmcgui.Dialog()
ok = dialog.ok('Stickam_Live_Cams', 'Error: Invalid
user or not a live feed.')
xbmc.executebuiltin( "Container.Refresh" )
return
playpath = data[0][0]
rtmp_url = data[0][1]
swf='http://www.stickam.com/meta/'+url+'.xml'
print swf
req = urllib2.Request(swf)
req.add_header('User-Agent', HEADER)
f=urllib2.urlopen(req)
a=f.read()
f.close()
data2=re.compile('SWFObject\(\'(.+?)\',').findall( a)
data4=re.compile('<status>(.+?)</status>').findall(a)
data5=re.compile('<translated_category>(.*?)</translated_category>').fi
ndall(a)
data6=re.compile('<translated_subcategory>(.*?)</translated_subcategory
>').findall(a)
data7=re.compile('<screen_cap>(.*?)</screen_cap>').findall(a)
if name == 'get_cat':
thumb = get_thumbnail(data7[0])
name = clean(data5[0] + ' / ' + data6[0])
referer = 'http://www.stickam.com/'+url
SWFPlayer = data2[0]
if (len(data4) == 0):
title = 'Stickacm_Live_Cams'
else:
title = clean(data4[0])
match=re.compile('&#(.+?);').findall(title)
for trash in match:
title=title.replace('&#'+trash+';','')
item =
xbmcgui.ListItem(label=title,iconImage="DefaultVideo.png",thumbnailImag
e=thumb)
item.setInfo( type="Video", infoLabels={ "Title": title,
"Director": url, "Studio": url, "Genre": name } )
item.setProperty("SWFPlayer", SWFPlayer)
item.setProperty("PlayPath", playpath)
item.setProperty("PageURL", referer)
xbmc.Player(xbmc.PLAYER_CORE_DVDPLAYER).play(rtmp_ url, item)
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
params=get_params()
mode=None
name=None
url=None
page=1
try:
url=urllib.unquote_plus(params["url"])
except:
pass
try:
name=urllib.unquote_plus(params["name"])
except:
pass
try:
mode=int(params["mode"])
except:
pass
try:
page=int(params["page"])
except:
pass
try:
thumb=urllib.unquote_plus(params["thumb"])
except:
pass
if mode==None:
temp_dir()
_check_for_update()
_check_compatible()
name=''
showCategories()
elif mode==0:
showSubCategories(url, name)
elif mode==1:
showLinks(url, name)
elif mode==2:
playVideo(url, name, thumb)
elif mode==3:
runKeyboard()
elif mode==4:
name=''
runSearch(url)
elif mode==5:
runKeyboard2()
elif mode==6:
name=''
runKeyboard3()
elif mode==7:
removeB(name,url)
elif mode==8:
editB(name,url)
elif mode==9:
name=''
runKeyboard4()
xbmcplugin.setPluginCategory(int(sys.argv[1]), name )
xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ),
sortMethod=xbmcplugin.SORT_METHOD_LABEL )
xbmcplugin.endOfDirectory(int(sys.argv[1]))
__scriptname__ = "Stickam_Live_Cams"
__date__ = '2009-07-29'
__version__ = "1.4.9"
__XBMC_Revision__ = "21803"
import xbmc, xbmcgui, xbmcplugin, urllib2, urllib, re, string, sys, os,
traceback, shutil
from urllib2 import Request, urlopen, URLError, HTTPError
from urllib import urlretrieve, urlcleanup
HEADER = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10)
Gecko/2009042316 Firefox/3.0.10'
THUMBNAIL_PATH = os.path.join(os.getcwd().replace( ";", ""
),'resources','media')
BASE_CACHE_PATH = os.path.join( xbmc.translatePath( "special://temp/"
), "Stickam_Live_Cams" )
def temp_dir():
if os.path.isdir(BASE_CACHE_PATH):
shutil.rmtree(BASE_CACHE_PATH)
os.mkdir(BASE_CACHE_PATH)
dir = "0123456789abcdef"
for path in dir:
new = os.path.join( xbmc.translatePath(
"special://temp/" ), "Stickam_Live_Cams", path )
os.mkdir(new)
def showCategories():
if xbmcplugin.getSetting('language') == '0':
idd = 'en'
elif xbmcplugin.getSetting('language') == '1':
idd = 'en'
url='http://www.stickam.com/'
req = urllib2.Request(url)
req.add_header('User-Agent', HEADER)
f=urllib2.urlopen(req)
a=f.read()
f.close()
match=re.compile('<ul class="fp_categories">(.+?)<div
id="FPTakeoverSkinv2_holder">', re.DOTALL).findall(a)
cat=re.compile('<a
href="(.+?)"><b>(.+?)</b></a>').findall(match[0])
name = 'All'
url='http://www.stickam.com/liveStream.do?category=social&filter=featur
ed'+idd
li=xbmcgui.ListItem(name)
u=sys.argv[0]+"?mode=1&name="+urllib.quote_plus(name)+"&url="+urllib.qu
ote_plus(url)
xbmcplugin.addDirectoryItem(int(sys.argv[1]),u,li,True)
for url,name in cat:
new=url.replace('/directory','/directory/dropmenu/subcategory')
url='http://www.stickam.com/liveStream.do?category=social&filter=featur
ed'+idd
li=xbmcgui.ListItem(name)
u=sys.argv[0]+"?mode=0&name="+urllib.quote_plus(name)+"&url="+urllib.qu
ote_plus(url)
xbmcplugin.addDirectoryItem(int(sys.argv[1]),u,li,True)
li=xbmcgui.ListItem('(Search)',iconImage="DefaultVideo.png",
thumbnailImage=os.path.join(THUMBNAIL_PATH, 'search_icon.png'))
u=sys.argv[0]+"?mode=3&name="+urllib.quote_plus('(Search)')
xbmcplugin.addDirectoryItem(int(sys.argv[1]),u,li,True)
li=xbmcgui.ListItem('(User
Search)',iconImage="DefaultVideo.png",
thumbnailImage=os.path.join(THUMBNAIL_PATH, 'search_icon.png'))
u=sys.argv[0]+"?mode=5&name="+urllib.quote_plus('(User
Search)')
xbmcplugin.addDirectoryItem(int(sys.argv[1]),u,li,True)
def showSubCategories(url, name):
cat_name=name
req = urllib2.Request(url)
req.add_header('User-Agent', HEADER)
f=urllib2.urlopen(req)
a=f.read()
f.close()
cat=re.compile('<li class="subcategory"><a
href="(.+?)">(.+?)</a></li>').findall(a)
for url,name in cat:
url='http://www.stickam.com' + url
li=xbmcgui.ListItem(name)
u=sys.argv[0]+"?mode=1&name="+urllib.quote_plus(cat_name+' /
'+name)+"&url="+urllib.quote_plus(url)
xbmcplugin.addDirectoryItem(int(sys.argv[1]),u,li,True)
def showLinks(url, name):
url=url.replace('kind=live&','')
cat_name=name
thisurl=url
req = urllib2.Request(url+'&page='+str(int(page)))
req.add_header('User-Agent', HEADER)
f=urllib2.urlopen(req)
a=f.read()
f.close()
match=re.compile('<ul class="channel_list li_grid
clearfix">(.+?)<div id="pagelinks" class="pagelinks clear">',
re.DOTALL).findall(a)
if len(match) == 0:
dialog = xbmcgui.Dialog()
ok = dialog.ok('Stickam_Live_Cams', 'Error: No live
streams available.')
showCategories()
return
cat=re.compile('<a href="(.+?)"
class="title">(.+?)</a>').findall(match[0])
data=re.compile('<img alt="" class="cap lateload" src1="(.+?)"
src').findall(match[0])
stat1=re.compile('<span class="overlay
viewers_count">(.+?)</span>').findall(match[0])
stat2=re.compile('<span class="small">on <a
href="(.+?)">(.+?)</a></span>').findall(match[0])
x=0
for url,title in cat:
url=url.replace('/','')
name=str(int(x+1)+(36*(page-1)))+') '+clean(title)+'
on '+clean(stat2[x][1])+' - '+stat1[x]
thumb = get_thumbnail(data[x])
li=xbmcgui.ListItem(name, iconImage=thumb,
thumbnailImage=thumb)
rwparris2
2009-09-13, 06:06
http://pastebin.com !!
Or at least code tags around your code
If you don't do it right, our spam filters won't let you post.
Leo Leporte is on Stickam.com, and everyone (I think) enjoys watching people act ignorent once in a while. Is there a way to scrape, or a plugin for stickam.com I have created a plugin for stickam.com, but it errors off and I don't know why. I tried posting it on these forums, but the length restrictions would not let me, and I had to break it in half.....If anyone is interested, I can email scratch that, don't give me your e-mail, I'll find a free upload place for download of the default.py that I have, if anyone wants to try and tweak it to actually work.
jpickle
Dan Dare
2009-09-13, 12:50
@jpickle
That's why you need to use http://pastebin.com or sites like that to put your error log in there, rather than pasting it in here.
Try to upload your code somewhere, like xp-dev.com or googlecode.com, so people can access it, or zip it up and upload at mediafire.com or other hosting sites.
here is the URL for the pastebin page.....Thanks for the info.
http://pastebin.com/f75981900
This is the Heart of the code (default.py) if you or anyone could help, we just might get this thing to work. It will (should) pull a dynamic list of live cams every time you run the script, that way we 'might' be able to bypass stickam's security measure. What do you think, All feedback is more than welcome,and thanks for your help.
jpickle
Any and All help will be appreciated.
Thanks
Jpickle
Dan Dare
2009-09-18, 23:43
@jpickle
That's not the entire source code, you're missing functions, like _check_for_update()...
And it goes downhill from there, there is an exception in line 37, in showCategories() - maybe you need to change the regexp.
I would suggest using BeautifulSoup if you are not familiar with regular expressions - might find it easier to work with.
http://www.crummy.com/software/BeautifulSoup/
I would also suggest using the Internet Explorer Developer Toolbar to walk the page and identify the HTML elements to extract the data you need, then use tools like Fiddler to get the FLV address.
Seems the FLV is part of the main viewMedia.do page:
<div class="video_big"><script>writeCommentedMediaPlayer('http://player.stickam.com/flash/stickam/stickam_player.swf', 'movieName=%2Fmedia%2Fvideo%2Fconverted%2F1765%2F2 354%2F7%2Fa0748d097177f47a965067e2d3bbfb65_6983153 5.flv&userID=176523547&app=mplayer_small_21.swf&duration=3148.0&link=true&hostName=http%3A%2F%2Fwww.stickam.com&MId=185758843&langID=en&autoplay=1&videoTag=false&', '448');</script></div>
It looks like your are using a lot useless pieces of code from the Justin.tv plugin that is unique to the Justin.tv website. Instead of using that code as your base, you should just start off by scratch.
You might want to check if you can play the actual rtmp stream on xbmc before you waste your time making a plugin. You can do this by reading rtmp headers with Wireshark.
If the stream plays, you then need to find out where the rtmp links are coming from.
Good luck with your first plugin :;):
There are two navi-xtreme (navi-x) processors on turner3d that he made (with explination of how he done it. One is for live broadcasts the other is for static videos. There is a link on the forums at hxxp://navix.turner3d.net to a text files so you can see how they work. They work fine in Navi-x, but the problem is that the live broadcasts at hxxp://smotri.com/broadcast/list/ are dynamic and constantly change, so if you make a .plx playlist of them, they only work for the length of time the person is broadcasting. They get assigned a new Ticket, and a new SID is generated every time they start a new broadcast even though they have static profile pages, so for live broadcasts there must be a scraper to parse the dynamic content. I can't make a scraper for Navi-X, or a plugin for XBMC, I have tried and I just can't do it. If anyone could help with this I would be greatful, if not, a little tutorial would help I am lost with this and really want to help XBMC, but I need help. Once I'm shown something I can usually absorb and understand it, and put it to good use. Can anyone help? Thanks
jpickle
I admit it, I did mod the justin.tv plugin (or script, don't remember) and I apologize for that. I did that because I figured a lot of different sites use the same PHP script just modified to the admin's taste, niche, etc...so I figured there 'might' be a chance that Justin.tv and Stickam.com, or smotri.com used the same basic php script for their sites, but obviously that is not the case. I just wanted to admit it, and apologize if modding justin.tv was wrong.
In any event, Here is a link to the navi-x processor that will take a link to a live stream url from smotri.com and pull the actual RTMP stream and send the correct Ticket, and Sid and it works well so there is half the plugin. The info in text file uses perl to process the url to its underlying RTMP Stream.
hxxp://navix.turner3d.net/smotri_live.txt
That is very helpful, and could be used to help create a plugin for xbmc, but for a plugin that would parse the /broadcast/live html for valid dynamic links and pass them to xbox, I don't know how that would happen, could some one illustrate, or point me to a plugin making Tutorial for a site with dynamic live streams like Justin.tv, smotri.com, stickam.com, etc... That may be a lot to ask, but I would really like to learn so that I can contribute to the Xbmc project, but I have to learn how to do it first.
Thanks
jpickle
I don't care that you used the code from the Justin.tv plugin. Everything here is open source.
Here are some steps you want to take when making a plugin for a site like justin.tv
1) Download and install Wireshark. (Live HTTP headers is also useful for Firefox, I use both)
2) While Wireshark is running, start playing a stream or channel
3) Copy the rtmp information from needed to play the stream and attempt to play it on xbmc
4) If you are able to play the stream, you should now start looking for where you find the rtmp information on the website. Usually, javascripts are called and their is a xml with everything.
5) Then you should start making a plugin to scrape the site layout.
I will look into those sties when I have the time.
Thanks Stacked for your help. Actually that text link I posted show how to do all of the stuff that you talked about. actually on the hxxp://navix.turner3d.net/ forum Turner walks me through (with pictures) of how he used 'httpfox' and wireshark, and hexedit32 of how he obtained all the info to create the processor. I can do that for individual links, but everytime a person turns off then on the camera they get assigned a new stream number/id etc.. so I can create a list of one moments live broadcasts, but in 5 minutes none of them (or most of them work) that is why I was trying to get a scraper (either for navi-x) or more preferably an XBMC Plugin.
thanks
jpickle
btw, I think stickam uses swf verification and xbmc rtmplib doesn't support it.
http://xbmc.org/forum/showthread.php?t=48754&page=2
I apologize, the website I was talking about (that turner created navi-x processors for which shows how to grab the RTMP stream of live feeds) is for Smotri.com He has done the hard part (I think) to make a plugin one would have to do a scrape and parse of live feed links, and just use the code written by turner to pass that info to xbmc, here is the last half of a scraper in perl
#!/usr/bin/perl -w
use strict;
use CGI;
my $params=CGI::Vars();
use LWP;
use HTTP::Request::Common;
use URI::Escape;
print "content-type:text/plain\n\n";
if($params->{url}){
#####################
### Instruct mode ###
#####################
my $url=$params->{url};
print "$url\n";
print qq~(?s)'file', '(.*?)'.*?'sid', '(.*?)'~;
}elsif($params->{v1}){
####################
### Process mode ###
####################
my $file=$params->{v1};
my $sid=$params->{v2};
my $ua=LWP::UserAgent->new;
$ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4");
my $response=$ua->request(POST "http://smotri.com/broadcast/view/url/?ktulhu=1",
Content=>[
'ktulhu'=>1,
'ticket'=>$file,
'sid'=>$sid,
]);
my $raw='';
if ($response->is_success) {
$raw=$response->content;
}else{
print "error - could not retrieve video info";
exit;
}
my($vidurl,$server,$streamname)=$raw=~/_vidURL=([^&]+).*?_server=([^&]+).*?_streamName=([^&]+)/;
$server=uri_unescape($server);
$vidurl=uri_unescape($vidurl);
$streamname=uri_unescape($streamname);
print qq*$server/$vidurl/
http://pics.smotri.com/broadcast_play.swf
$streamname*;
}
This works, but only if you go to smotri.com get a dynamic link of a live broadcast and pass it to this code. A scraper would have to scrape the smotri.com/broadcast/live
page and then pass all the links to the above code, and bam, I believe you have a valid scraper for smotri.com's live feeds.
what do you think?
jpickle
This works, but only if you go to smotri.com get a dynamic link of a live broadcast and pass it to this code. A scraper would have to scrape the smotri.com/broadcast/live
page and then pass all the links to the above code, and bam, I believe you have a valid scraper for smotri.com's live feeds.
what do you think?
jpickle
Yeah, that should be fairly simple for your first plugin. Let me know on your progress. :;):
I would let you know, but I can't as I don't know how to parse out the video link, the title, and the thumb. I can get the page, but I don't know how to extract only the info needed to pass to the processor code that turner wrote. I am studying, but everyone that I look up on google has all these third party libraries, and what not, and after a couple of hours of research, I just get numb.
I am trying but I feel like I am banging my head against a locked door, you know what I mean? Is there anyway, you or some one else could (Please) just do it, and then once I see how it is done, I can fully understand, and start making a real (hopefully) meaningful contribution to the XBMC project..I know that is a lot to ask, and all of you guys are really busy, but I'm afraid that is, unfortunately, the only way I will be able to do it. Any way, Thanks for all of your help, and sorry that I don't understand well enough to take some burden off of others, but I just don't, sorry.
thanks
jpickle
start with a basic python script and then go on from there. just look at the page source, find the section with the important info, and use 'lazy' regex.
import urllib2, urllib, re, string, sys, os, traceback
HEADER = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1'
def open_url(url):
req = urllib2.Request(url)
req.add_header('User-Agent', HEADER)
content=urllib2.urlopen(req)
data=content.read()
content.close()
return data
url='http://smotri.com/broadcast/list/'
data=open_url(url)
info = re.compile('<a href="/broadcast/view/\?id=(.+?)"\n><img src="(.*?)" width="100" height="75" class="Iframe" alt="(.*?)" title="(.*?)" /></a> </div>',re.DOTALL).findall(data)
for id,thumb,alt,title in info:
url='http://smotri.com/broadcast/view/?id='+id
label=title.decode('utf-8')
print label
print url
print thumb
Wow, Thanks for that. You're good. I didn't realize it was that simple. I really appreciate your help, and I won't forget it. And I will study this and will do my best to help Xbmc.
Thank you
jpickle
The code above isn't picking up all the streams on that page. Use this instead.
import urllib2, urllib, re, string, sys, os, traceback
HEADER = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1'
def open_url(url):
req = urllib2.Request(url)
req.add_header('User-Agent', HEADER)
content=urllib2.urlopen(req)
data=content.read()
content.close()
return data
url='http://smotri.com/broadcast/list/'
data=open_url(url)
limit=re.compile('<table class="VideoList">(.+?)<div id="ajax_slider_">', re.DOTALL).findall(data)
info=re.compile(' <a href="(.+?)"\n><img src="(.*?)" width="100" height="75" class="Iframe" alt="(.*?)" title="(.*?)" /></a> </div>',re.DOTALL).findall(limit[0])
for url,thumb,alt,title in info:
url='http://smotri.com'+url
label=title.decode('utf-8')
print label
print url
print thumb