Last active
July 12, 2020 23:25
-
-
Save mclavan/27c0c204ff7ea721ee2cbcf9873d527e to your computer and use it in GitHub Desktop.
Maya Tool - Creates a time stamps for YouTube chapter markers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| mcChapterStamper.py | |
| Author: Michael Clavan | |
| https://gist.github.com/mclavan/27c0c204ff7ea721ee2cbcf9873d527e | |
| Description: | |
| Version 1.0 | |
| Creates a time stamp for youTubes chapter markers | |
| Chapters | |
| 00:00:00 - | |
| 00:00:12 - | |
| Version 1.1 | |
| Added the functionality to import an outline | |
| Version 1.2 | |
| Added the functionality to import a previous state. | |
| Version 1.3 | |
| Quality of life additions. | |
| - Outline doesn't get deleted and when restarting the timer. | |
| - Button added to clear outline. | |
| How to Run: | |
| import mcChapterStamper | |
| mcChapterStamper.gui() | |
| ''' | |
| import pymel.core as pm | |
| import time | |
| import pickle | |
| import os.path | |
| stamps = [] | |
| info = [] | |
| outline = [] | |
| start = 0.0 | |
| end = 0.0 | |
| script_path = pm.internalVar(userScriptDir=True) | |
| path = os.path.join(script_path, 'stampData.txt') | |
| def export_info(*args): | |
| outFile = open(path,'wb') | |
| pickle.dump(start, outFile) | |
| pickle.dump(stamps, outFile) | |
| pickle.dump(info, outFile) | |
| pickle.dump(outline, outFile) | |
| outFile.close() | |
| def import_info(*args): | |
| global start, stamps, info, outline | |
| inFile = open(path,'rb') | |
| start = pickle.load(inFile) | |
| stamps = pickle.load(inFile) | |
| info = pickle.load(inFile) | |
| outline = pickle.load(inFile) | |
| inFile.close() | |
| update_chapters() | |
| update_compile_list_widget() | |
| def compile_outline_gui(*args): | |
| global outline_field | |
| win_width = 400 | |
| win_height = 300 | |
| win_obj = pm.window(w=win_width, title='Compile Outliner') | |
| main_layout = pm.columnLayout() | |
| outline_field = pm.scrollField(w=win_width, h=win_height) | |
| pm.button(label='Apply', w=win_width, c=compile_list) | |
| win_obj.show() | |
| def compile_list(*args): | |
| global outline_info | |
| outline_info = outline_field.getText() | |
| outline_pieces = outline_info.split('\n') | |
| outline.extend(outline_pieces) | |
| update_compile_list_widget() | |
| export_info() | |
| def clear_outline(*args): | |
| global outline | |
| outline = [] | |
| update_compile_list_widget() | |
| export_info() | |
| def compile_list_widget(current_layout): | |
| global compile_dynList, compile_list_frame | |
| pm.setParent(current_layout) | |
| pm.button(label='Add Outline', w=win_width, c=compile_outline_gui) | |
| pm.button(label='Clear', w=win_width, c=clear_outline) | |
| pm.frameLayout(label='Outline List', width=win_width, parent=current_layout) | |
| compile_list_frame = pm.scrollLayout(width=win_width, height=150) | |
| compile_dynList = pm.columnLayout() | |
| pm.setParent(current_layout) | |
| def update_compile_list_widget(*args): | |
| global compile_dynList, compile_list_frame, outline | |
| pm.setParent(compile_list_frame) | |
| # Remove the dynamic list | |
| pm.deleteUI(compile_dynList) | |
| # Recreate the dynamic list | |
| compile_dynList = pm.columnLayout(parent=compile_list_frame) | |
| for current_piece in outline: | |
| pm.button(label=current_piece, w=win_width-5, command=pm.Callback(update_last_info, current_piece)) | |
| # pm.deleteUI(compile_dynList) | |
| # compile_dynList = pm.columnLayout() | |
| # for current_piece in outline_pieces: | |
| # pm.button() | |
| # pm.setParent(current_layout) | |
| def gui(): | |
| global chapter_field, win_width | |
| win_width = 300 | |
| win_height = 200 | |
| win_obj = pm.window(w=win_width, title='Chapter Stamper', menuBar=True) | |
| pm.menu( label='File' ) | |
| pm.menuItem( label='import', c=import_info ) | |
| main_layout = pm.columnLayout() | |
| col_width = win_width * .25 | |
| col1 = pm.rowColumnLayout(nc=2, cw=[[1, col_width], [2, win_width * .75]]) | |
| col2 = pm.columnLayout() | |
| pm.button(label='Start', c=start_timer, width=col_width - 5) | |
| pm.text(h=5, l='') | |
| pm.button(label='Stamp', w=col_width - 5, h=win_height, c=stamp) | |
| pm.setParent(col1) | |
| chapter_field = pm.scrollField(w=win_width * .75, h=win_height) | |
| compile_list_widget(main_layout) | |
| win_obj.show() | |
| def start_timer(*args): | |
| global start, stamps, info | |
| start = time.time() | |
| stamps = [] | |
| info = [] | |
| outline = [] | |
| line = '{2:02d}:{1:02d}:{0:02d}'.format(0, 0, 0) | |
| stamps.append(line) | |
| info.append('') | |
| update_chapters() | |
| export_info() | |
| def stamp(*args): | |
| global stampes | |
| current_stamp = time.time() # Get the current clock time | |
| seconds = int((current_stamp - start)%60) # Break up into seconds | |
| minutes = int((current_stamp - start)/60) # Break up into minutes (but it will expand beyond the hour marker) | |
| hours = minutes/60 # Break up into hours | |
| minutes =minutes % 60 # Now cut off any minutes over 60. | |
| line = '{2:02d}:{1:02d}:{0:02d}'.format(seconds, minutes, hours) | |
| stamps.append(line) | |
| info.append('') | |
| update_chapters() | |
| export_info() | |
| def update_last_info(new_info): | |
| global info | |
| info[-1] = new_info | |
| update_chapters() | |
| export_info() | |
| def end_timer(*args): | |
| global end | |
| end = time.time() | |
| print_chapters_end() | |
| def update_chapters(): | |
| line = '\nChapters\n\n' | |
| i = 0 | |
| for i in range(len(stamps)): | |
| line += '{0} - {1}\n'.format(stamps[i], info[i]) | |
| i += 1 | |
| # Add to scroll field | |
| chapter_field.setText(line) | |
| ''' | |
| # To be deleted | |
| def print_chapters_end(): | |
| line = '\nChapters\n\n' | |
| #line += '00:00:00 - \n' | |
| for stamp in stamps: | |
| seconds = int((stamp - start)%60) | |
| minutes = int((stamp - start)/60) | |
| hours = int(minutes/60) | |
| line += '{2:02d}:{1:02d}:{0:02d} - \n'.format(seconds, minutes, hours) | |
| seconds = int((end - start)%60) | |
| minutes = int((stamp - start)/60) | |
| hours = int(minutes/60) | |
| line += '{2:02d}:{1:02d}:{0:02d} - \n'.format(seconds, minutes, hours) | |
| chapter_field.setText(line) | |
| def print_chapters(): | |
| line = '\nChapters\n\n' | |
| #line += '00:00:00 - \n' | |
| for stamp in stamps: | |
| seconds = int((stamp - start)%60) | |
| minutes = int((stamp - start)/60) | |
| hours = int(minutes/60) | |
| line += '{2:02d}:{1:02d}:{0:02d} - \n'.format(seconds, minutes, hours) | |
| seconds = int((end - start)%60) | |
| minutes = int((stamp - start)/60) | |
| hours = int(minutes/60) | |
| line += '{2:02d}:{1:02d}:{0:02d} - \n'.format(seconds, minutes, hours) | |
| print line | |
| return line | |
| ''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment