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

Video open close loop when using ani-cli hook #637

Open
sgtoutlaw opened this issue Aug 20, 2022 · 14 comments
Open

Video open close loop when using ani-cli hook #637

sgtoutlaw opened this issue Aug 20, 2022 · 14 comments

Comments

@sgtoutlaw
Copy link

sgtoutlaw commented Aug 20, 2022

So whenever I try and use the ani-cli hook, it launches the player and closes it over and over again until it has cycled through all the episodes of the series. Sometimes it is open long enough for me to see a second or 2 of the actual show playing.

I am on Arch linux, and it was installed with the use of the AUR trackma-git package.

Playing files on the seems to work okay.

I tried to change over to to auto for the tracker, but it had the same video window opening and closing but didn't have as much to say with -d as mpris.

Initializing engine...
Engine: Trackma v0.8.4 - using account sgtoutlaw(anilist).
Engine: Reading config files...
Data: Initializing...
[D] Data: Reading userconfig...
libanilist: Initializing...
Data: Using libanilist (anime)
[D] Data: Locking database...
[D] Data: Reading metadata...
[D] Data: Reading queue...
[D] Data: Reading info DB...
[D] Data: Reading cache...
Engine: Parsing redirection file...
Engine: Scanning local library...
[D] Engine: Scanning for Watching
[D] Engine: Scanning for Rewatching
[D] Engine: Scanning for Paused
[D] Engine: Scanning for Plan to Watch
[D] Engine: Directory: /home/ghiblic/Videos
[D] Engine: File in cache: /home/ghiblic/Videos/Haikyuu Episode 1.mp4
[D] Engine: File in cache but skipped: /home/ghiblic/Videos/ReplaySorcery/2021-09-21_02-46-36.mp4
[D] Engine: Time: 0.0004456043243408203
Engine: Importing user hooks...
[D] Engine: Importing hook episode_missing_ani-cli...
[D] Engine: Initializing tracker...
Tracker (MPRIS): Initializing...
[D] Tracker (MPRIS): Enabling tracker...
Tracker (MPRIS): Using MPRIS.

Ready. Type 'help' for a list of commands.
Press tab for autocompletion and up/down for command history.
Available statuses: watching, completed, rewatching, paused, dropped, plantowatch

ghiblic [anilist] (anime) watching >> play 2
Engine: Getting 'Jiandao Di Yi Xian' episode '9' from library...
Engine: Episode not found. Calling hooks...
[D] Engine: Calling hook episode_missing_ani-cli:episode_missing...
episode_missing: /usr/bin/ani-cli -a 9 'Jiandao Di Yi Xian'
Tracker (MPRIS): Connecting to MPRIS player: org.mpris.MediaPlayer2.mpv
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New video: Jiandao Di Yi Xian Episode 9
[D] Tracker (MPRIS): Guessing filename: Jiandao Di Yi Xian Episode 9
[D] Tracker (MPRIS): Show guess: Jiandao Di Yi Xian: {'id': 137643, 'title': 'Jiandao Di Yi Xian', 'my_progress': 8, 'total': 20, 'type': None, 'titles': ['Jiandao Di Yi Xian', 'Jiandao Di Yi Xian', '剑道第一仙']} (9)
Tracker (MPRIS): Will update Jiandao Di Yi Xian 9
[D] Tracker (MPRIS): New tracker status: Tracker.PLAYING (previously: Tracker.PLAYING)
[D] Tracker (MPRIS): (Tracker.PLAYING) Setting active player: :1.58
[D] Tracker (MPRIS): Starting MPRIS timer.
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): Clearing active player: :1.58
Tracker (MPRIS): Player was closed before update.
Tracker (MPRIS): Connecting to MPRIS player: org.mpris.MediaPlayer2.mpv
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New video: Jiandao Di Yi Xian Episode 10
[D] Tracker (MPRIS): Guessing filename: Jiandao Di Yi Xian Episode 10
[D] Tracker (MPRIS): Show guess: Jiandao Di Yi Xian: {'id': 137643, 'title': 'Jiandao Di Yi Xian', 'my_progress': 8, 'total': 20, 'type': None, 'titles': ['Jiandao Di Yi Xian', 'Jiandao Di Yi Xian', '剑道第一仙']} (10)
Tracker (MPRIS) warning: Not playing the next episode of Jiandao Di Yi Xian (expected: 9, found: 10). Ignoring.
[D] Tracker (MPRIS): New tracker status: Tracker.PLAYING (previously: Tracker.IGNORED)
[D] Tracker (MPRIS): (Tracker.IGNORED) Setting active player: :1.59
[D] Tracker (MPRIS): Starting MPRIS timer.
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): Clearing active player: :1.59
Tracker (MPRIS): Connecting to MPRIS player: org.mpris.MediaPlayer2.mpv
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New video: Jiandao Di Yi Xian Episode 11
[D] Tracker (MPRIS): Guessing filename: Jiandao Di Yi Xian Episode 11
[D] Tracker (MPRIS): Show guess: Jiandao Di Yi Xian: {'id': 137643, 'title': 'Jiandao Di Yi Xian', 'my_progress': 8, 'total': 20, 'type': None, 'titles': ['Jiandao Di Yi Xian', 'Jiandao Di Yi Xian', '剑道第一仙']} (11)
Tracker (MPRIS) warning: Not playing the next episode of Jiandao Di Yi Xian (expected: 9, found: 11). Ignoring.
[D] Tracker (MPRIS): New tracker status: Tracker.PLAYING (previously: Tracker.IGNORED)
[D] Tracker (MPRIS): (Tracker.IGNORED) Setting active player: :1.60
[D] Tracker (MPRIS): Starting MPRIS timer.
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): Clearing active player: :1.60
Tracker (MPRIS): Connecting to MPRIS player: org.mpris.MediaPlayer2.mpv
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New video: Jiandao Di Yi Xian Episode 12
[D] Tracker (MPRIS): Guessing filename: Jiandao Di Yi Xian Episode 12
[D] Tracker (MPRIS): Show guess: Jiandao Di Yi Xian: {'id': 137643, 'title': 'Jiandao Di Yi Xian', 'my_progress': 8, 'total': 20, 'type': None, 'titles': ['Jiandao Di Yi Xian', 'Jiandao Di Yi Xian', '剑道第一仙']} (12)
Tracker (MPRIS) warning: Not playing the next episode of Jiandao Di Yi Xian (expected: 9, found: 12). Ignoring.
[D] Tracker (MPRIS): New tracker status: Tracker.PLAYING (previously: Tracker.IGNORED)
[D] Tracker (MPRIS): (Tracker.IGNORED) Setting active player: :1.58
[D] Tracker (MPRIS): Starting MPRIS timer.
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
Tracker (MPRIS): Connecting to MPRIS player: org.mpris.MediaPlayer2.mpv.instance359589
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): Clearing active player: :1.58
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New video: Jiandao Di Yi Xian Episode 13
[D] Tracker (MPRIS): Guessing filename: Jiandao Di Yi Xian Episode 13
[D] Tracker (MPRIS): Show guess: Jiandao Di Yi Xian: {'id': 137643, 'title': 'Jiandao Di Yi Xian', 'my_progress': 8, 'total': 20, 'type': None, 'titles': ['Jiandao Di Yi Xian', 'Jiandao Di Yi Xian', '剑道第一仙']} (13)
Tracker (MPRIS) warning: Not playing the next episode of Jiandao Di Yi Xian (expected: 9, found: 13). Ignoring.
[D] Tracker (MPRIS): New tracker status: Tracker.PLAYING (previously: Tracker.IGNORED)
[D] Tracker (MPRIS): (Tracker.IGNORED) Setting active player: :1.58
[D] Tracker (MPRIS): Starting MPRIS timer.
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): Clearing active player: :1.58
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
Tracker (MPRIS): Connecting to MPRIS player: org.mpris.MediaPlayer2.mpv
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New video: Jiandao Di Yi Xian Episode 14
[D] Tracker (MPRIS): Guessing filename: Jiandao Di Yi Xian Episode 14
[D] Tracker (MPRIS): Show guess: Jiandao Di Yi Xian: {'id': 137643, 'title': 'Jiandao Di Yi Xian', 'my_progress': 8, 'total': 20, 'type': None, 'titles': ['Jiandao Di Yi Xian', 'Jiandao Di Yi Xian', '剑道第一仙']} (14)
Tracker (MPRIS) warning: Not playing the next episode of Jiandao Di Yi Xian (expected: 9, found: 14). Ignoring.
[D] Tracker (MPRIS): New tracker status: Tracker.PLAYING (previously: Tracker.IGNORED)
[D] Tracker (MPRIS): (Tracker.IGNORED) Setting active player: :1.63
[D] Tracker (MPRIS): Starting MPRIS timer.
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): New playback status: Stopped
[D] Tracker (MPRIS): Clearing active player: :1.63
[D] Tracker (MPRIS): New playback status: Stopped
Tracker (MPRIS): Connecting to MPRIS player: org.mpris.MediaPlayer2.mpv
[D] Tracker (MPRIS): New playback status: Playing
[D] Tracker (MPRIS): New video: Jiandao Di Yi Xian Episode 15
[D] Tracker (MPRIS): Guessing filename: Jiandao Di Yi Xian Episode 15
[D] Tracker (MPRIS): Show guess: Jiandao Di Yi Xian: {'id': 137643, 'title': 'Jiandao Di Yi Xian', 'my_progress': 8, 'total': 20, 'type': None, 'titles': ['Jiandao Di Yi Xian', 'Jiandao Di Yi Xian', '剑道第一仙']} (15)
Tracker (MPRIS) warning: Not playing the next episode of Jiandao Di Yi Xian (expected: 9, found: 15). Ignoring.
[D] Tracker (MPRIS): New tracker status: Tracker.PLAYING (previously: Tracker.IGNORED)
[D] Tracker (MPRIS): (Tracker.IGNORED) Setting active player: :1.64

It goes down like that until the episodes run out.

@z411
Copy link
Owner

z411 commented Aug 20, 2022

Trackma just runs the command /usr/bin/ani-cli -a 9 'Jiandao Di Yi Xian'. Does everything function normally when you run this command manually?

@sgtoutlaw
Copy link
Author

sgtoutlaw commented Aug 21, 2022

Here is a video of how it looks, as well as how my task manager looks during that time, and then how ani-cli runs the command fine by itself.

2022-08-21_07-47-52.mp4

I don't really know how to code, but I managed to replace ani-cli in the python hook with animdl. I had to default an index choice for it to work so it gives the wrong episode a lot. I don't exactly consider it a good alterative, but it doesn't seem to have the same problem that ani-cli is giving. This leads me to think that maybe it is some problem with the interaction between trackma and ani-cli.

Or at least in my case.

Edit: Alright, I commented out the menu loop that appears and holds the terminal while you are playing an episode using ani-cli, and now it seems to work like it should for play in trackma.

#while` : ; do
	auto_play=0
	unset menu
	unset options
	[ "$episode" -ne "$last_ep_number" ] && menu=$(append "$menu" 'next' 'n')
	[ "$episode" -ne "$first_ep_number" ] && menu=$(append "$menu" 'previous' 'p')
	menu=$(append "$menu" 'replay' 'r')
	[ "$first_ep_number" -ne "$last_ep_number" ] && menu=$(append "$menu" 'select' 's')
	menu=$(append "$menu" 'quit' 'q')
	if [ "$fzf" -eq 1 ];then
		progress ""
		choice="$(selection_menu_fzf ". Menu>>" "$menu")"
		[ -z "$choice" ] && die "No anime Selected"
	else
		selection_menu "$menu"
			choice="$REPLY"
	fi
	case $choice in
		n|'')
			ep_choice_start=$((episode + 1))
			unset ep_choice_end
			;;
		p)
			ep_choice_start=$((episode - 1))
			unset ep_choice_end
			;;
		r)
			ep_choice_start="$episode"
			unset ep_choice_end
			;;
		s)
			episode_selection ;;
		q)
			break ;;
		*)
			tput clear
			err "Invalid choice"
			continue
			;;
	esac
	generate_ep_list
	open_selection
done

I don't know any coding so not sure how you go from here, just figured it might be useful.

@sgtoutlaw
Copy link
Author

Put in a request over at
pystardust/ani-cli#872
that seems to fix the problem for me, but obviously would rather have people who know how to code to chime in, so I am just leaving this here.

@port19x
Copy link

port19x commented Aug 22, 2022

Can confirm issue / unintended usage on our end.
ani-cli users usually use trackmas detection of running video players, we set compatible titles to support that

@FichteFoll
Copy link
Collaborator

FichteFoll commented Aug 22, 2022

It looks to me as if the ani-cli tool interacts with the terminal/stdin and trackma does not hold a reference to stdin to communicate with ani-cli, causing ani-cli to think the session should be closed. Probably ani-cli needs a hands-off mode/flag where it just runs the specified episode without also requiring stdin/a tty.

@arisu0
Copy link

arisu0 commented Oct 28, 2022

As a temporal fix, I edited the script for it to open ani-cli through the terminal of my choice, in this case alacritty. Only noticeable edits are using os.system to start alacritty instead of utils.spawn_process and adding "alacritty -e" as first argument. Probably not the best fix, but it does the job for me.

import shutil
import os
from trackma import utils


# Executed when trying to watch an episode that doesn't exist in your library
def episode_missing(engine, show, episode):

    query = show["title"].strip()
    anicli = shutil.which("ani-cli")  # find 'ani-cli' executable
    if anicli:
        args = ["alacritty -e", anicli, "-q", "best", "-a", str(episode), query]
        cmd = " ".join(args[:-1]) + f" '{query}'"
        engine.msg.info("episode_missing", cmd)  # Show the command used
        #utils.spawn_process(args)
        os.system(cmd)
    else:
        engine.msg.info("episode_missing", "ani-cli was not found")```

@imsamuka
Copy link
Contributor

It's unfortunate ani-cli intentions to remove the -a flag.

A long term support would be to change it for another program, since it would be quite a pain to use then.

I can reproduce the bug with this on the terminal:

ani-cli -a 9 Jiandao Di Yi Xian < /dev/null

Since ani-cli loads the next episode when you press enter without any input, i assume this happens because /dev/null will do practically the same thing, and load every episodes until no episode is found.

This will solve the problem on the terminal:

echo q | ani-cli -9 Jiandao Di Yi Xian

This will input the letter q in ani-cli, quitting it. I don't know how to do this in python yet, but I will find, test it and put up a PR.

@imsamuka
Copy link
Contributor

Fixed on #652

@port19x
Copy link

port19x commented Apr 28, 2023

Btw ani-cli has full support for non-interactive usage again.
In 4.2.x ani-cli -S 1 -e 1 flcl will select (-S) the first search result and play the first episode (-e) of flcl.

A python wrapper is a bad idea.
If you want to integrate with a python based project instead, check out animdl

@port19x
Copy link

port19x commented Apr 28, 2023

@imsamuka

@port19x
Copy link

port19x commented Apr 28, 2023

We actually still open a menu after the episode has played.
I'll make sure this gets resolved asap

@imsamuka
Copy link
Contributor

imsamuka commented Apr 28, 2023

@port19x
In the new version, when the terminal is non interactive, they run rofi as a menu, where you can quit, repeat, next, select another, etc.

Isn't that arguably a even better solution than just quitting the program after the episode is done?

And when you don't have rofi installed, it just closes, like previously intended too

Test it with ani-cli -e 1 flcl < /dev/null

@imsamuka
Copy link
Contributor

imsamuka commented Apr 28, 2023

In fact, it would be probably better to not specify -S 1 by default, only when rofi is not installed, because the user can select the correct anime to watch.

This is a deal breaker for me, personally I almost never used this script that i made, because it most often fails to select the correct anime (and the poor bit rate)

This is specially true if you want to watch a anime with more than 1 season or with specials. If you search for Death Note, the last entry will be the actual anime. It's actually rare to find anime where this doesn't happen, like One Piece, or anime airing for the first time recently.

@imsamuka
Copy link
Contributor

I updated #652 to the new 4.2 version. It's pretty satisfactory now, specially if you have rofi installed.

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

No branches or pull requests

6 participants