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 _cmd(self, history, args): for fn in history.get_source_files(): tn = history.get_transcoded_to(fn) if tn is None: continue local_tn = reverse_tcode(tn) if (not _do_check_file(fn, args) and not _do_check_file(tn, args) and not _do_check_file(reverse_tcode(tn), args) ): continue print(fn) fn_tags = history.get_tags_for(fn) print('- Tags: {0}'.format(repr(fn_tags))) adjusted_tags = False while True: tag_name = prompt_value('Tag to edit (empty to continue)') if tag_name is None: break tag_name = tag_name.strip() tag_value = prompt_value('New value') if tag_value is None: if tag_name in fn_tags: del fn_tags[tag_name] adjusted_tags = True else: fn_tags[tag_name] = tag_value adjusted_tags = True if adjusted_tags: if FF_PROBES.is_supported(fn): # Fix the source, too. try: set_tags_on_file(fn, fn_tags) # TODO This will make the checksums wrong, but, meh. except Exception as e: OUTPUT.error("Couldn't update tags on source file {0} ({1})".format( fn, e )) set_tags_on_file(local_tn, fn_tags) history.set_tags_for(fn, fn_tags) return 0
def _query_dup(self, current, dup_data): while True: v = prompt_value("s) skip, l) list, 1-{0}) select index".format( len(dup_data))) if v == 's': return -1 if v == 'l': self._list_dups(current, dup_data) continue try: pos = int(v) - 1 if pos >= 0 and pos < len(dup_data): return pos except: pass
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 _cmd(self, history, args): global CACHE CACHE = MediaCache(history) item_list = [] running = True current_index = 0 while running: current = None options = {} HELP_ACTION.current_options = options add_actions_to_options(ACTIONS_ANY, options) prompt = "(empty list)" if len(item_list) > 0: add_actions_to_options(ACTIONS_WITH_LIST, options) if current_index < len(item_list) and current_index >= 0: current = item_list[current_index] prompt = "(at list end)" if current is not None: prompt = "{0}\n{2}/{1}".format(current.source, len(item_list) - 1, current_index) add_actions_to_options(ACTIONS_WITH_CURRENT, options) text = None while text is None or len(text) <= 0: text = prompt_value(prompt) try: p = shlex.split(text, False) except Exception as e: print("Invalid command: {0}".format(e)) continue if p[0] not in options: print("Unknown command: {0}".format(p[0])) print("Use '?' for help.") continue else: res = options[p[0]].run(history, item_list, current_index, p[1:]) if res == RESULT_QUIT: running = False elif res is not None: current_index = res commit()
def _cmd(self, history, args): tag_names = args[0] args = args[1] for fn in history.get_source_files_without_tag_names(tag_names): tn = history.get_transcoded_to(fn) if tn is None: continue if not _do_check_file(fn, args) and not _do_check_file(tn, args): continue print(fn) print(' -> {0}'.format(tn)) fn_tags = history.get_tags_for(fn) print('- Tags: {0}'.format(repr(fn_tags))) adjusted_tags = False for t in tag_names: if t not in fn_tags or len(fn_tags[t].strip()) <= 0: tv = prompt_value(t) if tv is not None: fn_tags[t] = tv adjusted_tags = True else: print("Already handled {0}".format(t)) if adjusted_tags: if FF_PROBES.is_supported(fn): # Fix the source, too. try: set_tags_on_file(fn, fn_tags) # TODO This will make the checksums wrong, but, meh. except Exception as e: OUTPUT.error("Couldn't update tags on source file {0} ({1})".format( fn, e )) set_tags_on_file(tn, fn_tags) history.set_tags_for(fn, fn_tags) print("Finished with tag handling") return 0
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