def run(self, history, item_list, current_index, args): current = item_list[current_index] if len(args) != 2: print(self.help) return current_index start_time = args[0] end_time = args[1] output_fd, output_file = tempfile.mkstemp( suffix=os.path.splitext(current.transcoded_to)[1]) os.close(output_fd) try: worked = trim_audio(current.transcoded_to, output_file, start_time, end_time) if not worked: return current_index while True: print("p) play trimmed, K) keep trimmed, s) skip trimming") v = prompt_value('pKs') if v == 'p': get_media_player().play_file(output_file) if v == 'K': shutil.copyfile(output_file, current.transcoded_to) break if v == 's': break #except Exception as e: # print(str(e)) # print(e) # return current_index finally: os.unlink(output_file) return current_index
def run(self, history, item_list, current_index, args): current = item_list[current_index] if 'src' in args: source = current.source elif current.transcoded_to is None: print("No transcoded file for `{0}`".format(current.source)) return current_index else: source = current.transcoded_to if not os.path.isfile(source): print('Cannot find file `{0}`'.format(source)) else: get_media_player().play_file(source) return current_index
def run(self, history, item_list, current_index, args): current = item_list[current_index] output_fd, output_file = tempfile.mkstemp( suffix=os.path.splitext(current.transcoded_to)[1]) headroom = 0.1 if len(args) > 0: try: headroom = float(args[0]) if headroom < 0: print('headroom value must be a positive number.') return current_index except: print( 'headroom value must be a floating point value, read {0}'. format(args[0])) return current_index print("Normalizing file by {1:#.1f} into {0}".format( output_file, headroom)) os.close(output_fd) try: increase = normalize_audio(current.transcoded_to, output_file, headroom) if increase is None: print("Can't normalize.") return current_index print("Increased volume by {0}dB".format(increase)) while True: print( "p) play normalized, K) keep normalized, s) skip normalization" ) v = prompt_value('pKs') if v == 'p': get_media_player().play_file(output_file) if v == 'K': shutil.copyfile(output_file, current.transcoded_to) break if v == 's': break #except Exception as e: # print(str(e)) # print(e) # return current_index finally: os.unlink(output_file) return current_index
def run(self, history, item_list, current_index, args): # FIXME HAAAAAACK # This should be fetched from elsewhere. base_destdir = sys.argv[1] current = item_list[current_index] if not os.path.isfile(current.probe.filename): print("Original file does not exist anymore: {0}".format( current.probe.filename)) return current_index original = current.transcoded_to if original is not None and os.path.exists(original): os.unlink(original) verbose = '-v' in args destfile = transcode_correct_format(history, current.probe, get_destdir(base_destdir), verbose=verbose) if original != destfile: print( "[debug] replacing old transcode dest ({0}) with ({1})".format( original, destfile)) current.set_transcoded_to(destfile) print("New transcoded file recorded at {0}".format(destfile)) if '-norm' in args: output_fd, output_file = tempfile.mkstemp( suffix=os.path.splitext(destfile)[1]) try: headroom = 0.1 print("Normalizing file by {1:#.1f} into {0}".format( output_file, headroom)) os.close(output_fd) increase = normalize_audio(destfile, output_file, headroom) if increase is None: print("Can't normalize.") else: print("Increased volume by {0}dB".format(increase)) shutil.copyfile(output_file, destfile) finally: os.unlink(output_file) if "-np" not in args: get_media_player().play_file(destfile) return current_index
def run(self, history, item_list, current_index, args): do_commit = True do_play = True for a in args: if a == 'k': do_commit = False if a == 'n': do_play = False if do_commit: commit() next = min(len(item_list), current_index + 1) if do_play and next != current_index and next >= 0 and next < len( item_list): current = item_list[next] source = current.transcoded_to if source is not None: if not os.path.isfile(source): print('Cannot find file `{0}`'.format(source)) else: get_media_player().play_file(source) return next
def run(self, history, item_list, current_index, args): current = item_list[current_index] while True: dup_data = self._get_dups(current, history) if len(dup_data) <= 0: print("No duplicates left.") break print( "s) skip, l) list, u) unmark duplicate, p) play a duplicate's source file," ) print("m) mark another file as duplicate of this file") print("n) mark this file as a duplicate of another file") print("N) set new source, X) delete duplicate source file,") act = prompt_value("sldNX") if act == 's': break elif act == 'l': self._list_dups(current, dup_data) elif act == 'u': v = self._query_dup(current, dup_data) if v >= 0: history.delete_duplicate_id(dup_data[v]['duplicate_id']) print('{0} no longer a duplicate of {1}'.format( dup_data[v]['filename'], current.source)) elif act == 'p': v = self._query_dup(current, dup_data) if v >= 0: source = dup_data[v]['filename'] if not os.path.isfile(source): print('Cannot find file `{0}`'.format(source)) else: get_media_player().play_file(source) elif act == 'm': v = prompt_value("Source file which is a duplicate of this") if v >= 0: print("NOT IMPLEMENTED YET") elif act == 'N': v = self._query_dup(current, dup_data) if v >= 0: selected = dup_data[v] new_source_filename = dup_data[v]['filename'] history.mark_duplicate(current.probe, new_source_filename) for i in range(0, len(dup_data)): if i != v: dup = dup_data[i] dup_probe = CACHE.get(selected['filename']) history.delete_duplicate_id(dup['duplicate_id']) history.mark_duplicate(dup_probe.probe, new_source_filename) print('New source of duplicates is {0}'.format( new_source_filename)) elif act == 'X': v = self._query_dup(current, dup_data) if v >= 0: dup = dup_data[v] cfn = prompt_value("Y) Permanently Delete {0}".format( dup['filename'])) if cfn == 'Y': history.delete_duplicate_id(dup['duplicate_id']) history.delete_source_record(dup['filename']) if os.path.isfile(dup['filename']): os.unlink(dup['filename']) print('Permanently deleted {0}'.format( dup['filename'])) else: print('skipping permanent delete') return current_index