Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thumbfast integration #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This theme replaces [the built in `osc.lua`](https://github.com/mpv-player/mpv/b

![](https://i.imgur.com/cYqWlw5.png)

Local files can show thumbnail previews (using a patched version of [mpv_thumbnail_script](https://github.com/TheAMM/mpv_thumbnail_script)).
Local files can show thumbnail previews (using [thumbfast](https://github.com/po5/thumbfast) or a patched version of [mpv_thumbnail_script](https://github.com/TheAMM/mpv_thumbnail_script)).

![](https://i.imgur.com/FegXl3W.png)

Expand Down
52 changes: 44 additions & 8 deletions osc_tethys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ local tethys = {
}
read_options(tethys, "tethys")

local thumbfast = {
width = 0,
height = 0,
disabled = true,
available = false
}

local function parseColor(color)
if string.find(color, "#") then
local colorU = string.upper(color)
Expand Down Expand Up @@ -1513,6 +1520,8 @@ function Thumbnailer:register_client()
-- Notify workers to generate thumbnails when video loads/changes
-- This will be executed after the on_video_change (because it's registered after it)
mp.observe_property("video-dec-params", "native", function()
if thumbfast.available then return end

local duration = mp.get_property_native("duration")
local max_duration = thumbnailer_options.autogenerate_max_duration

Expand All @@ -1526,6 +1535,8 @@ function Thumbnailer:register_client()

local thumb_script_key = not thumbnailer_options.disable_keybinds and "T" or nil
mp.add_key_binding(thumb_script_key, "generate-thumbnails", function()
if thumbfast.available then return end

if self.state.available then
mp.osd_message("Started thumbnailer jobs")
self:start_worker_jobs()
Expand Down Expand Up @@ -1845,8 +1856,8 @@ function renderThumbnailTooltip(pos, sliderPos, ass)
if thumb_size == nil then
return
end
local thumbGlobalWidth = thumb_size.w
local thumbGlobalHeight = thumb_size.h
local thumbGlobalWidth = thumbfast.available and thumbfast.width or thumb_size.w
local thumbGlobalHeight = thumbfast.available and thumbfast.height or thumb_size.h
local thumbWidth = math.floor(thumbGlobalWidth * scaleX)
local thumbHeight = math.floor(thumbGlobalHeight * scaleY)

Expand Down Expand Up @@ -1923,14 +1934,11 @@ function renderThumbnailTooltip(pos, sliderPos, ass)
ass:append(timestampLabel)

-- If thumbnails are not available, bail
if not (Thumbnailer.state.enabled and Thumbnailer.state.available) then
if not thumbfast.available and not (Thumbnailer.state.enabled and Thumbnailer.state.available) then
return
end

local thumbPath, thumbIndex, closestIndex = Thumbnailer:get_thumbnail_path(thumbTime)
-- msg.warn("renderThumbnailTooltip", thumbIndex, closestIndex, thumbPath)

if thumbPath then
if thumbPath or thumbfast.available then
---- Thumb BG/Outline
ass:new_event()
ass:pos(tooltipX, tooltipY)
Expand All @@ -1950,7 +1958,23 @@ function renderThumbnailTooltip(pos, sliderPos, ass)
ass:rect_cw(0, 0, thumbWidth, thumbHeight)
ass:draw_stop()
end
end

if thumbfast.available then
if not thumbfast.disabled then
mp.commandv("script-message-to", "thumbfast", "thumb",
thumbTime,
math.floor(thumbGlobalX + 0.5),
math.floor(thumbGlobalY + 0.5)
)
end
return
end

local thumbPath, thumbIndex, closestIndex = Thumbnailer:get_thumbnail_path(thumbTime)
-- msg.warn("renderThumbnailTooltip", thumbIndex, closestIndex, thumbPath)

if thumbPath then
---- Render Thumbnail
seekbarThumb.thumbPath = thumbPath
seekbarThumb.globalWidth = thumbGlobalWidth
Expand Down Expand Up @@ -2762,7 +2786,10 @@ function render_elements(master_ass)
an=2, -- x,y is bottom-center
}
renderThumbnailTooltip(thumbPos, sliderPos, elem_ass)

else
if thumbfast.available then
mp.commandv("script-message-to", "thumbfast", "clear")
end
end
end

Expand Down Expand Up @@ -5501,5 +5528,14 @@ mp.add_key_binding(nil, "visibility", function() visibility_mode("cycle") end)

mp.register_script_message("osc-idlescreen", idlescreen_visibility)

mp.register_script_message("thumbfast-info", function(json)
local data = utils.parse_json(json)
if type(data) ~= "table" or not data.width or not data.height then
msg.error("thumbfast-info: received json didn't produce a table with thumbnail information")
else
thumbfast = data
end
end)

set_virt_mouse_area(0, 0, 0, 0, "input")
set_virt_mouse_area(0, 0, 0, 0, "window-controls")