A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Sagnac/streamsave/commit/6d5c0e04472bd04ad91b5148fb0d9ad5bd9bbb72 below:

Host change hack · Sagnac/streamsave@6d5c0e0 · GitHub

@@ -109,6 +109,8 @@ local opts = {

109 109

range_marks = false, -- <yes|no> set chapters at A-B loop points?

110 110

autostart = false, -- <yes|no> automatically dump cache at start?

111 111

autoend = "no", -- <no|HH:MM:SS> cache time to stop at

112 +

hostchange = false, -- <yes|no> use if the host changes mid stream

113 +

quit = "no", -- <no|HH:MM:SS> quits player at specified time

112 114

}

113 115 114 116

-- for internal use

@@ -124,6 +126,8 @@ local file = {

124 126

cache_dumped, -- whether the current cache has been written

125 127

cache_observed, -- whether the cache time is being observed

126 128

endseconds, -- user specified autoend cache time in seconds

129 +

prior_cache = 0, -- previous cache time

130 +

quit_timer, -- used as a replacement for autoend if hostchange is used

127 131

}

128 132 129 133

local loop = {

@@ -142,6 +146,7 @@ local ab_chapters = {} -- A-B loop point chapters

142 146

local chapter_points

143 147

local convert_time

144 148

local observe_cache

149 +

local autoquit

145 150 146 151

local function validate_opts()

147 152

if opts.output_label ~= "increment" and

@@ -183,7 +188,7 @@ local function update_opts(changed)

183 188

mp.set_property_native("chapter-list", chapter_list)

184 189

end

185 190

end

186 -

if changed["autostart"] or changed["autoend"] then

191 +

if changed["autostart"] or changed["autoend"] or changed["hostchange"] then

187 192

observe_cache()

188 193

end

189 194

validate_opts()

@@ -192,13 +197,22 @@ end

192 197

options.read_options(opts, "streamsave", update_opts)

193 198

update_opts{}

194 199 195 -

function convert_time()

196 -

local H, M, S = opts.autoend:match("(%d+):(%d+):(%d+)")

200 +

function convert_time(value, quit)

201 +

local H, M, S = value:match("(%d+):(%d+):(%d+)")

197 202

if not (H and M and S) then

198 -

file.endseconds = nil

203 +

if quit then

204 +

opts.quit = "no"

205 +

else

206 +

file.endseconds = nil

207 +

end

199 208

return

200 209

end

201 -

file.endseconds = H*3600 + M*60 + S

210 +

local compute = H*3600 + M*60 + S

211 +

if quit then

212 +

return compute

213 +

else

214 +

file.endseconds = compute

215 +

end

202 216

end

203 217 204 218

-- dump mode switching

@@ -245,6 +259,7 @@ mp.observe_property("media-title", "string", title_change)

245 259

-- Determine container for standard formats

246 260

function container()

247 261

file.cache_dumped = false

262 +

file.prior_cache = 0

248 263

if opts.force_extension ~= "no" and not file.oldext then

249 264

return end

250 265

local file_format = mp.get_property("file-format")

@@ -340,6 +355,30 @@ local function change_end(value)

340 355

end

341 356

end

342 357 358 +

local function change_hostchange(value)

359 +

if not value or value == "no" then

360 +

opts.hostchange = false

361 +

print("Hostchange disabled")

362 +

mp.osd_message("streamsave: hostchange disabled")

363 +

else

364 +

opts.hostchange = true

365 +

opts.autostart = true

366 +

observe_cache()

367 +

print("Hostchange enabled")

368 +

mp.osd_message("streamsave: hostchange enabled")

369 +

end

370 +

end

371 + 372 +

local function change_quit(value)

373 +

opts.quit = value or opts.quit

374 +

if file.quit_timer and file.quit_timer:is_enabled() then

375 +

file.quit_timer:kill()

376 +

end

377 +

autoquit(convert_time(opts.quit, true))

378 +

print("Quit set to " .. opts.quit)

379 +

mp.osd_message("streamsave: quit set to " .. opts.quit)

380 +

end

381 + 343 382

local function range_flip()

344 383

loop.a = mp.get_property_number("ab-loop-a")

345 384

loop.b = mp.get_property_number("ab-loop-b")

@@ -495,13 +534,20 @@ local function stop()

495 534

end

496 535 497 536

local function automatic(_, value)

498 -

if not value then

499 -

return end

537 +

if opts.hostchange and file.prior_cache ~= 0

538 +

and (not value or math.abs(value - file.prior_cache) > 300)

539 +

then

540 +

-- reload stream

541 +

mp.command("playlist-play-index current")

542 +

return

543 +

elseif not value then

544 +

return

545 +

end

500 546

if opts.autostart and not file.cache_dumped then

501 547

opts.dump_mode = "continuous"

502 548

cache_write()

503 549

end

504 -

if not file.endseconds then

550 +

if not file.endseconds and not opts.hostchange then

505 551

mp.unobserve_property(automatic)

506 552

file.cache_observed = false

507 553

end

@@ -511,24 +557,37 @@ local function automatic(_, value)

511 557

file.cache_observed = false

512 558

file.cache_dumped = false

513 559

end

560 +

file.prior_cache = value

514 561

end

515 562 516 563

-- cache duration observation switch for runtime changes

517 564

function observe_cache()

518 -

convert_time()

565 +

convert_time(opts.autoend)

519 566

if not file.cache_observed and (opts.autostart or file.endseconds) then

520 567

mp.observe_property("demuxer-cache-time", "number", automatic)

521 568

file.cache_observed = true

522 569

end

523 570

end

524 571

observe_cache()

525 572 573 +

function autoquit(value)

574 +

if opts.quit == "no" then

575 +

return

576 +

end

577 +

file.quit_timer = mp.add_timeout(value, function() mp.command("quit")

578 +

print("Quit after " .. opts.quit)

579 +

end)

580 +

end

581 +

autoquit(convert_time(opts.quit, true))

582 + 526 583

mp.register_script_message("streamsave-mode", mode_switch)

527 584

mp.register_script_message("streamsave-title", title_override)

528 585

mp.register_script_message("streamsave-extension", format_override)

529 586

mp.register_script_message("streamsave-path", change_path)

530 587

mp.register_script_message("streamsave-label", change_label)

531 588

mp.register_script_message("streamsave-autoend", change_end)

589 +

mp.register_script_message("streamsave-hostchange", change_hostchange)

590 +

mp.register_script_message("streamsave-quit", change_quit)

532 591 533 592

mp.add_key_binding("Alt+z", "mode-switch", function() mode_switch("cycle") end)

534 593

mp.add_key_binding("Ctrl+x", "stop-cache-write", stop)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4