def __init__(self, redirectstderrout, appname, params, single_instance_checker, installdir, i2iport, sport): BaseApp.__init__(self, redirectstderrout, appname, params, single_instance_checker, installdir, i2iport, sport) self.videoHTTPServer = VideoHTTPServer(VIDEOHTTP_LISTENPORT) self.videoHTTPServer.background_serve() self.videoHTTPServer.register(self.videoservthread_error_callback, self.videoservthread_set_status_callback) # 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 = {} # 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?
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
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?
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, "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]
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?
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,"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]
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, 'bg: 4INFO: Sending',info uic.info(info)
def OnInit(self): try: # Do common initialization BaseApp.OnInitBase(self) return True except Exception, e: print_exc() self.show_error(str(e)) self.OnExit() return False
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,time.asctime(),'-', "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)
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,time.asctime(),'-', "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,time.asctime(),'-', "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,time.asctime(),'-', "bg: remove_playing_download: No, someone interested",`duser['uic']`
def OnInit(self): try: # Do common initialization BaseApp.OnInitBase(self) print >> sys.stderr, "bg: Awaiting commands" return True except Exception, e: print_exc() self.show_error(str(e)) self.OnExit() return False
def __init__(self, redirectstderrout, appname, params, single_instance_checker, installdir, i2iport, sport): BaseApp.__init__(self, redirectstderrout, appname, params, single_instance_checker, installdir, i2iport, sport) self.videoHTTPServer = VideoHTTPServer(VIDEOHTTP_LISTENPORT) self.videoHTTPServer.background_serve() self.videoHTTPServer.register(self.videoservthread_error_callback, self.videoservthread_set_status_callback) # 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 = {} # 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?
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, 'bg: 4INFO: Sending',info uic.info(info)
def gui_states_callback(self,dslist,haspeerlist): """ Override BaseApp """ #print >>sys.stderr,time.asctime(),'-', "bg: gui_states_callback",currentThread().getName() (playing_dslist,totalhelping,totalspeed) = BaseApp.gui_states_callback(self,dslist,haspeerlist) # print >>sys.stderr,time.asctime(),'-', "playing_dslist=",playing_dslist," totalhelping=",totalhelping," down=",totalspeed[DOWNLOAD]," up=",totalspeed[UPLOAD],"\n" 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 = 'totalhelping='+str(totalhelping)+"\tdown="+str(round(totalspeed[DOWNLOAD]))+" KB/s\tup="+str(round(totalspeed[UPLOAD]))+" KB/s" # info = msg #if DEBUG: # print >>sys.stderr, time.asctime(),'-', 'bg: 4INFO: Sending',info uic.info(info)