Пример #1
0
    def __init__(self, redirectstderrout, appname, appversion, params, single_instance_checker, installdir, i2iport, sport, httpport):

        # Almost generic HTTP server
        self.videoHTTPServer = VideoHTTPServer(httpport)
        self.videoHTTPServer.register(self.videoservthread_error_callback,self.videoservthread_set_status_callback)

        BaseApp.__init__(self, redirectstderrout, appname, appversion, params, single_instance_checker, installdir, i2iport, sport)
        self.httpport = httpport
        
        # SEARCH:P2P
        # Maps a query ID to the original searchstr, timestamp and all hits (local + remote)
        self.id2hits = Query2HitsMap()
        
        # Maps a URL path received by HTTP server to the requested resource,
        # reading or generating it dynamically.
        #
        # For saving .torrents received in hits to P2P searches using
        # SIMPLE+METADATA queries
        self.tqueue = TimedTaskQueue(nameprefix="BGTaskQueue")
        self.searchmapper = SearchPathMapper(self.s,self.id2hits,self.tqueue)
        self.hits2anypathmapper = Hits2AnyPathMapper(self.s,self.id2hits)
        
        self.videoHTTPServer.add_path_mapper(self.searchmapper)
        self.videoHTTPServer.add_path_mapper(self.hits2anypathmapper)

        # WEB Interface        
        # Maps a URL path received by HTTP server to the requested resource,
        # reading or generating it dynamically.
        self.webIFmapper = WebIFPathMapper(self, self.s)
        
        self.videoHTTPServer.add_path_mapper(self.webIFmapper)

        # Generic HTTP server start. Don't add mappers dynamically afterwards!
        self.videoHTTPServer.background_serve()

        # Maps Downloads to a using InstanceConnection and streaminfo when it 
        # plays. So it contains the Downloads in VOD mode for which there is
        # active interest from a plugin.
        #
        # At the moment each Download is used/owned by a single IC and a new
        # request for the same torrent will stop playback to the original IC
        # and resume it to the new user.
        #
        self.dusers = {}   
        self.approxplayerstate = MEDIASTATE_STOPPED

        self.counter = 0 # counter for the stats reported periodically
        self.interval = 120 # report interval
        self.iseedeadpeople = False
        
        if sys.platform == "win32":
            # If the BG Process is started by the plug-in notify it with an event
            try:
                startupEvent = win32event.CreateEvent( None, 0, 0, 'startupEvent' )
                win32event.SetEvent( startupEvent )
                win32api.CloseHandle( startupEvent ) # TODO : is it possible to avoid importing win32api just to close an handler?
            except:
                pass
Пример #2
0
    def __init__(self, redirectstderrout, appname, params, single_instance_checker, installdir, i2iport, sport):

        self.videoHTTPServer = VideoHTTPServer(VIDEOHTTP_LISTENPORT)
        self.videoHTTPServer.register(self.videoservthread_error_callback,self.videoservthread_set_status_callback)
        self.videoHTTPServer.background_serve()

        #self.searchHTTPServer = MultiHTTPServer(VIDEOHTTP_LISTENPORT+1)
        #self.searchHTTPServer.register(self.videoservthread_error_callback,self.videoservthread_set_status_callback)
        self.searchHTTPServer = self.videoHTTPServer

        BaseApp.__init__(self, redirectstderrout, appname, params, single_instance_checker, installdir, i2iport, sport)
        
        # SEARCH:P2P
        # Maps a query ID to the original searchstr, timestamp and all hits (local + remote)
        self.id2hits = Query2HitsMap()
        
        # Maps a URL path received by HTTP server to the requested resource,
        # reading or generating it dynamically.
        #
        # For saving .torrents received in hits to P2P searches using
        # SIMPLE+METADATA queries
        self.tqueue = TimedTaskQueue(nameprefix="BGTaskQueue")
        self.searchmapper = SearchPathMapper(self.s,self.id2hits,self.tqueue)
        self.hits2anypathmapper = Hits2AnyPathMapper(self.s,self.id2hits)
        
        self.searchHTTPServer.add_path_mapper(self.searchmapper)
        self.searchHTTPServer.add_path_mapper(self.hits2anypathmapper)
        self.searchHTTPServer.background_serve()
        self.searchurl = 'http://127.0.0.1:'+str(self.searchHTTPServer.get_port())+URLPATH_SEARCH_PREFIX


        # Maps Downloads to a using InstanceConnection and streaminfo when it 
        # plays. So it contains the Downloads in VOD mode for which there is
        # active interest from a plugin.
        #
        # At the moment each Download is used/owned by a single IC and a new
        # request for the same torrent will stop playback to the original IC
        # and resume it to the new user.
        #
        self.dusers = {}   
        self.approxplayerstate = MEDIASTATE_STOPPED

        self.counter = 0 # counter for the stats reported periodically
        self.interval = 120 # report interval
        
        if sys.platform == "win32":
            # If the BG Process is started by the plug-in notify it with an event
            startupEvent = win32event.CreateEvent( None, 0, 0, 'startupEvent' )
            win32event.SetEvent( startupEvent )
            win32api.CloseHandle( startupEvent ) # TODO : is it possible to avoid importing win32api just to close an handler?
Пример #3
0
 def remove_playing_download(self,d2remove):
     """ Called when sesscb_remove_playing_callback has determined that
     we should remove this Download, because it would take too much
     bandwidth to download it and the user is apparently no longer
     interested. 
     """
     BaseApp.remove_playing_download(self,d2remove)
     if d2remove in self.dusers:
         if DEBUG:
             print >>sys.stderr,time.asctime(),'-', "bg: remove_playing_download"
         if 'streaminfo' in self.dusers[d2remove]:
             stream = self.dusers[d2remove]['streaminfo']['stream']
             stream.close() # Close original stream. 
         del self.dusers[d2remove]
Пример #4
0
    def gui_states_callback(self, dslist, haspeerlist):
        """ Override BaseApp """
        #print >>sys.stderr,"bg: gui_states_callback",currentThread().getName()

        (playing_dslist, totalhelping,
         totalspeed) = BaseApp.gui_states_callback(self, dslist, haspeerlist)
        try:
            self.report_periodic_vod_stats(playing_dslist)
        except:
            print_exc()

        for ds in playing_dslist:
            d = ds.get_download()
            duser = self.dusers[d]
            uic = duser['uic']
            if uic is not None:
                # Generate info string for all
                [
                    topmsg, msg, duser['said_start_playback'],
                    duser['decodeprogress']
                ] = get_status_msgs(ds, self.approxplayerstate, self.appname,
                                    duser['said_start_playback'],
                                    duser['decodeprogress'], totalhelping,
                                    totalspeed)
                info = msg
                #if DEBUG:
                #    print >>sys.stderr, 'bg: 4INFO: Sending',info
                uic.info(info)
Пример #5
0
    def OnInit(self):
        try:
            # Do common initialization
            BaseApp.OnInitBase(self)

            # Arno, 2010-07-15: We try to detect browser presence by looking
            # at get_speed_info JSON request from Firefox statusbar. However.
            # these calls are unreliable, i.e., somethings the XmlHTTPRequest
            # at the client doesn't reach the server, although the server is
            # capable of replying to the request. Hence, we disable self-destruct
            # for now.
            if KILLONIDLE:
                print >> sys.stderr, "bg: Kill-on-idle test enabled"
                self.i2is.add_task(self.i2i_kill_on_browser_gone,
                                   IDLE_BEFORE_SELFKILL / 2)
            else:
                print >> sys.stderr, "bg: Kill-on-idle test disabled"

            print >> sys.stderr, "bg: Awaiting commands"
            return True

        except Exception, e:
            print_exc()
            self.show_error(str(e))
            self.OnExit()
            return False
Пример #6
0
 def gui_webui_halt_download(self, d2halt, stop=False):
     """ Called when user has decided to stop or remove a specific DL via webUI.
     For stop the Download is not removed. """
     if d2halt in self.dusers:
         try:
             duser = self.dusers[d2halt]
             olduic = duser['uic']
             if olduic is not None:
                 print >> sys.stderr, "bg: gui_webui_halt_download: Oops, someone interested, removing anyway"
                 olduic.shutdown()
             if 'streaminfo' in duser:
                 # Download was already playing, clean up.
                 stream = duser['streaminfo']['stream']
                 stream.close()  # Close original stream.
         finally:
             del self.dusers[d2halt]
     if stop:
         BaseApp.stop_playing_download(self, d2halt)
     else:
         BaseApp.remove_playing_download(self, d2halt)
Пример #7
0
 def gui_webui_halt_download(self,d2halt,stop=False):
     """ Called when user has decided to stop or remove a specific DL via webUI.
     For stop the Download is not removed. """
     if d2halt in self.dusers:
         try:
             duser = self.dusers[d2halt]
             olduic = duser['uic'] 
             if olduic is not None:
                 print >>sys.stderr,"bg: gui_webui_halt_download: Oops, someone interested, removing anyway"
                 olduic.shutdown()
             if 'streaminfo' in duser:
                 # Download was already playing, clean up.
                 stream = duser['streaminfo']['stream']
                 stream.close() # Close original stream.
         finally: 
             del self.dusers[d2halt]
     if stop:
         BaseApp.stop_playing_download(self,d2halt)
     else:
         BaseApp.remove_playing_download(self,d2halt)
Пример #8
0
 def remove_playing_download(self,d2remove):
     """ Called when sesscb_remove_playing_callback has determined that
     we should remove this Download, because it would take too much
     bandwidth to download it. However, we must check in another user has not
     become interested. 
     """
     if DEBUG:
         print >>sys.stderr,"bg: remove_playing_download @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
     if d2remove in self.dusers:
         duser = self.dusers[d2remove]
         if duser['uic'] is None:
             # No interest
             if DEBUG:
                 print >>sys.stderr,"bg: remove_playing_download: Yes, no interest"
             BaseApp.remove_playing_download(self,d2remove)
             if 'streaminfo' in duser:
                 stream = duser['streaminfo']['stream']
                 stream.close() # Close original stream. 
             del self.dusers[d2remove]
         elif DEBUG:
             print >>sys.stderr,"bg: remove_playing_download: No, someone interested",`duser['uic']`
Пример #9
0
 def remove_playing_download(self, d2remove):
     """ Called when sesscb_remove_playing_callback has determined that
     we should remove this Download, because it would take too much
     bandwidth to download it. However, we must check in another user has not
     become interested. 
     """
     if DEBUG:
         print >> sys.stderr, "bg: remove_playing_download @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
     if d2remove in self.dusers:
         duser = self.dusers[d2remove]
         if duser['uic'] is None:
             # No interest
             if DEBUG:
                 print >> sys.stderr, "bg: remove_playing_download: Yes, no interest"
             BaseApp.remove_playing_download(self, d2remove)
             if 'streaminfo' in duser:
                 stream = duser['streaminfo']['stream']
                 stream.close()  # Close original stream.
             del self.dusers[d2remove]
         elif DEBUG:
             print >> sys.stderr, "bg: remove_playing_download: No, someone interested", ` duser[
                 'uic'] `
Пример #10
0
 def gui_states_callback(self,dslist,haspeerlist):
     """ Override BaseApp """
     (playing_dslist,totalhelping,totalspeed) = BaseApp.gui_states_callback(self,dslist,haspeerlist)
     try:
         self.report_periodic_vod_stats(playing_dslist)
     except:
         print_exc()
    
     for ds in playing_dslist:
         d = ds.get_download()
         duser = self.dusers[d]
         uic = duser['uic']
         
         # Generate info string for all
         [topmsg,msg,duser['said_start_playback'],duser['decodeprogress']] = get_status_msgs(ds,self.approxplayerstate,self.appname,duser['said_start_playback'],duser['decodeprogress'],totalhelping,totalspeed)
         info = msg
         #if DEBUG:
         #    print >>sys.stderr, time.asctime(),'-', 'bg: 4INFO: Sending',info
         uic.info(info)
Пример #11
0
    def __init__(self, redirectstderrout, appname, appversion, params,
                 single_instance_checker, installdir, i2iport, sport,
                 httpport):

        # Almost generic HTTP server
        self.videoHTTPServer = VideoHTTPServer(httpport)
        self.videoHTTPServer.register(self.videoservthread_error_callback,
                                      self.videoservthread_set_status_callback)

        BaseApp.__init__(self, redirectstderrout, appname, appversion, params,
                         single_instance_checker, installdir, i2iport, sport)
        self.httpport = httpport

        # SEARCH:P2P
        # Maps a query ID to the original searchstr, timestamp and all hits (local + remote)
        self.id2hits = Query2HitsMap()

        # Maps a URL path received by HTTP server to the requested resource,
        # reading or generating it dynamically.
        #
        # For saving .torrents received in hits to P2P searches using
        # SIMPLE+METADATA queries
        self.tqueue = TimedTaskQueue(nameprefix="BGTaskQueue")
        self.searchmapper = SearchPathMapper(self.s, self.id2hits, self.tqueue)
        self.hits2anypathmapper = Hits2AnyPathMapper(self.s, self.id2hits)

        self.videoHTTPServer.add_path_mapper(self.searchmapper)
        self.videoHTTPServer.add_path_mapper(self.hits2anypathmapper)

        # WEB Interface
        # Maps a URL path received by HTTP server to the requested resource,
        # reading or generating it dynamically.
        self.webIFmapper = WebIFPathMapper(self, self.s)

        self.videoHTTPServer.add_path_mapper(self.webIFmapper)

        # Generic HTTP server start. Don't add mappers dynamically afterwards!
        self.videoHTTPServer.background_serve()

        # Maps Downloads to a using InstanceConnection and streaminfo when it
        # plays. So it contains the Downloads in VOD mode for which there is
        # active interest from a plugin.
        #
        # At the moment each Download is used/owned by a single IC and a new
        # request for the same torrent will stop playback to the original IC
        # and resume it to the new user.
        #
        self.dusers = {}
        self.approxplayerstate = MEDIASTATE_STOPPED

        self.counter = 0  # counter for the stats reported periodically
        self.interval = 120  # report interval
        self.iseedeadpeople = False

        if sys.platform == "win32":
            # If the BG Process is started by the plug-in notify it with an event
            try:
                startupEvent = win32event.CreateEvent(None, 0, 0,
                                                      'startupEvent')
                win32event.SetEvent(startupEvent)
                win32api.CloseHandle(
                    startupEvent
                )  # TODO : is it possible to avoid importing win32api just to close an handler?
            except:
                pass