Skip to content

Commit

Permalink
v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Thuan Pham committed Dec 17, 2023
1 parent ff4689d commit 30a73d5
Show file tree
Hide file tree
Showing 4 changed files with 2,976 additions and 44 deletions.
31 changes: 3 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,7 @@ Live demo: https://www.youtube.com/watch?v=_-s7AZpUv4A

## Install

> Right now I only test on Windows, which means this Just works. If you use other OS (MacOS, Linux,
TempleOS, etc...) Refer read the docs below provided by the author OR you know what you doing.

> Copy and paste in PowerShell
```pwsh
git clone https://github.com/ongedit/snap-captions/
cd snap-captions
cp "Snap Captions.lua" "$env:appdata\Blackmagic Design\DaVinci Resolve\Support\Fusion\Scripts\Comp\"
ii ./fonts/
```

OR

```pwsh
./install.ps1
```

1. Open the [fonts/](./fonts/) folder
2. Select all
3. Right click
4. Select install
5. Make sure Davinci Resolve isn't opening (because it's needs loading the font)
6. Open the `Snap Captions Index.drb` (if some issue happen just restart the davinci resole)


Copy the Snap Captions bin into the power bin for easy import or just click this `.drb` file every time you new project
watch this: <https://www.youtube.com/watch?v=Arsw6quCMcA>

## Dev

Expand All @@ -47,6 +22,6 @@ Copy the Snap Captions bin into the power bin for easy import or just click this

## Docs

- Snap Caption script v1.3
- Snap Caption script v1.4
- Link to Snap Captions <https://ko-fi.com/s/67e49a15e7>
- https://mediable.notion.site/Snap-Captions-Install-Guide-f39ead46635148d9bd4c4e1052c43d19
- <https://mediable.notion.site/Snap-Captions-Install-Guide-f39ead46635148d9bd4c4e1052c43d19>
71 changes: 57 additions & 14 deletions Snap Captions.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Copyright (C) 2023 Orson Lord & Dan Knowlton
--
-- Snap Captions v1.3
-- Snap Captions v1.4
-- This tool automates the process of creating Text+ clips from subtitle
-- clips.
--
Expand All @@ -11,6 +11,10 @@
-- permission of the authors.


local utf8 = string
local hasUtf8Support = false


local ui = fu.UIManager
local disp = bmd.UIDispatcher(ui)

Expand Down Expand Up @@ -52,6 +56,22 @@ end

local SCRIPT_INSTALLED = ScriptIsInstalled()


local function LoadUTF8Module()
-- Remove any previously loaded utf8 module.
package.loaded.utf8_snapcaptions = nil

hasUtf8Support, utf8 = pcall(require, "utf8_snapcaptions")
if not hasUtf8Support and SCRIPT_INSTALLED then
print("[WARNING]: Snap Captions utf8 module could not be loaded. " ..
"Please ensure that the utf8_snapcaptions.lua file exists in " ..
"the Modules/Lua folder.")
utf8 = string
end
end
LoadUTF8Module()


local COLUMN_WIDTH = 130
local WINDOW_WIDTH = 320
local WINDOW_HEIGHT = 356
Expand Down Expand Up @@ -273,27 +293,43 @@ local function CreateDialog(title, message)
end


local function CopyFile(source, target)
local source_file = io.open(source, "r")
local contents = source_file:read("*a")
source_file:close()

local target_file = io.open(target, "w")
if target_file == nil then
return false
end
target_file:write(contents)
target_file:close()

return true
end


local function InstallScript()
local source_path = script_path()
local target_path = nil
local modules_path = nil
if platform == "Windows" then
target_path = os.getenv("APPDATA") .. "\\Blackmagic Design\\DaVinci Resolve\\Support\\Fusion\\Scripts\\Comp\\"
modules_path = os.getenv("APPDATA") .. "\\Blackmagic Design\\DaVinci Resolve\\Support\\Fusion\\Modules\\Lua\\"
elseif platform == "Mac" then
target_path = os.getenv("HOME") .. "/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Comp/"
modules_path = os.getenv("HOME") .. "/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Modules/Lua/"
else
target_path = os.getenv("HOME") .. "/.local/share/DaVinciResolve/Fusion/Scripts/Comp/"
modules_path = os.getenv("HOME") .. "/.local/share/DaVinciResolve/Fusion/Modules/Lua/"
end

local script_name = source_path:match(".*[/\\](.*)")
target_path = target_path .. script_name

-- Copy the file.
local source_file = io.open(source_path, "r")
local contents = source_file:read("*a")
source_file:close()

local target_file = io.open(target_path, "w")
if target_file == nil then
local success = CopyFile(source_path, target_path)
if not success then
local dialog = CreateDialog("Failed to install Snap Captions",
"Snap Captions could not be installed automatically. " ..
"Please manually copy to the Scripts/Comp folder.")
Expand All @@ -302,8 +338,15 @@ local function InstallScript()
return false
end

target_file:write(contents)
target_file:close()
-- Also copy the utf8 modules to the Modules folder.
local utf8_source = source_path:match("(.*[/\\]).+$") .. "utf8_snapcaptions.lua"
local utf8_target = modules_path .. "utf8_snapcaptions.lua"
success = CopyFile(utf8_source, utf8_target)

if success then
-- Reload the utf8 module.
LoadUTF8Module()
end

print("[Snap Captions] Installed to " .. target_path)
return true
Expand Down Expand Up @@ -533,17 +576,17 @@ end


local function ToTitleCase(first, rest)
return first:upper()..rest:lower()
return utf8.upper(first)..utf8.lower(rest)
end


local function ApplyTextTransform(text, transform)
if transform == "To Lowercase" then
return string.lower(text)
return utf8.lower(text)
elseif transform == "To Uppercase" then
return string.upper(text)
return utf8.upper(text)
elseif transform == "Capitalize All Words" then
return text:gsub("(%a)([%w_']*)", ToTitleCase)
return utf8.gsub(text, "(%a)([%w_']*)", ToTitleCase)
else
return text
end
Expand Down Expand Up @@ -762,7 +805,7 @@ local function CreateToolWindow()
local win = disp:AddWindow(
{
ID = winID,
WindowTitle = "Snap Captions V1.3",
WindowTitle = "Snap Captions v1.4",
Geometry = {nil, nil, WINDOW_WIDTH, WINDOW_HEIGHT},
Margin = 16,

Expand Down
2 changes: 0 additions & 2 deletions install.ps1

This file was deleted.

Loading

0 comments on commit 30a73d5

Please sign in to comment.