def on_cut_play_clicked(self, widget, data=None): filename = self.gui.main_window.get_selected_filenames()[0] error, cutlists = cutlists_management.download_cutlists( filename, self.app.config.get('general', 'server'), self.app.config.get('general', 'choose_cutlists_by'), self.app.config.get('general', 'cutlist_mp4_as_hq')) if error: return cutlist = cutlists_management.get_best_cutlist(cutlists) cutlist.download(self.app.config.get('general', 'server'), filename) cutlist.read_cuts() # delete cutlist? if self.app.config.get('general', 'delete_cutlists'): fileoperations.remove_file(cutlist.local_filename) # make edl # https://github.com/mpv-player/mpv-player.github.io/blob/master/guides/edl-playlists.rst edlurl = "edl://" for count, (start, duration) in enumerate(cutlist.cuts_seconds): edlurl = edlurl + filename + "," + str(start) + "," + str( duration) + ";" p = subprocess.Popen([self.app.config.get_program('mpv'), edlurl]) while p.poll() == None: time.sleep(1) while Gtk.events_pending(): Gtk.main_iteration()
def on_cut_play_clicked(self, widget, data=None): filename = self.gui.main_window.get_selected_filenames()[0] error, cutlists = cutlists_management.download_cutlists( filename, self.app.config.get('general', 'server'), self.app.config.get('general', 'choose_cutlists_by'), self.app.config.get('general', 'cutlist_mp4_as_hq')) if error: return cutlist = cutlists_management.get_best_cutlist(cutlists) cutlist.download(self.app.config.get('general', 'server'), filename) cutlist.read_cuts() # delete cutlist? if self.app.config.get('general', 'delete_cutlists'): fileoperations.remove_file(cutlist.local_filename) # make edl # http://www.mplayerhq.hu/DOCS/HTML/en/edl.html # [Begin Second] [End Second] [0=Skip/1=Mute] edl_filename = os.path.join( self.app.config.get('general', 'folder_uncut_avis'), ".tmp.edl") f = open(edl_filename, "w") f.write("0 %s 0\n" % (cutlist.cuts_seconds[0][0] - 1)) for count, (start, duration) in enumerate(cutlist.cuts_seconds): end = start + duration if count + 1 == len(cutlist.cuts_seconds): f.write("%s 50000 0\n" % (end)) else: f.write("%s %s 0\n" % (end, (cutlist.cuts_seconds[count + 1][0] - 1))) f.close() p = subprocess.Popen([ self.app.config.get('general', 'mplayer'), "-edl", edl_filename, filename ]) while p.poll() == None: time.sleep(1) while gtk.events_pending(): gtk.main_iteration(False) fileoperations.remove_file(edl_filename)
def on_cut_play_clicked(self, widget, data=None): filename = self.gui.main_window.get_selected_filenames()[0] error, cutlists = cutlists_management.download_cutlists(filename, self.app.config.get('general', 'server'), self.app.config.get('general', 'choose_cutlists_by'), self.app.config.get('general', 'cutlist_mp4_as_hq')) if error: return cutlist = cutlists_management.get_best_cutlist(cutlists) cutlist.download(self.app.config.get('general', 'server'), filename) cutlist.read_cuts() # delete cutlist? if self.app.config.get('general', 'delete_cutlists'): fileoperations.remove_file(cutlist.local_filename) # make edl # http://www.mplayerhq.hu/DOCS/HTML/en/edl.html # [Begin Second] [End Second] [0=Skip/1=Mute] edl_filename = os.path.join(self.app.config.get('general', 'folder_uncut_avis'), ".tmp.edl") f = open(edl_filename, "w") f.write("0 %s 0\n" % (cutlist.cuts_seconds[0][0] - 1)) for count, (start, duration) in enumerate(cutlist.cuts_seconds): end = start + duration if count + 1 == len(cutlist.cuts_seconds): f.write("%s 50000 0\n" % (end)) else: f.write("%s %s 0\n" % (end, (cutlist.cuts_seconds[count+1][0] - 1))) f.close() p = subprocess.Popen([self.app.config.get('general', 'mplayer'), "-edl", edl_filename, filename]) while p.poll() == None: time.sleep(1) while gtk.events_pending(): gtk.main_iteration(False) fileoperations.remove_file(edl_filename)
def cut(self, file_conclusions, action, default_cut_action=None): # now this method may not return "False" self.gui.main_window.set_tasks_visible(True) self.gui.main_window.block_gui(True) if not default_cut_action: default_cut_action = self.config.get('general', 'cut_action') for count, file_conclusion in enumerate(file_conclusions): self.gui.main_window.set_tasks_text( "Cutlist %s/%s wählen" % (count + 1, len(file_conclusions))) self.gui.main_window.set_tasks_progress( (count + 1) / float(len(file_conclusions)) * 100) # file correctly decoded? if action == Action.DECODEANDCUT: if file_conclusion.decode.status != Status.OK: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Datei wurde nicht dekodiert." continue file_conclusion.cut.cut_action = default_cut_action if default_cut_action in [ Cut_action.ASK, Cut_action.CHOOSE_CUTLIST ]: # show dialog self.gui.dialog_cut.setup( file_conclusion.uncut_video, self.config.get('general', 'folder_cut_avis'), default_cut_action == Cut_action.ASK) cutlists = [] self.cutlists_error = False def error_cb(error): self.gui.dialog_cut.builder.get_object( 'label_status').set_markup("<b>%s</b>" % error) self.cutlists_error = True def cutlist_found_cb(cutlist): self.gui.dialog_cut.add_cutlist(cutlist) cutlists.append(cutlist) def completed(): if not self.cutlists_error: self.gui.dialog_cut.builder.get_object( 'label_status').set_markup("") GeneratorTask(cutlists_management.download_cutlists, None, completed).start( file_conclusion.uncut_video, self.config.get('general', 'server'), self.config.get('general', 'choose_cutlists_by'), self.config.get('general', 'cutlist_mp4_as_hq'), error_cb, cutlist_found_cb) response = self.gui.dialog_cut.run() self.gui.dialog_cut.hide() if response < 0: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Abgebrochen." else: # change cut_action accordingly file_conclusion.cut.cut_action = response if file_conclusion.cut.cut_action == Cut_action.MANUALLY: # MANUALLY error_message, cutlist = self.cut_file_manually( file_conclusion.uncut_video) if not error_message: file_conclusion.cut.create_cutlist = True file_conclusion.cut.upload_cutlist = True file_conclusion.cut.cutlist = cutlist else: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error_message elif file_conclusion.cut.cut_action == Cut_action.BEST_CUTLIST: error, cutlists = cutlists_management.download_cutlists( file_conclusion.uncut_video, self.config.get('general', 'server'), self.config.get('general', 'choose_cutlists_by'), self.config.get('general', 'cutlist_mp4_as_hq')) if error: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error continue if len(cutlists) == 0: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Keine Cutlist gefunden." continue file_conclusion.cut.cutlist = cutlists_management.get_best_cutlist( cutlists) elif file_conclusion.cut.cut_action == Cut_action.CHOOSE_CUTLIST: if self.gui.dialog_cut.chosen_cutlist is not None: file_conclusion.cut.cutlist = self.gui.dialog_cut.chosen_cutlist else: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Keine Cutlist gefunden." elif file_conclusion.cut.cut_action == Cut_action.LOCAL_CUTLIST: file_conclusion.cut.cutlist.local_filename = file_conclusion.uncut_video + ".cutlist" if not exists(file_conclusion.cut.cutlist.local_filename): file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = "Keine lokale Cutlist gefunden." elif file_conclusion.cut.cut_action == Cut_action.ASK: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Keine Cutlist gefunden." # and finally cut the file for count, file_conclusion in enumerate(file_conclusions): if file_conclusion.cut.status in [Status.NOT_DONE, Status.ERROR]: continue self.log.info("[Decodeandcut] Datei %s wird geschnitten" % file_conclusion.uncut_video) self.gui.main_window.set_tasks_text( "Datei %s/%s schneiden" % (count + 1, len(file_conclusions))) self.gui.main_window.set_tasks_progress(0) while Gtk.events_pending(): Gtk.main_iteration() # download cutlist if file_conclusion.cut.cut_action in [ Cut_action.BEST_CUTLIST, Cut_action.CHOOSE_CUTLIST ]: file_conclusion.cut.cutlist.download( self.config.get('general', 'server'), file_conclusion.uncut_video) cut_video, ac3_file, error = self.cut_file_by_cutlist( file_conclusion.uncut_video, file_conclusion.cut.cutlist, None) if cut_video is None: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error file_conclusion.cut.upload_cutlist = False else: file_conclusion.cut.status = Status.OK file_conclusion.cut_video = cut_video file_conclusion.ac3_file = ac3_file if self.config.get('general', 'rename_cut'): file_conclusion.cut.rename = self.rename_by_schema( basename(file_conclusion.cut_video) ) # rename after cut video, extension could have changed else: file_conclusion.cut.rename = basename(cut_video) if os.path.isfile(file_conclusion.uncut_video + '.ffindex_track00.kf.txt'): os.remove(file_conclusion.uncut_video + '.ffindex_track00.kf.txt') if os.path.isfile(file_conclusion.uncut_video + '.ffindex_track00.tc.txt'): os.remove(file_conclusion.uncut_video + '.ffindex_track00.tc.txt') return True
def on_cut_play_clicked(self, widget, data=None): filename = self.gui.main_window.get_selected_filenames()[0] error, cutlists = cutlists_management.download_cutlists( filename, self.app.config.get('general', 'server'), self.app.config.get('general', 'choose_cutlists_by'), self.app.config.get('general', 'cutlist_mp4_as_hq')) if error: return cutlist = cutlists_management.get_best_cutlist(cutlists) cutlist.download(self.app.config.get('general', 'server'), filename) cutlist.read_cuts() # delete cutlist? if self.app.config.get('general', 'delete_cutlists'): fileoperations.remove_file(cutlist.local_filename) # make mplayer edl # http://www.mplayerhq.hu/DOCS/HTML/en/edl.html # [Begin Second] [End Second] [0=Skip/1=Mute] edl_filename = os.path.join( self.app.config.get('general', 'folder_uncut_avis'), ".tmp.edl") f = open(edl_filename, "w") f.write("0 %s 0\n" % (cutlist.cuts_seconds[0][0] - 1)) for count, (start, duration) in enumerate(cutlist.cuts_seconds): end = start + duration if count + 1 == len(cutlist.cuts_seconds): f.write("%s 50000 0\n" % (end)) else: f.write("%s %s 0\n" % (end, (cutlist.cuts_seconds[count + 1][0] - 1))) f.close() # make mpv edl # https://github.com/mpv-player/mpv-player.github.io/blob/master/guides/edl-playlists.rst edlurl = "edl://" for count, (start, duration) in enumerate(cutlist.cuts_seconds): edlurl = edlurl + filename + "," + str(start) + "," + str( duration) + ";" def check_prog(prog): cmdfound = False plays = False if shutil.which(prog): cmdfound = True if not subprocess.call(prog, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT): plays = True else: self.log.error("{} failed to start.".format(prog)) else: exist = False self.log.error("{} is not installed.".format(prog)) return cmdfound and plays def play_with(prog): if prog == 'mplayer': p = subprocess.Popen([ self.app.config.get_program('mplayer'), "-edl", edl_filename, filename ]) elif prog == 'mpv': p = subprocess.Popen( [self.app.config.get_program('mpv'), edlurl]) if self.app.config.get('general', 'prefer_mpv'): self.playprog = ['mpv', 'mplayer'] else: self.playprog = ['mplayer', 'mpv'] if check_prog(self.playprog[0]): play_with(self.playprog[0]) elif check_prog(self.playprog[1]): play_with(self.playprog[1]) else: self.gui.message_error_box("Zum Anzeigen der Schnitte sind weder mpv noch mplayer " + \ "installiert bzw. funktionieren nicht.") return while p.poll() == None: time.sleep(1) while Gtk.events_pending(): Gtk.main_iteration() fileoperations.remove_file(edl_filename)
def cut(self, file_conclusions, action, default_cut_action=None): # now this method may not return "False" self.gui.main_window.set_tasks_visible(True) self.gui.main_window.block_gui(True) if not default_cut_action: default_cut_action = self.config.get('general', 'cut_action') for count, file_conclusion in enumerate(file_conclusions): self.gui.main_window.set_tasks_text("Cutlist %s/%s wählen" % (count + 1, len(file_conclusions))) self.gui.main_window.set_tasks_progress((count + 1) / float(len(file_conclusions)) * 100) # file correctly decoded? if action == Action.DECODEANDCUT: if file_conclusion.decode.status != Status.OK: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Datei wurde nicht dekodiert." continue file_conclusion.cut.cut_action = default_cut_action if default_cut_action in [Cut_action.ASK, Cut_action.CHOOSE_CUTLIST]: # show dialog self.gui.dialog_cut.setup( file_conclusion.uncut_video, self.config.get('general', 'folder_cut_avis'), default_cut_action == Cut_action.ASK) cutlists = [] self.cutlists_error = False def error_cb(error): self.gui.dialog_cut.builder.get_object('label_status').set_markup("<b>%s</b>" % error) self.cutlists_error = True def cutlist_found_cb(cutlist): self.gui.dialog_cut.add_cutlist(cutlist) cutlists.append(cutlist) def completed(): if not self.cutlists_error: self.gui.dialog_cut.builder.get_object('label_status').set_markup("") GeneratorTask(cutlists_management.download_cutlists, None, completed).start(file_conclusion.uncut_video, self.config.get('general', 'server'), self.config.get('general', 'choose_cutlists_by'), self.config.get('general', 'cutlist_mp4_as_hq'), error_cb, cutlist_found_cb) response = self.gui.dialog_cut.run() self.gui.dialog_cut.hide() if response < 0: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Abgebrochen." else: # change cut_action accordingly file_conclusion.cut.cut_action = response if file_conclusion.cut.cut_action == Cut_action.MANUALLY: # MANUALLY error_message, cutlist = self.cut_file_manually(file_conclusion.uncut_video) if not error_message: file_conclusion.cut.create_cutlist = True file_conclusion.cut.upload_cutlist = True file_conclusion.cut.cutlist = cutlist else: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error_message elif file_conclusion.cut.cut_action == Cut_action.BEST_CUTLIST: error, cutlists = cutlists_management.download_cutlists(file_conclusion.uncut_video, self.config.get('general', 'server'), self.config.get('general', 'choose_cutlists_by'), self.config.get('general', 'cutlist_mp4_as_hq')) if error: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error continue if len(cutlists) == 0: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Keine Cutlist gefunden." continue file_conclusion.cut.cutlist = cutlists_management.get_best_cutlist(cutlists) elif file_conclusion.cut.cut_action == Cut_action.CHOOSE_CUTLIST: if self.gui.dialog_cut.chosen_cutlist != None: file_conclusion.cut.cutlist = self.gui.dialog_cut.chosen_cutlist else: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Keine Cutlist gefunden." elif file_conclusion.cut.cut_action == Cut_action.LOCAL_CUTLIST: file_conclusion.cut.cutlist.local_filename = file_conclusion.uncut_video + ".cutlist" if not exists(file_conclusion.cut.cutlist.local_filename): file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = "Keine lokale Cutlist gefunden." elif file_conclusion.cut.cut_action == Cut_action.ASK: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Keine Cutlist gefunden." # and finally cut the file for count, file_conclusion in enumerate(file_conclusions): if file_conclusion.cut.status in [Status.NOT_DONE, Status.ERROR]: continue print "[Decodeandcut] Datei %s wird geschnitten" % file_conclusion.uncut_video self.gui.main_window.set_tasks_text("Datei %s/%s schneiden" % (count + 1, len(file_conclusions))) self.gui.main_window.set_tasks_progress(0) while events_pending(): main_iteration(False) # download cutlist if file_conclusion.cut.cut_action in [Cut_action.BEST_CUTLIST, Cut_action.CHOOSE_CUTLIST]: file_conclusion.cut.cutlist.download(self.config.get('general', 'server'), file_conclusion.uncut_video) cut_video, ac3_file, error = self.cut_file_by_cutlist(file_conclusion.uncut_video, file_conclusion.cut.cutlist) if cut_video == None: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error file_conclusion.cut.upload_cutlist = False else: file_conclusion.cut.status = Status.OK file_conclusion.cut_video = cut_video file_conclusion.ac3_file = ac3_file if self.config.get('general', 'rename_cut'): file_conclusion.cut.rename = self.rename_by_schema(basename(file_conclusion.cut_video)) # rename after cut video, extension could have changed else: file_conclusion.cut.rename = basename(cut_video) if os.path.isfile(file_conclusion.uncut_video + '.ffindex_track00.kf.txt'): os.remove(file_conclusion.uncut_video + '.ffindex_track00.kf.txt') return True
def cut(self, file_conclusions, action, default_cut_action=None): # now this method may not return "False" self.__gui.main_window.set_tasks_visible(True) self.__gui.main_window.block_gui(True) if not default_cut_action: default_cut_action = self.config.get('general', 'cut_action') for count, file_conclusion in enumerate(file_conclusions): self.__gui.main_window.set_tasks_text("Cutlist %s/%s wählen" % (count + 1, len(file_conclusions))) self.__gui.main_window.set_tasks_progress((count + 1) / float(len(file_conclusions)) * 100) # file correctly decoded? if action == Action.DECODEANDCUT: if file_conclusion.decode.status != Status.OK: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Datei wurde nicht dekodiert." continue file_conclusion.cut.cut_action = default_cut_action if default_cut_action in [Cut_action.ASK, Cut_action.CHOOSE_CUTLIST]: # show dialog self.__gui.dialog_cut.setup( file_conclusion.uncut_video, self.config.get('general', 'folder_cut_avis'), default_cut_action == Cut_action.ASK) cutlists = [] self.cutlists_error = False def error_cb(error): self.__gui.dialog_cut.builder.get_object('label_status').set_markup("<b>%s</b>" % error) self.cutlists_error = True def cutlist_found_cb(cutlist): self.__gui.dialog_cut.add_cutlist(cutlist) cutlists.append(cutlist) def completed(): if not self.cutlists_error: self.__gui.dialog_cut.builder.get_object('label_status').set_markup("") GeneratorTask(cutlists_management.download_cutlists, None, completed).start(file_conclusion.uncut_video, self.config.get('general', 'server'), self.config.get('general', 'choose_cutlists_by'), self.config.get('general', 'cutlist_mp4_as_hq'), error_cb, cutlist_found_cb) response = self.__gui.dialog_cut.run() self.__gui.dialog_cut.hide() if response < 0: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Abgebrochen." else: # change cut_action accordingly file_conclusion.cut.cut_action = response if file_conclusion.cut.cut_action == Cut_action.MANUALLY: # MANUALLY error_message, cuts, executable = self.cut_file_manually(file_conclusion.uncut_video) if not error_message: file_conclusion.cut.create_cutlist = True file_conclusion.cut.cutlist.cuts_frames = cuts file_conclusion.cut.cutlist.intended_app = basename(executable) file_conclusion.cut.cutlist.usercomment = 'Mit OTR-Verwaltung geschnitten' fps, error = self.__get_fps(file_conclusion.uncut_video) if not error: file_conclusion.cut.cutlist.fps = fps else: file_conclusion.cut.cutlist.fps = 25. print "Achtung! Möglicherweise wurde eine falsche Fps-Anzahl eingetragen! (%s)" % error # calculate seconds for start_frame, duration_frames in cuts: file_conclusion.cut.cutlist.cuts_seconds.append((start_frame / fps, duration_frames / fps)) else: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error_message elif file_conclusion.cut.cut_action == Cut_action.BEST_CUTLIST: error, cutlists = cutlists_management.download_cutlists(file_conclusion.uncut_video, self.config.get('general', 'server'), self.config.get('general', 'choose_cutlists_by'), self.config.get('general', 'cutlist_mp4_as_hq')) if error: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error continue if len(cutlists) == 0: file_conclusion.cut.status = Status.NOT_DONE file_conclusion.cut.message = "Keine Cutlist gefunden." continue file_conclusion.cut.cutlist = cutlists_management.get_best_cutlist(cutlists) elif file_conclusion.cut.cut_action == Cut_action.CHOOSE_CUTLIST: file_conclusion.cut.cutlist = self.__gui.dialog_cut.chosen_cutlist elif file_conclusion.cut.cut_action == Cut_action.LOCAL_CUTLIST: file_conclusion.cut.cutlist.local_filename = file_conclusion.uncut_video + ".cutlist" if not exists(file_conclusion.cut.cutlist.local_filename): file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = "Keine lokale Cutlist gefunden." # and finally cut the file for count, file_conclusion in enumerate(file_conclusions): if file_conclusion.cut.status in [Status.NOT_DONE, Status.ERROR]: continue print "[Decodeandcut] Datei %s wird geschnitten" % file_conclusion.uncut_video self.__gui.main_window.set_tasks_text("Datei %s/%s schneiden" % (count + 1, len(file_conclusions))) self.__gui.main_window.set_tasks_progress(0.5) # download cutlist if file_conclusion.cut.cut_action in [Cut_action.BEST_CUTLIST, Cut_action.CHOOSE_CUTLIST]: file_conclusion.cut.cutlist.download(self.config.get('general', 'server'), file_conclusion.uncut_video) cut_video, error = self.cut_file_by_cutlist(file_conclusion.uncut_video, file_conclusion.cut.cutlist) if cut_video == None: file_conclusion.cut.status = Status.ERROR file_conclusion.cut.message = error else: file_conclusion.cut.status = Status.OK file_conclusion.cut_video = cut_video if self.config.get('general', 'rename_cut'): file_conclusion.cut.rename = self.rename_by_schema(basename(file_conclusion.uncut_video)) else: file_conclusion.cut.rename = basename(cut_video) return True