def main(args): argp = ARGPARSER.parse_args(args[1:]) # ID is the stem of a file id_to_ann_files = defaultdict(list) # Index all ID;s before we merge so that we can do a little magic for file_path in (l.strip() for l in stdin): if not any((file_path.endswith(suff) for suff in UNMERGED_SUFFIXES)): if not argp.no_warn: import sys print >> sys.stderr, ( 'WARNING: invalid file suffix for %s, ignoring' ) % (file_path, ) continue dirname, basename = split_path(file_path) id = join_path(dirname, basename.split('.')[0]) id_to_ann_files[id].append(file_path) for id, ann_files in id_to_ann_files.iteritems(): #XXX: Check if output file exists lines = [] for ann_file_path in ann_files: with open(ann_file_path, 'r') as ann_file: for line in ann_file: lines.append(line) with open(id + '.' + MERGED_SUFFIX, 'w') as merged_ann_file: for line in lines: merged_ann_file.write(line)
def main(args): argp = ARGPARSER.parse_args(args[1:]) id_to_ann_files = defaultdict(list) for file_path in (l.strip() for l in stdin): if not any((file_path.endswith(suff) for suff in UNMERGED_SUFFIXES)): if not argp.no_warn: import sys print >> sys.stderr, ( 'WARNING: invalid file suffix for %s, ignoring') % ( file_path, ) continue dirname, basename = split_path(file_path) id = join_path(dirname, basename.split('.')[0]) id_to_ann_files[id].append(file_path) for id, ann_files in id_to_ann_files.iteritems(): lines = [] for ann_file_path in ann_files: with open(ann_file_path, 'r') as ann_file: for line in ann_file: lines.append(line) with open(id + '.' + MERGED_SUFFIX, 'w') as merged_ann_file: for line in lines: merged_ann_file.write(line)
def main(args): argp = ARGPARSER.parse_args(args[1:]) # ID is the stem of a file id_to_ann_files = defaultdict(list) # Index all ID;s before we merge so that we can do a little magic for file_path in (l.strip() for l in stdin): if not any((file_path.endswith(suff) for suff in UNMERGED_SUFFIXES)): if not argp.no_warn: import sys print(('WARNING: invalid file suffix for %s, ignoring') % (file_path, ), file=sys.stderr) continue dirname, basename = split_path(file_path) id = join_path(dirname, basename.split('.')[0]) id_to_ann_files[id].append(file_path) for id, ann_files in id_to_ann_files.items(): # XXX: Check if output file exists lines = [] for ann_file_path in ann_files: with open(ann_file_path, 'r') as ann_file: for line in ann_file: lines.append(line) with open(id + '.' + MERGED_SUFFIX, 'w') as merged_ann_file: for line in lines: merged_ann_file.write(line)
def main(): global g_adv_length save_result = "./d.txt" regex = r"Duration:.+(\d\d:\d\d:\d\d\.\d\d)" g_adv_length = float( input( "In vidoe at tails ,the adverisement duration times Long(ep. 5 seconds input 5 and Enter):" )) curdir = input("Need to cut video directory : ") if os.path.exists(save_result): os.unlink(save_result) videofiles = get_videofiles(curdir) for file_name in videofiles: basename = os.path.basename(file_name) videosize = os.path.getsize(file_name) ext_name = os.path.splitext(file_name)[1] file_path = os.path.dirname(file_name) new_name = "%s/%s_%s" % (file_path, basename.split(".")[0], ext_name) duration = get_VideoDurationsByName(file_name) start_at = "00:00:00" total_seconds = get_seconds(duration) how_Long = format_TimeStyles(total_seconds - g_adv_length) ## print("duration=%s\nhow_Long=%s"%(duration,how_Long)) ## print("file_name=%s file_path=%s\nbasename=%s\nnew_name=%s"%(file_name,file_path,basename,new_name)) output = cut_VideoAds(file_name, new_name, start_at, how_Long, save_result)
def _get_download_content(self): asset_path = join(self.repo.path, "downloads") backends = ["freecad", "openscad"] #find most current release release = {} development = {} for backend in backends: release[backend] = {} development[backend] = {} for filename in listdir(join(asset_path, backend)): basename, ext = splitext(filename) if ext == ".gz": ext = ".tar.gz" basename = splitext(basename)[0] parts = basename.split("_") version_string = parts[2] #some old development snapshots have no license in filename license = "none" if len(parts) > 3: license = parts[3] kind = development[backend] version = None try: version = int(version_string) except ValueError: version = float(version_string) kind = release[backend] if not license in kind: kind[license] = {} if not ext in kind[license]: kind[license][ext] = (version, join(backend, filename)) elif version > kind[license][ext][0]: kind[license][ext] = (version, join(backend, filename)) params = {} for kind, kind_name in zip([release, development], ["release", "development"]): for backend in backends: rows = [] for license in ["lgpl2.1+", "gpl3"]: if license in kind[backend]: rows.append([ LICENSES_SHORT[license], '<a href="downloads/%s">.tar.gz</a>' % (kind[backend][license][".tar.gz"][1]), '<a href="downloads/%s">.zip</a>' % (kind[backend][license][".zip"][1]) ]) if len(rows) == 0: rows = [["No %s distribution available" % kind_name]] params["%s%s" % (backend, kind_name)] = html_table(rows) return params
def find_matching_files(file_list, acc, pos): match_files = [] for fname in [f for f in file_list if f.startswith(acc)]: basename = splitext(fname)[0] res_range = basename.split("_")[-1] res_i = int(res_range.split("-")[0]) res_f = int(res_range.split("-")[1]) if res_i <= int(pos) <= res_f: match_files.append(fname) return match_files
def _get_download_content(self): asset_path = join(self.repo.path,"downloads") backends = ["freecad","openscad"] #find most current release release = {} development = {} for backend in backends: release[backend] = {} development[backend] = {} for filename in listdir(join(asset_path,backend)): basename,ext = splitext(filename) if ext == ".gz": ext = ".tar.gz" basename = splitext(basename)[0] parts = basename.split("_") version_string = parts[2] #some old development snapshots have no license in filename license = "none" if len(parts) > 3: license = parts[3] kind = development[backend] version = None try: version = int(version_string) except ValueError: version = float(version_string) kind = release[backend] if not license in kind: kind[license] = {} if not ext in kind[license]: kind[license][ext] = (version, join(backend,filename)) elif version > kind[license][ext][0]: kind[license][ext] = (version, join(backend,filename)) params = {} for kind,kind_name in zip([release, development], ["release","development"]): for backend in backends: rows = [] for license in ["lgpl2.1+","gpl3"]: if license in kind[backend]: rows.append([LICENSES_SHORT[license], '<a href="downloads/%s">.tar.gz</a>' % (kind[backend][license][".tar.gz"][1]), '<a href="downloads/%s">.zip</a>' % (kind[backend][license][".zip"][1])]) if len(rows) == 0: rows = [["No %s distribution available" % kind_name]] params["%s%s" % (backend, kind_name)] = html_table(rows) return params
def main(): global g_adv_length included_ads_nums = 0 save_result = "./d.txt" standrod_simple = "./ads_sample.png" # 广告截图标准图片 standord_v = compute_standord_simple_data(standrod_simple) regex = r"Duration:.+(\d\d:\d\d:\d\d\.\d\d)" g_adv_length = 6.5 # float(input("In vidoe at tails ,the adverisement duration times Long(ep. 5 seconds input 5 and Enter):")) curdir = input("Need to cut video directory : ") if os.path.exists(save_result): os.unlink(save_result) videofiles = get_videofiles(curdir) for file_name in videofiles: basename = os.path.basename(file_name) videosize = os.path.getsize(file_name) ext_name = os.path.splitext(file_name)[1] file_path = os.path.dirname(file_name) new_name = "%s/%s_%s" % (file_path, basename.split(".")[0], ext_name) duration = get_VideoDurationsByName(file_name) start_at = "00:00:00" total_seconds = get_seconds(duration) how_Long = format_TimeStyles(total_seconds - g_adv_length) print("duration=%s\nhow_Long=%s" % (duration, how_Long)) print("file_name=%s file_path=%s\nbasename=%s\nnew_name=%s" % (file_name, file_path, basename, new_name)) extract_pic_name = "%s/%s" % (file_path, "tmp_pic_%03d.png") #print(extract_pic_name) extract_at = format_TimeStyles(total_seconds - g_adv_length + 3) # 加3 使刚好落在广告期间 ads_time_s = "2" clear_curdir_Images(file_name) #清空图片 extract_AdsImages(file_name, extract_at, ads_time_s, extract_pic_name) # ads_time取广告视频区间任意位置中 2秒 中images sleep(1) crop_AdsImgs(file_path) #裁剪抽取出来的样本 similar_value = compute_image_similar2(standord_v, file_path) if similar_value == True: #含有广告 output = cut_VideoAds(file_name, new_name, start_at, how_Long, save_result) print("从视频中剔出广告视频,生成新视频文件 [ %s ]" % new_name) included_ads_nums += 1 print("\n") print("\n\n____________") print("Total vidoes = %s" % len(videofiles)) print("Included adversion videos have : %s" % included_ads_nums)
def _parse_page_basename(basename): """Split the page basename into the article id and locale. `basename` is (supposed to be) of the form `<article_id>.<locale>`, e.g. `news.en`. If either there is no dot or the locale is unknown, `babel.default_locale` is returned. :return: The tuple `(article_id, locale)`. """ default_locale = babel.default_locale components = basename.split('.') if len(components) == 1: return basename, default_locale article_id = '.'.join(components[:-1]) try: return article_id, Locale(components[-1]) except UnknownLocaleError: return basename, default_locale
def replace_extension(path, extension=''): dirname, basename = split(path) return join(dirname, basename.split('.')[0] + extension)
def filename_for_key(self, key): """ Returns the pickle storage filename corresponding to the job id """ basename = self.key2basename(key) components = "/".join(basename.split(':')) f = components + '/' + basename + self.file_extension return os.path.join(self.basepath, f)