View Full Version : www.TurunSanoma.fi Video browser PythonScript..
realjobe
2007-06-18, 21:59
Hi.
I know this Python suggestion is VERY odd, due to a Finnish nature of the thing. "TurunSanomat" is the newspaper here in Finland and they also publish .flv video on local news etc..
The priciple is very simple with the publish.
Site is http://videot.turunsanomat.fi/
I think the Python might be quite simple.
- Open site http://videot.turunsanomat.fi/
- Search for "video_item" and get it's '<a href="?video=5ab6e381' Video value. in here it is 5ab6e381.
- Load the picture for is from http://videot.turunsanomat.fi/videot/5ab6e381.jpg
- Generate link for the video http://videot.turunsanomat.fi/videot/5ab6e381.flv
- Read the text from "video_text" tags below and show it also with the pic and with the link to video.
- Continue this as far as "<!--JavaScript Tag" tag shows reading all "video_item" taqs that comes along and stripping / generating the data from..
I have NO idea of how doing this But the man who gets this done will be Greatly Hoorayd! There are thousands of Finns using XBMC and this solution is very needed. :)
Nuka1195
2007-06-19, 01:44
from sgmllib import SGMLParser
class VideoParser( SGMLParser ):
def reset( self ):
self.videos = ()
self.base_url = "http://videot.turunsanomat.fi/"
self._clear_checks()
self._clear_items()
SGMLParser.reset( self )
def _clear_checks( self ):
self.link_found = False
self.title_found = False
def _clear_items( self ):
self.image = ""
self.title = ""
def handle_data( self, text ):
if ( self.image and self.title_found ):
self.title = unicode( text.strip(), "utf-8" )
self._clear_checks()
elif ( self.image and self.title and text.strip() ):
self.videos += ( ( self.title, self.base_url + self.image, self.base_url + os.path.splitext( self.image )[ 0 ] + ".flv", unicode( text.strip(), "utf-8" ), ), )
self._clear_items()
def start_a( self, attrs ):
if ( self.image ):
for key, value in attrs:
if ( key == "href" ):
self.link_found = True
def start_b( self, attrs ):
if ( self.link_found ):
self.title_found = True
def start_img( self, attrs ):
for key, value in attrs:
if ( key == "src" and value.endswith( ".jpg" ) ):
self.image = value
if ( __name__ == "__main__" ):
import os
import urllib2
debug = True
debugWrite = False
base_url = "http://videot.turunsanomat.fi/"
if ( not debug ):
usock = urllib2.urlopen( base_url )
else: usock = open( os.path.join( os.getcwd().replace( ";", "" ), "htmlsource.txt" ), "r" )
htmlSource = usock.read()
usock.close()
####################### write source for testing #######################
if (debugWrite):
usock = open( os.path.join( os.getcwd().replace( ";", "" ), "htmlsource.txt" ), "w" )
usock.write( htmlSource )
usock.close()
################################################## ############
parser = VideoParser()
parser.feed( htmlSource )
parser.close()
for item in parser.videos:
print item[ 0 ].encode( "ascii", "ignore" ) #Title
print item[ 1 ] #Image url
print item[ 2 ] #Video url
print item[ 3 ].encode( "ascii", "ignore" ) #Description
print "---------------------------------"
The above code parses the web page a creates a tuple of tuples that contain: Title, Image url, Video Url, Description.
You need to download the image files and cache them, add the info to a list and then you can select which to view.
Maybe someone who speaks the language can finish it up with a nice WindowXML skin.
Good Luck
realjobe
2007-06-19, 09:46
AMAZING! I'm Stunned, Speachless!
THANK YOU SO MUCH!!!
I'll give it a try!!!!!
:grin:
realjobe
2007-06-25, 10:14
I'm auffully sorry, but I'm a bit lost here how to put the script to working .py file.
That other resources I need, shall I take some other streaming scipt as a base and change the default.py?
realjobe
2007-06-27, 12:17
Hi there.
I'm sorry, but my efforts are in vain. I am not qualifiled to make pythons, I just don't understand.
I was wonderig If some wonderful person could build simple default.py with no fancy gfx or navigations, just plain pyhton that
- loads the html and parses it and prints the links & payload to screen.
- the links then when selected and pressed creates Mplayer object and starts to stream the .flv file..
I would greatly be in humble debt.
:laugh:
realjobe
2007-10-15, 08:58
hi there.
Now that we have Plugin technology created for Pythons, how dificult is it to create this into plugin? :)