def start(apptype, exec_dir): appname = "freestream" single_instance_checker = wx.SingleInstanceChecker(appname + '-' + wx.GetUserId()) if single_instance_checker.IsAnotherRunning(): print >> sys.stderr, 'appwrapper: already running, exit' if get_default_api_version(apptype, exec_dir) < 2: send_startup_event() os._exit(0) globalConfig.set_value('apptype', apptype) globalConfig.set_mode('client_wx') wrapper = AppWrapper() try: bgapp = run_bgapp(wrapper, appname, VERSION) except Exception as e: print >> sys.stderr, 'Fatal error while starting:', str(e) print_exc() os._exit(0) wrapper.set_bgapp(bgapp) bgapp.debug_systray = bgapp.debug_level & 1024 != 0 freestream.Player.systray.DEBUG = bgapp.debug_systray freestream.Player.systray.SHOW_DEBUG_LEVEL = bgapp.debug_systray freestream.Player.systray.DEBUG_PIECES = bgapp.debug_level & 128 != 0 freestream.Player.systray.DEBUG_VIDEOSTATUS = bgapp.debug_level & 2048 != 0 freestream.Player.systray.DEBUG_PROXY_BUF = bgapp.debug_level & 4096 != 0 wrapper.MainLoop() if not ALLOW_MULTIPLE: del single_instance_checker stop_bgapp(bgapp)
def start(apptype, exec_dir): globalConfig.set_value('apptype', apptype) appname = "freestream" globalConfig.set_mode('client_console') wrapper = AppWrapper() bgapp = run_bgapp(wrapper, appname, VERSION) wrapper.set_bgapp(bgapp) wrapper.MainLoop() stop_bgapp(bgapp)
def _start_stream(self, config): if len(config['destdir']) == 0: state_dir = Session.get_default_state_dir() config['destdir'] = os.path.join(state_dir, 'streams') try: config['destdir'] = config['destdir'].decode('utf-8') except: print_exc() if not os.path.isdir(config['destdir']): try: os.makedirs(config['destdir']) except: print_exc() return try: path = os.path.join(config['destdir'], config['name']) if os.path.isfile(path): os.remove(path) except: print_exc() globalConfig.set_mode('stream') sscfg = SessionStartupConfig() statedir = tempfile.mkdtemp() sscfg.set_state_dir(statedir) sscfg.set_listen_port(config['port']) sscfg.set_megacache(False) sscfg.set_overlay(False) sscfg.set_dialback(True) if config['host']: url = 'http://' + str(config['host']) + ':' + str(sscfg.get_listen_port()) + '/announce' sscfg.set_internal_tracker_url(url) s = Session(sscfg) authfilename = os.path.join(config['destdir'], config['name'] + '.sauth') try: authcfg = RSALiveSourceAuthConfig.load(authfilename) except: authcfg = RSALiveSourceAuthConfig() authcfg.save(authfilename) config['protected'] = True provider_key = config['provider-key'] if len(config['provider-key']) else None bitrate = int(config['bitrate']) bitrate *= 125 tdef = TorrentDef() tdef.create_live(config['name'], bitrate, config['duration'], authcfg, config['protected'], provider_key) tdef.set_tracker(s.get_internal_tracker_url()) if config['piecesize'] == 'auto': piece_size = self.get_piece_size(bitrate) else: piece_size = int(config['piecesize']) tdef.set_piece_length(piece_size) print >> sys.stderr, 'bitrate:', config['bitrate'] print >> sys.stderr, 'piece size:', piece_size print >> sys.stderr, 'dest dir:', config['destdir'] print >> sys.stderr, 'tracker url:', s.get_internal_tracker_url() if config['trackers']: trackers = [[s.get_internal_tracker_url()]] for t in config['trackers'].split(','): print >> sys.stderr, 'tracker:', t trackers.append([t]) tdef.set_tracker_hierarchy(trackers) tdef.finalize() print >> sys.stderr, '-------------------' ext = 'acelive' torrentbasename = config['name'] + '.' + ext torrentfilename = os.path.join(config['destdir'], torrentbasename) config['torrentfilename'] = torrentfilename tdef.save(torrentfilename) self.send_torrent_to_server(tdef) dscfg = DownloadStartupConfig() dscfg.set_dest_dir(config['destdir']) source = self.init_source(config['source'], tdef, dscfg) self.source = HaltOnEOFStream(source) restartstatefilename = os.path.join(config['destdir'], config['name'] + '.restart') dscfg.set_video_source(self.source, authcfg, restartstatefilename=restartstatefilename) dscfg.set_max_uploads(config['maxclients']) self.s = s self.statedir = statedir self.config = config self.download = s.start_download(tdef, dscfg) self.download.set_state_callback(self.state_callback, getpeerlist=False)
def _start_stream(self, config): if len(config['destdir']) == 0: state_dir = Session.get_default_state_dir() config['destdir'] = os.path.join(state_dir, 'streams') try: config['destdir'] = config['destdir'].decode('utf-8') except: print_exc() if not os.path.isdir(config['destdir']): try: os.makedirs(config['destdir']) except: print_exc() return try: path = os.path.join(config['destdir'], config['name']) if os.path.isfile(path): os.remove(path) except: print_exc() globalConfig.set_mode('stream') sscfg = SessionStartupConfig() statedir = tempfile.mkdtemp() sscfg.set_state_dir(statedir) sscfg.set_listen_port(config['port']) sscfg.set_megacache(False) sscfg.set_overlay(False) sscfg.set_dialback(True) if config['host']: url = 'http://' + str(config['host']) + ':' + str( sscfg.get_listen_port()) + '/announce' sscfg.set_internal_tracker_url(url) s = Session(sscfg) authfilename = os.path.join(config['destdir'], config['name'] + '.sauth') try: authcfg = RSALiveSourceAuthConfig.load(authfilename) except: authcfg = RSALiveSourceAuthConfig() authcfg.save(authfilename) config['protected'] = True provider_key = config['provider-key'] if len( config['provider-key']) else None bitrate = int(config['bitrate']) bitrate *= 125 tdef = TorrentDef() tdef.create_live(config['name'], bitrate, config['duration'], authcfg, config['protected'], provider_key) tdef.set_tracker(s.get_internal_tracker_url()) if config['piecesize'] == 'auto': piece_size = self.get_piece_size(bitrate) else: piece_size = int(config['piecesize']) tdef.set_piece_length(piece_size) print >> sys.stderr, 'bitrate:', config['bitrate'] print >> sys.stderr, 'piece size:', piece_size print >> sys.stderr, 'dest dir:', config['destdir'] print >> sys.stderr, 'tracker url:', s.get_internal_tracker_url() if config['trackers']: trackers = [[s.get_internal_tracker_url()]] for t in config['trackers'].split(','): print >> sys.stderr, 'tracker:', t trackers.append([t]) tdef.set_tracker_hierarchy(trackers) tdef.finalize() print >> sys.stderr, '-------------------' ext = 'acelive' torrentbasename = config['name'] + '.' + ext torrentfilename = os.path.join(config['destdir'], torrentbasename) config['torrentfilename'] = torrentfilename tdef.save(torrentfilename) self.send_torrent_to_server(tdef) dscfg = DownloadStartupConfig() dscfg.set_dest_dir(config['destdir']) source = self.init_source(config['source'], tdef, dscfg) self.source = HaltOnEOFStream(source) restartstatefilename = os.path.join(config['destdir'], config['name'] + '.restart') dscfg.set_video_source(self.source, authcfg, restartstatefilename=restartstatefilename) dscfg.set_max_uploads(config['maxclients']) self.s = s self.statedir = statedir self.config = config self.download = s.start_download(tdef, dscfg) self.download.set_state_callback(self.state_callback, getpeerlist=False)