Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- How to install: https://gist.github.com/DmitriySalnikov/016648a478f668c48a0322e1051147ca#file-readme-md
- ------------------------------------------------------------------------------
- -- by Dmitriy Salnikov
- -- GitHub: https://github.com/DmitriySalnikov
- -- Youtube: https://www.youtube.com/channel/UCUPGXIVLD2jxML3L1qqkoEw
- --
- -- Config:
- --
- -- The first title is at 00:00 if the marker is not found
- firstTitle = "Intro"
- -- Filter by marker color (true) or by name (false)
- isFilterByColor = true
- -- Color filter for markers
- -- Available marker colors (ordered like in Davinci): Blue, Cyan, Green, Yellow,
- -- Red, Pink, Purple, Fuchsia, Rose, Lavender, Sky, Mint, Lemon, Sand, Cocoa, Cream
- colorFilter = "Cream"
- -- Name filter for markers
- -- Any string that Davinci can accept as Name of marker is allowed
- nameFilter = "Timecode"
- -- Enable (true) or disable (false) resulting dialog
- showCopyDialog = true
- -- Enable (true) or disable (false) console output
- printToConsole = false
- ------------------------------------------------------------------------------
- -- The Linux copy to clipboard command is "xclip"
- -- This requires a custom xclip tool install on Linux:
- -- Debian/Ubuntu:
- -- sudo apt-get install xclip
- -- Redhat/Centos/Fedora:
- -- yum install xclip
- ------------------------------------------------------------------------------
- -- Initialization
- local platform = (FuPLATFORM_WINDOWS and "Windows") or
- (FuPLATFORM_MAC and "Mac") or
- (FuPLATFORM_LINUX and "Linux")
- local result = ""
- local p = Resolve():GetProjectManager():GetCurrentProject()
- local t = p:GetCurrentTimeline()
- local m = t:GetMarkers()
- local timelineFPS = t:GetSetting("timelineFrameRate")
- local isLongerThanOneHour = (t:GetEndFrame() / (timelineFPS * 60.0 * 60.0) %
- (60.0 * 60.0)) >= 1.0
- local exitCode = 0
- -- Auto formatted by VS Code...
- ------------------------------------------------------------------------------
- function FrameToText(frame)
- local res = ""
- if isLongerThanOneHour then
- res = res ..
- string.format("%02d", (frame / (timelineFPS * 60.0 * 60.0)) %
- (60.0 * 60.0)) .. ":"
- end
- res = res .. string.format("%02d", (frame / (timelineFPS * 60.0)) % 60.0) ..
- ":" .. string.format("%02d", (frame / timelineFPS) % 60.0)
- return res
- end
- -- https://gist.github.com/AndrewHazelden/b9909520490624305183f7c8f77368a2
- function CopyToClipboard(textString)
- local outputDirectory = app:MapPath('Temp:/CopyTimecodebyMarkerstoClipboard/')
- local clipboardTempFile = outputDirectory .. 'ClipboardText.txt'
- os.execute('mkdir "' .. outputDirectory .. '"')
- local outClipFile, err = io.open(clipboardTempFile, 'w')
- if err then
- print("[Error Opening Clipboard Temporary File for Writing]")
- return
- end
- outClipFile:write(textString, '\n')
- outClipFile:close()
- local command = ""
- if platform == 'Windows' then
- -- Windows requires powershell to support utf8 encoding
- command = 'powershell -command "Get-Content -Encoding utf8 \'' ..
- clipboardTempFile .. '\' | Set-Clipboard"'
- elseif platform == 'Mac' then
- command = 'pbcopy < "' .. clipboardTempFile .. '"'
- elseif platform == 'Linux' then
- command = 'cat "' .. clipboardTempFile ..
- '" | xclip -selection clipboard &'
- end
- if printToConsole then
- print('[Copy Text to Clipboard Command] ' .. command)
- print('[Clipboard]\n' .. textString)
- end
- exitCode = os.execute(command)
- end
- function CheckMarker(marker)
- return (isFilterByColor and marker.color == colorFilter) or
- (not isFilterByColor and marker.name == nameFilter)
- end
- ------------------------------------------------------------------------------
- -- First timecode
- if not (m[0] ~= nil and CheckMarker(m[0])) then
- result = FrameToText(0) .. " " .. firstTitle .. "\n"
- end
- -- Sort markers by time
- -- https://stackoverflow.com/a/26166560/8980874
- local tkeys = {}
- for k in pairs(m) do table.insert(tkeys, k) end
- table.sort(tkeys)
- -- Generate resulting text
- for _, k in ipairs(tkeys) do
- local val = m[k]
- if CheckMarker(val) then
- result = result .. FrameToText(k) .. " " ..
- (isFilterByColor and val.name or val.note) .. "\n"
- end
- end
- result = result:sub(1, -2)
- CopyToClipboard(result)
- ------------------------------------------------------------------------------
- -- Resulting Dialog
- -- https://www.steakunderwater.com/wesuckless/viewtopic.php?f=6&t=1411
- if showCopyDialog then
- local ui = fu.UIManager
- local disp = bmd.UIDispatcher(ui)
- local width, height = 550, 600
- local win = disp:AddWindow({
- ID = 'CopyDialog',
- WindowTitle = 'Copy Timecodes by Markers',
- Geometry = {100, 100, width, height},
- Spacing = 0,
- Margin = 0,
- ui:VGroup{
- ID = 'root',
- ui:TextEdit{
- ID = 'TE',
- Weight = 0.5,
- HTML = [[<h1>Copy Timecodes by Markers</h1>
- <p><strong>Version 1.0</strong></p>
- <p>by Dmitriy Salnikov<br/>
- GitHub: <a href="https://github.com/DmitriySalnikov">https://github.com/DmitriySalnikov</a><br/>
- Youtube: <a href="https://www.youtube.com/channel/UCUPGXIVLD2jxML3L1qqkoEw">https://www.youtube.com/channel/UCUPGXIVLD2jxML3L1qqkoEw</a></p>]] ..
- ((exitCode == 0 or exitCode == true) and
- '<p>The resulting text has already been copied to the clipboard, if not, you can copy it yourself below.</p>' or
- '<p>The resulting text could not be copied to the clipboard automatically, but you can copy it by yourself below.</p>') ..
- '<p><strong>Result:</strong></p><hr/><br/><code>' ..
- result:gsub("\n", "<br/>") .. '</code>',
- ReadOnly = true
- }
- }
- })
- function win.On.CopyDialog.Close(ev) disp:ExitLoop() end
- win:Show()
- disp:RunLoop()
- win:Hide()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement