def scrape(data): us_apps_filter = Filter( field='app_store_url', op=operator.contains, value='/us/' ) filter_chain = FilterChain() filter_chain.add_filter(us_apps_filter) us_apps = filter_chain.filter(data) gathered_data = gather_data(us_apps) spanish_and_tagalog_filter = ListContainedinListFilter( field='languages', op=operator.contains, value=[u'Spanish', u'Tagalog'] ) filter_chain = FilterChain() filter_chain.add_filter(spanish_and_tagalog_filter) spanish_and_tagalog_data = filter_chain.filter(gathered_data) insta_in_name_filter = CaseInsensitiveStringFilter( field='name', op=operator.contains, value='insta' ) filter_chain = FilterChain() filter_chain.add_filter(insta_in_name_filter) insta_in_name_data = filter_chain.filter(gathered_data) filtered_data = { 'apps_in_spanish_and_tagalog': [_d.get('app_identifier') for _d in spanish_and_tagalog_data], 'apps_with_insta_in_name': [_d.get('app_identifier') for _d in insta_in_name_data] } write_json_to_file(filtered_data, 'filtered_apps.json') write_json_to_file(gathered_data, 'apps.json')
def initFilter(self): self.chain = FilterChain() self.chain._filters.append( Filter(FilterType.LShelving, self.LOW_EQ, 0, 1, enabled=True)) # self.chain._filters.append(Filter(FilterType.HShelving, deffs[4], 0, 1, enabled = True)) # self.chain._filters.append(Filter(FilterType.Peak, deffs[0], 0, 1, enabled = True)) self.chain._filters.append( Filter(FilterType.Peak, self.HIGH_EQ, 0, 1, enabled=True)) # self.chain._filters.append(Filter(FilterType.LPButter, deffs[3], 0, 1, enabled = True)) # self.chain._filters.append(Filter(FilterType.HPButter, deffs[3], 0, 1, enabled = True)) self.chain.reset()
def initFilter(): global deffs, chain, fs chain = FilterChain() chain._filters.append( Filter(FilterType.LShelving, LOW_EQ, 0, 1, enabled=True)) # chain._filters.append(Filter(FilterType.HShelving, deffs[4], 0, 1, enabled = True)) # chain._filters.append(Filter(FilterType.Peak, deffs[0], 0, 1, enabled = True)) chain._filters.append(Filter(FilterType.Peak, HIGH_EQ, 0, 1, enabled=True)) # chain._filters.append(Filter(FilterType.LPButter, deffs[3], 0, 1, enabled = True)) # chain._filters.append(Filter(FilterType.HPButter, deffs[3], 0, 1, enabled = True)) chain.reset()
def __init__(self, frag=None, filters=None): """The ``frag`` argument must be a :py:class:`splat.data.Fragment` instance. If `None`, a default empty fragment will be automatically created (2 channels, 48kHz). A chain of ``filters`` can also be initialised here with a list of filter functions and internally create a :py:meth:`splat.filters.FilterChain` object. This can be altered later via :py:attr:`splat.gen.Generator.filters`. """ self.frag = frag self._filter_chain = FilterChain(filters) self._levels = 1.0
def concat_videos(list, outdir=None, ffmpeg='ffmpeg', audio=True): dir = outdir if outdir else os.path.dirname(os.path.realpath(__file__)) videos = _download_file_list(list, dir) if bool(videos) == False: return None # make the video files list file_name = os.path.normpath(os.path.join(dir, str(uuid.uuid4()))) with open(file_name, 'w') as file: for video in videos: file.write("file '" + video + "'\n") # concatenate the videos output = os.path.normpath(os.path.join(dir, "video.mp4")) ff = FFmpeg(executable=ffmpeg, global_options=[ "-y", "-f", "concat", "-safe", "0", "-protocol_whitelist", "file,http,https,tcp,tls" ], inputs={file_name: None}, outputs={output: "-c copy"}) #print ff.cmd out = ff.run() # if audio background is requested we will try to get duration of movie and matching audio file if audio == True: # collect data for concatenated movie total duration length = time.strptime( re.findall("(?<=time\\=)[0-9.:]+", out)[-1], "%H:%M:%S.%f") lenght_t = datetime.timedelta(hours=length.tm_hour, minutes=length.tm_min, seconds=length.tm_sec).total_seconds() inputs = OrderedDict([(output, None)]) applied_filters = ["[0:v]null[video]"] audio_track = _get_audio(lenght_t, dir) # build the filter chain and execute it audioseq = FilterChain([ ReplicateAudioFilter( repetitions=int(math.ceil(lenght_t / float(audio_track[1])))), ConcatFilter(is_video=False, outputtag="caf"), TrimAudioFilter(length=lenght_t), FadeOutAudioFilter(start=lenght_t - AUDIO_FADE_OUT_T, length=AUDIO_FADE_OUT_T, outstreamprefix="audio") ]) applied_filters += audioseq.generate(["1:a"])[0] # add the audio track to the inputs collection inputs.update({audio_track[0]: None}) # build the video output = os.path.normpath(os.path.join(dir, "videoa.mp4")) ff = FFmpeg(executable=ffmpeg, global_options=["-y"], inputs=inputs, outputs={ output: "-filter_complex \"" + ";".join(applied_filters) + "\" -map \"[video]\" -map \"[audio]\"" }) #print ff.cmd ff.run() return output
def _make(images, scene_duration, dir, ffmpeg, width, height, audio, effect, transition, batch_mode): # exit if no images were found if bool(images) == False: return None scene_duration_f = scene_duration * FPS w = width / 2 * 2 if width != None else -2 if height != None else OUTPUT_VIDEO_WIDTH h = height / 2 * 2 if height != None else -2 if width != None else OUTPUT_VIDEO_HEIGHT # build the animation dictionary of filters and first slide handling flag animations = { "zoompan": (CombiningFilter([ ZoompanEffectFilter(maxzoom=MAX_ZOOM, frames=scene_duration_f), ImageSlideFilter(duration=scene_duration, width=w, height=h) ], outstreamprefix="zpaf"), False), "fadeinout": (CombiningFilter([ FadeTransitionFilter(transition_duration=TRANSITION_T, total_duration=scene_duration), ImageSlideFilter(duration=scene_duration, width=w, height=h) ], outstreamprefix="faf"), False), "zoompanfadeinout": (CombiningFilter([ ZoompanEffectFilter(maxzoom=MAX_ZOOM, frames=scene_duration_f), FadeTransitionFilter(transition_duration=TRANSITION_T, total_duration=scene_duration), ImageSlideFilter(duration=scene_duration, width=w, height=h) ], outstreamprefix="zpfaf"), False), "slidein": (FilterChain([ ImageSlideFilter(duration=scene_duration, width=w, height=h), SlideTransitionFilter( transition_duration=TRANSITION_T, preserve_first=batch_mode != BatchMode.non_initial_batch) ]), True), "zoompanslidein": (ZoompanSlideInTransitionFilter( transition_duration=TRANSITION_T, total_duration=scene_duration, fps=FPS, width=w, height=h, maxzoom=MAX_ZOOM, preserve_first=batch_mode != BatchMode.non_initial_batch), True) } animationkey = (effect if effect else "") + (transition if transition else "") animation = animations[animationkey] if animationkey in animations else None # determines if transition is requested and how to interpret the inputs list preserve_first_slide = animation[1] if animation else False if batch_mode != BatchMode.non_initial_batch: slides = images lenght_t = scene_duration * len(slides) elif preserve_first_slide: slides = images lenght_t = scene_duration * (len(slides) - 1) else: slides = images[1:] lenght_t = scene_duration * len(slides) inputs = OrderedDict([(i, "-loop 1") for i in slides]) # create the video filter chain videoseq = FilterChain() if animation: videoseq.append(animation[0]) else: videoseq.append( ImageSlideFilter(duration=scene_duration, width=w, height=h)) videoseq.append(ConcatFilter(True, "video")) applied_filters = videoseq.generate( ["%d:v" % i for (i, x) in enumerate(inputs)])[0] # load audio track if requested if audio == True: audio_track = _get_audio(lenght_t, dir) # build the filter chain and execute it audioseq = FilterChain([ ReplicateAudioFilter( repetitions=int(math.ceil(lenght_t / float(audio_track[1])))), ConcatFilter(is_video=False, outputtag="caf"), TrimAudioFilter(length=lenght_t), FadeOutAudioFilter(start=lenght_t - AUDIO_FADE_OUT_T, length=AUDIO_FADE_OUT_T, outstreamprefix="audio") ]) applied_filters += audioseq.generate(["%d:a" % len(inputs)])[0] # add the audio track to the inputs collection inputs.update({audio_track[0]: None}) # build the video output = "video.mp4" output = dir + "/" + output if dir else output ff = FFmpeg(executable=ffmpeg, global_options=["-y"], inputs=inputs, outputs={ output: "-filter_complex \"" + ";".join(applied_filters) + "\" -map \"[video]\"" + (" -map \"[audio]\"" if audio == True else "") + " -c:v libx264 -pix_fmt yuvj420p -q:v 1" }) #print ff.cmd ff.run() return output
def filters(self, filters): self._filter_chain = FilterChain(filters)
def __init__(self, *args): QWidget.__init__(self, *args) self.setFixedSize(1000,500) self.setWindowTitle('EQ') self.show() layout = QVBoxLayout(self) #--------- track controls ----------- open_btn = QPushButton('Load file') open_btn.clicked.connect(self.onOpenBtnClick) self.path_label = QLabel('') self.loop_box = QCheckBox('Loop') play_btn = QPushButton('Play') play_btn.clicked.connect(self.onPlayBtnClick) stop_btn = QPushButton('Stop') stop_btn.clicked.connect(self.onStopBtnClick) save_btn = QPushButton('Apply EQ and save') save_btn.clicked.connect(self.onSaveBtnClick) trackctrl_layout = QHBoxLayout() trackctrl_layout.addWidget(open_btn) trackctrl_layout.addWidget(self.path_label) trackctrl_layout.addWidget(play_btn) trackctrl_layout.addWidget(stop_btn) trackctrl_layout.addWidget(self.loop_box) trackctrl_layout.addSpacing(50) trackctrl_layout.addWidget(save_btn) layout.addLayout(trackctrl_layout) #--------- plot ------------ self.plotwin = PlotWin(self) layout.addWidget(self.plotwin) #--------- filter controls ---------- sub_layout = QHBoxLayout() labels_layout = QVBoxLayout() labels_layout.addWidget(QLabel('Filter type')) labels_layout.addWidget(QLabel('Cutoff/Center')) labels_layout.addWidget(QLabel('Gain')) labels_layout.addWidget(QLabel('Q or Slope')) sub_layout.addLayout(labels_layout) self.nodes = [] deffs = [100, 1000, 3000, 5000, 15000] for i in range(0,5): filter_list = QComboBox() filter_list.addItems(list(filterTypes.values())) if i == 0: filter_list.setCurrentIndex(FilterType.HPBrickwall) elif i == 4: filter_list.setCurrentIndex(FilterType.LPBrickwall) else: filter_list.setCurrentIndex(FilterType.Peak) checkbox = QCheckBox('On') freq_txt = QLineEdit(str(deffs[i])) freq_txt.setValidator(QIntValidator(self.plotwin.xaxis.min, self.plotwin.xaxis.max, self)) gain_txt = QLineEdit('0') gain_txt.setValidator(QDoubleValidator(-12, 12, 1, self)) q_slider = QSlider(Qt.Horizontal) node = NodeLayout(i, self) node.addControls(checkbox, filter_list, freq_txt, gain_txt, q_slider) node.setControlsEnabled(False) self.nodes.append(node) sub_layout.addLayout(node) node.enabled.connect(self.onFilterEnableChange) node.updated.connect(self.paramChanged) layout.addLayout(sub_layout) #------------------------------------ self.setLayout(layout) #----------- Filters ---------------- self.chain = FilterChain() deffs = [fc * 2 / fs for fc in deffs] self.chain._filters.append(Filter(FilterType.HPBrickwall, deffs[0], enabled = False)) self.chain._filters.append(Filter(FilterType.Peak, deffs[1], enabled = False)) self.chain._filters.append(Filter(FilterType.Peak, deffs[2], enabled = False)) self.chain._filters.append(Filter(FilterType.Peak, deffs[3], enabled = False)) self.chain._filters.append(Filter(FilterType.LPBrickwall, deffs[4], enabled = False)) self.updateChainTF() self.plotwin.updateHandles() self.stream = None self.wf = None