Skip to content

Adding functionality and improvements#4

Merged
pursvir merged 16 commits intopursvir:mainfrom
Serega007RU:patch-1
Feb 10, 2026
Merged

Adding functionality and improvements#4
pursvir merged 16 commits intopursvir:mainfrom
Serega007RU:patch-1

Conversation

@Serega007RU
Copy link
Copy Markdown
Contributor

@Serega007RU Serega007RU commented Feb 7, 2026

Hello @pursvir! It's me again, I can't stop and keep coming up with new things 😊

Here's what I did in this PR:

  • I rewrote the episode and torrent selection menu using the mp.utils.input.select API. This API is provided by MPV, it's better in functionality and usability, and it's also easier to write code for.

  • I added a display of whether the episode has been watched or not, using the ">" icon (this data is taken from TorgServer).

  • I added a display of speed and other data during file opening and caching.

  • I added the ability to disable the use of EDL via the configuration file, meaning I added the ability to revert to the old method of connecting external files if the user really wants to see the metadata of external files at the expense of speed.

  • I also refactored some of the code.

@pursvir pursvir self-assigned this Feb 8, 2026
@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

Hello, @Serega007RU ! Thanks again for enhancing this script. That mp.utils.input.select UI looks much better.

But currently, the script doesn't work correctly.
Listing TorrServer's torrents works well, but when I choose one of the entries, its "state" stays the same. After pressing Enter, torrent list is shown again.
When I select that torrent the second time, the input menu is disappeared and there's nothing after that.

There is nothing in the script's logs, so I'll need to go deeper.


I've tried to debug it a little, seems that closed handler in show_torrent_files > input.select causes this strange behaviour.
After putting prints at the start and at the end of nearly any function responsible for UI I saw that closed event of show_torrent_files is executed itself, with totally no user input. Very strange...
I've commented it, and it starts showing torrent files as intended. However play_from_playlist still doesn't work.

@Serega007RU
Copy link
Copy Markdown
Contributor Author

Regarding the "closed" handler, it's strange that it behaves this way in your case. I tested and verified everything before creating the PR.
The "closed" handler always triggers even if the user has selected something, which is why there's also a check for "selected."
Perhaps this is a Linux-specific issue (as far as I understand, you're using Linux). I'll try testing the script on Linux.
Also, please let me know what version of MPV you're using. As far as I know, "mp.utils.input.select" was recently added to MPV.

Regarding "play_from_playlist," are there any errors in your logs?

@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

as far as I understand, you're using Linux

Yes. Here's my environment, maybe it'll be useful:

mpv v0.41.0
libplacebo version: v7.351.0
FFmpeg version: n8.0.1
FFmpeg library versions:
libavcodec 62.11.100
libavdevice 62.1.100
libavfilter 11.4.100
libavformat 62.3.100
libavutil 60.8.100
libswresample 6.1.100
libswscale 9.1.100

UPD: I've tried both MPV from my package version and one from Flathub, so that's probably not a problem with the libraries.

I'll try to test this script on a Windows PC later too.

are there any errors in your logs?

no.

@Serega007RU
Copy link
Copy Markdown
Contributor Author

Serega007RU commented Feb 8, 2026

mpv v0.41.0

This is not enough, there should be more numbers further on, this is what my version looks like: v0.41.0-156-g40d2947fa

I tried testing the script on MPV version v0.41.0-41-g4ecf7293f and was able to reproduce your problem (on Windows).
You need to update MPV, but I'll still try to investigate this issue and see what's wrong and why it works differently on the older version of MPV.

UPD: I suspect this issue was fixed in mpv-player/mpv#17256

@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

That's my mpv --version output. pacman -Qi prints 0.41.0-2. There's nothing more.

Your -156-g40d2947fa suffix means your MPV was compiled from the Git commit with hash 40d2947fa, not from an archive from MPV's GitHub release pages with stable versions.

In my case, the source was a Git commit with a tag 0.41.0 (which is the commit e48ac7c).

Therefore, the difference between my MPV and your is 666 (lol) commits and about 10 months (2025-03-25 -> 2026-01-31).

I guess the time has come to compile MPV from source manually. 😄

@Serega007RU
Copy link
Copy Markdown
Contributor Author

As I understand it, Pacman or Flathub are providing you with an older version of MPV. Considering the commits that fix our issue were made only three weeks ago (which isn't that long ago), I think we should find a workaround for older versions of MPV.

@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

providing you with an older version of MPV.

Yeah, the stable release.

I'll try to compile MPV from the latest commit you've shown and test if this bug is really fixed.

@Serega007RU
Copy link
Copy Markdown
Contributor Author

I propose the following temporary solution:

@@ -387,10 +387,19 @@ local function play_from_playlist(torrent_menu, index)
 
     mp.commandv("loadlist", "memory://" .. torrent.playlist)
     mp.set_property_number("playlist-pos-1", index)
 end
 
+-- temporary solution to the problem
+-- https://github.com/mpv-player/mpv/pull/17256
+-- TODO remove this after a stable release of MPV with a fix appears
+local function input_select(args)
+    mp.add_timeout(0.1, function()
+        input.select(args)
+    end)
+end
+
 local function show_torrent_files(torrent_menu, torrent_index)
     if not torrent_menu.file_stats then
         torrent_menu = curl(TORRSERVER .. "/stream?link=" .. torrent_menu.hash .. "&stat")
         if not torrent_menu then return end
     end
@@ -417,11 +426,11 @@ local function show_torrent_files(torrent_menu, torrent_index)
             end
         end
     end
 
     local selected = false
-    input.select({
+    input_select({
         prompt = "Select an entry of torrent:",
         items = items,
         default_item = last_viewed,
 
         submit = function (index)
@@ -443,11 +452,11 @@ show_torrents = function (default_item)
     local items = {}
     for i, entry in ipairs(torrents) do
         items[i] = entry.name or entry.title
     end
 
-    input.select({
+    input_select({
         prompt = "Select a torrent:",
         items = items,
         default_item = default_item,
 
         submit = function (index)

@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

I've tested MPV compiled from the commit 3ed9b79 and the script works perfectly now.

Now let me test if that 0.1 sleep timeout really prevents that race condition.

@Serega007RU
Copy link
Copy Markdown
Contributor Author

I think we can reduce the timer to 0.01 to make the delay less noticeable.

@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

Yeah, that timeout really prevents that undefined behaviour.

But there one of 100+ torrents in my collection which causes this strange traceback:

[torrserver_loader]
[torrserver_loader] stack traceback:
[torrserver_loader] 	mp.input:76: in function 'select'
[torrserver_loader] 	/home/johnie/.config/mpv/torrserver_loader.lua:422: in function 'show_torrent_files'
[torrserver_loader] 	/home/johnie/.config/mpv/torrserver_loader.lua:454: in function </home/johnie/.config/mpv/torrserver_loader.lua:453>
[torrserver_loader] 	mp.input:49: in function 'handler'
[torrserver_loader] 	mp.defaults:388: in function 'handler'
[torrserver_loader] 	mp.defaults:522: in function 'call_event_handlers'
[torrserver_loader] 	mp.defaults:564: in function 'dispatch_events'
[torrserver_loader] 	mp.defaults:515: in function <mp.defaults:514>
[torrserver_loader] 	[C]: at 0x55fbb6e37640
[torrserver_loader] 	[C]: at 0x55fbb6e383c0
[torrserver_loader] Lua error: key must be a string, but got number

@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

I've tested the same torrent again, and the traceback is completely different now:

[torrserver_loader]
[torrserver_loader] stack traceback:
[torrserver_loader] 	mp.input:76: in function 'select'
[torrserver_loader] 	/home/johnie/.config/mpv/torrserver_loader.lua:400: in function 'cb'
[torrserver_loader] 	mp.defaults:369: in function 'process_timers'
[torrserver_loader] 	mp.defaults:542: in function 'dispatch_events'
[torrserver_loader] 	mp.defaults:515: in function <mp.defaults:514>
[torrserver_loader] 	[C]: at 0x564354f2b640
[torrserver_loader] 	[C]: at 0x564354f2c3c0
[torrserver_loader] Lua error: key must be a string, but got number

@Serega007RU
Copy link
Copy Markdown
Contributor Author

Serega007RU commented Feb 8, 2026

What version of MPV (commit number) does this problem occur in?
I'm interested to know what's in mp.input:76 (from stack traceback)

@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

I've tested both 0.41.0-2 from Arch repositories and 0.41.0.g3ed9b798-1 which I built myself from that fixing commit.

@Serega007RU
Copy link
Copy Markdown
Contributor Author

Serega007RU commented Feb 8, 2026

the error occurs here https://github.com/mpv-player/mpv/blob/3ed9b798bb88940e7a619b30c2c448dc1ac3441d/player/lua/input.lua#L76
It simply accepts the arguments mp.utils.input.select
I don't understand the problem yet.
Are you experiencing this error with a specific torrent? Can you share it with me so I can reproduce it?
Also, try printing the parameters passed to this method in the console.

@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 8, 2026

(I've coded a helper function to print tables as a string):

local function table_to_string(t)
    local result = "{ "
    for k, v in pairs(t) do
        if type(k) == "string" then
            result = result .. k .. " = "
        end
        if type(v) == "table" then
            result = result .. table_to_string(v) .. ", "
        else
            result = result .. tostring(v) .. ", "
        end
    end
    result = result .. "}"
    return result
end

I've sent you an example torrent in dm.

@Serega007RU Serega007RU force-pushed the patch-1 branch 2 times, most recently from d938642 to fc00da2 Compare February 8, 2026 23:45
@Serega007RU
Copy link
Copy Markdown
Contributor Author

fixed, you can check

what about this #4 (comment)?

…e cache only if watching content from TorrServer
@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 9, 2026

Great, now it works as intended. I've made a little changes, though.
I'm ready to merge, but I want to be sure that it works for you too and that those changes from my last commit are sensible. I'll wait until that moment.

Comment thread torrserver_loader.lua Outdated
Comment thread torrserver_loader.lua
Comment thread torrserver_loader.lua
Comment thread torrserver_loader.lua Outdated
@pursvir
Copy link
Copy Markdown
Owner

pursvir commented Feb 10, 2026

Good. Let's already merge it. And again, thank you a lot for your efforts! 🤝

@pursvir pursvir merged commit 03b9bcf into pursvir:main Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants