def start_recode(self, channel_name, duration, output='./'): output = os.path.abspath(output) if not os.path.isdir(output): os.mkdir(output) outfile = os.path.join(output, util.get_time_string() + ".flv") LOG.info("[channel] %s", channel_name) uuid = self._get_uuid(channel_name) flv_location = self._get_flv_location(uuid) LOG.info("[location] %s", flv_location) LOG.info("[output] %s", outfile) LOG.info("[start.... ] %s", util.get_time_string()) self.download_handle = DownloadStreamHandler(open(outfile,"w"), duration) self.http.fetch(flv_location, self.download_handle) LOG.info("[stop..... ] %s", util.get_time_string())
def start_recode(self, channel_name, duration, output='./'): ofile='' output = os.path.abspath(output) if not os.path.isdir(output): os.mkdir(output) ofile = os.path.join(output, util.get_time_string() + ".flv") print "[channel]", channel_name uuid = self.__get_uuid(channel_name) flv_location = self.__get_flv_location(uuid) print "[location]", flv_location print "[output]", ofile print "[start.... ]", util.get_time_string() self.download_handle = DownloadStreamHandler(open(ofile,"w"), duration) self.__http.fetch(flv_location, self.download_handle) print "[stop..... ]", util.get_time_string()
def recode(url, duration=None, vfmt=2, outpath='./', npf=3, freq=10, tmin=5, tmax=20, proxy=None, log=None): assert duration is None or duration > 0 name = '%s.%s.ts' % (_util.get_time_string(), hash(url)) outfile = pjoin(outpath, name) log.info("|=> begin: %s", url) if duration: log.info("|=>duration: %d", duration) log.info("|=> output: %s", outfile) _util.assure_path(outpath) axel = WorkShop(tmin=tmin, tmax=tmax, log=log) m3u8 = M3u8Stream(axel=axel, proxy=proxy,log=log) fetcher = HttpFetcher() start_at = time.time() try: with open(outfile, 'wb') as fp: if url.find('m3u8') > 0 or __is_url_file(url): axel.serve() m3u8.recode(url=url, duration=duration, vfmt=vfmt, fp=fp, npf=npf, freq=cfg.freq) else: fetcher.fetch(url=url, fp=fp) log.info("|=> end: total=%.2fs, out=%s", time.time() - start_at, outfile) finally: if axel.isAlive(): axel.setToStop() axel.join()
def recode(url, duration=None, vfmt=2, outpath='./', npf=3, freq=10, tmin=5, tmax=20, proxy=None, log=None): assert duration is None or duration > 0 name = '%s.%s.ts' % (_util.get_time_string(), hash(url)) outfile = pjoin(outpath, name) log.info("|=> begin: %s", url) if duration: log.info("|=>duration: %d", duration) log.info("|=> output: %s", outfile) _util.assure_path(outpath) axel = WorkShop(tmin=tmin, tmax=tmax, log=log) m3u8 = M3u8Stream(axel=axel, proxy=proxy, log=log) fetcher = HttpFetcher() start_at = time.time() try: with open(outfile, 'wb') as fp: if url.find('m3u8') > 0 or __is_url_file(url): axel.serve() m3u8.recode(url=url, duration=duration, vfmt=vfmt, fp=fp, npf=npf, freq=cfg.freq) else: fetcher.fetch(url=url, fp=fp) log.info("|=> end: total=%.2fs, out=%s", time.time() - start_at, outfile) finally: if axel.isAlive(): axel.setToStop() axel.join()