File: RSSPlaylist.py

package info (click to toggle)
freej 0.10git20100110-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 32,080 kB
  • ctags: 22,705
  • sloc: cpp: 156,254; ansic: 25,531; sh: 13,538; perl: 4,624; makefile: 3,278; python: 2,889; objc: 1,284; asm: 1,125; ruby: 126
file content (131 lines) | stat: -rw-r--r-- 3,598 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
# by Lluis Gomez y Bigorda
# GNU GPL v3

"""
Classes to make a continuous video stream playlist from an RSS feed.
The script is planned to be a useful tool for video online databases as
http://giss.tv/dmmdb and plumi.org based sites to be able to do 
continuity tv channels on the internet. 

The script takes a an argument the URL of the RSS feed. If it's not specified will
fetch http://giss.tv/dmmdb/rss.php?channel=piksel08 by default.

In order to run the script you need RSS.py, and rss parser you can found here::
http://www.mnot.net/python/RSS.py

The script is still not functional as we need new features on the freej core and 
in the freej python bindings. But it's an example as a simple user case and as 
feature request need example ;)

"""

import threading
import freej
import time
import sys
import inspect
import urllib
from RSS import ns, CollectionChannel, TrackingChannel

end_of_video = False;

class NextVideoCB(freej.DumbCall):
  def __init__(self, *args):
      super(NextVideoCB, self).__init__(*args)

  def callback(self):
      global end_of_video
      end_of_video = True;


class RSSsucker(object):
    """A RSSsucker is a RSS parser wich returns a video URL list of a RSS1.0 feed."""

    def __init__(self, url="http://giss.tv/dmmdb/rss.php?channel=piksel08"):
        self.url = url
        self.suck_feed()

    def suck_feed(self):
        #Indexes RSS data by item URL
        tc = TrackingChannel()

        #Returns the RSSParser instance used, which can usually be ignored
	print "Fetching ",self.url," ..."
        tc.parse(self.url)

        RSS10_TITLE = (ns.rss10, 'title')
        RSS10_DESC = (ns.rss10, 'description')

        self.list = list() 

        items = tc.listItems()
        for item in items:
            url = item[0].replace("ol","dl")
            print url
            self.list.append(url)
	

class RSSPlaylist(object):
  """A RSSPlaylist is a running freej context and a video playlist from an RSS."""

  def __init__(self, width=320, height=240, url = "http://giss.tv/dmmdb/rss.php?channel=piksel08"):
    global end_of_video
    self.width = width
    self.height = height
    self.rsssucker = RSSsucker(url)
    self.ctx_thread = None

    if len(self.rsssucker.list):
# init context
        self.cx = freej.Context()
        self.cx.init()

        self.scr = freej.SdlScreen()
        self.scr.init( 400, 300 );
        self.cx.add_screen(scr)

        self.cx.plugger.refresh(self.cx)
        self.ctx_thread = threading.Thread(target = self.cx.start,
                                           name = "freej")
        self.ctx_thread.start()
        
        self.callback = NextVideoCB()
        
        self.audio = freej.AudioCollector('freej', 1024, 44100);

        while (not self.cx.quit):
	            
            for file in self.rsssucker.list:
                print file
                self.lay = freej.VideoLayer()
                self.lay.init(self.cx)

                self.lay.open(urllib.pathname2url(file).replace("%3A",":"))
                self.lay.add_eos_call(self.callback)
                self.lay.start()

                self.scr.add_layer(self.lay)

	        self.scr.add_audio( self.audio.Jack )

                while(not end_of_video): time.sleep(5)
                print "end of video"
                self.lay.quit = True
                self.cx.rem_layer(self.lay)
		end_of_video = False

    else:
        print "Cannot start a show without playlist!"







if len(sys.argv) > 1:
    rssplaylist = RSSPlaylist(400,300,sys.argv[1])
else:
    rssplaylist = RSSPlaylist()