Skip to content

Commit

Permalink
脚本更新
Browse files Browse the repository at this point in the history
  • Loading branch information
dyphire committed Feb 14, 2025
1 parent 9da5cdb commit 127b4fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 57 deletions.
7 changes: 3 additions & 4 deletions scripts/trakt-scrobble/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,14 @@ function start_scrobble(config, data, no_osd)
message = "Scrobbling on trakt.tv: " .. state.title
end
if input_loaded and not no_osd then
local message1 = format_message(message, "00FF00")
local message2 = format_message("Incorrect scrobble? Press x to open the search menu", "FF8800")
message3 = message1 .. "\n" .. message2
mp.add_forced_key_binding("x", "search-trakt", function()
mp.osd_message("")
open_input_menu_get(state.filename, config)
stop_scrobble(config, data)
end)
mp.osd_message(message3, 9)
local message1 = format_message(message, "00FF00")
local message2 = format_message("Incorrect scrobble? Press x to open the search menu", "FF8800")
mp.osd_message(message1 .. "\n" .. message2, 9)
msg.info(message)
elseif not no_osd then
send_message(message, "00FF00", 3)
Expand Down
73 changes: 20 additions & 53 deletions scripts/trakt-scrobble/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ local function search_season(slug, type, id, title, config)
end
end

local function search_show(name, config, page)
local function search_trakt(name, class, config, page)
local limit = 20
local page = page or 1
local url = string.format("https://api.trakt.tv/search/show?query=%s&page=%d&limit=%s",
url_encode(name), page, limit)
local url = string.format("https://api.trakt.tv/search/%s?query=%s&page=%d&limit=%s",
class, url_encode(name), page, limit)
local res = http_request("GET", url, {
["trakt-api-key"] = base64.decode(config.client_id),
["trakt-api-version"] = "2"
Expand All @@ -78,54 +78,21 @@ local function search_show(name, config, page)
local items = {}
for _, item in ipairs(res) do
table.insert(items, {
title = item.show.title,
hint = item.show.year and item.type .." ".. item.show.year or item.type,
title = item[class].title,
hint = item[class].year and item.type .." ".. item[class].year or item.type,
value = function()
search_season(item.show.ids.slug, item.type, item.show.ids.trakt, item.show.title, config)
end
})
end
if #items == limit then
page = page + 1
table.insert(items, {
title = "Load next page",
value = function()
search_show(name, config, page)
end
})
else
msg.info("No more pages available.")
end
mp.add_timeout(0.1, function()
open_menu_select(items)
end)
end

local function search_movie(name, config, page)
local limit = 20
local page = page or 1
local url = string.format("https://api.trakt.tv/search/movie?query=%s&page=%d&limit=%s",
url_encode(name), page, limit)
local res = http_request("GET", url, {
["trakt-api-key"] = base64.decode(config.client_id),
["trakt-api-version"] = "2"
})
if not res or #res == 0 then
msg.info("No results found")
return
end
local items = {}
for _, item in ipairs(res) do
table.insert(items, {
title = item.movie.title,
hint = item.movie.year and item.type .." ".. item.movie.year or item.type,
value = function()
state.title = item.movie.title
state.id = item.movie.ids.trakt
local progress = get_progress()
local data = get_data(progress)
if data then
start_scrobble(config, data)
if class == "movie" then
state.type = item.type
state.title = item[class].title
state.id = item[class].ids.trakt
local progress = get_progress()
local data = get_data(progress)
if data then
start_scrobble(config, data)
end
write_history(state.dir, state.fname)
else
search_season(item[class].ids.slug, item.type, item[class].ids.trakt, item[class].title, config)
end
end
})
Expand All @@ -135,7 +102,7 @@ local function search_movie(name, config, page)
table.insert(items, {
title = "Load next page",
value = function()
search_movie(name, config, page)
search_trakt(name, class, config, page)
end
})
else
Expand All @@ -154,9 +121,9 @@ local function search(name, config)
:gsub("[eE]%d+$", "")
:gsub("^%s*(.-)%s*$", "%1")
if type == "movie" then
search_movie(name, config)
search_trakt(name, "movie", config)
else
search_show(name, config)
search_trakt(name, "show", config)
end
end

Expand Down

0 comments on commit 127b4fc

Please sign in to comment.