bjarneo / Pytify

A CLI application for controlling Spotify
MIT License
743 stars 40 forks source link

The challenge of automation #76

Closed c7v closed 1 year ago

c7v commented 2 years ago

I have a bash script file that is set to run automatically: https://github.com/c7v/work_run/blob/master/work_run.sh and I start Spotify before work.I was hoping that there would be music on Spotify at exactly 9:00, which would let me know if I'm not at the computer about the start of work hours. I was planning to run music in Spotify via cron using a script:

#!/bin/sh
/usr/bin/bash -i -c '/usr/local/bin/pytify -pp'

as a result, the script worked, but the music did not turn on, the following error was issued:

Date: Tue, 22 Feb 2022 10:53:01 +0400 (+04)

bash: не удаётся задать группу процесса терминала (21894): Неприменимый к данному устройству ioctl
bash: этот командный процессор не может управлять заданиями
bash: не удаётся задать группу процесса терминала (21894): Неприменимый к данному устройству ioctl
bash: этот командный процессор не может управлять заданиями

Some errors occured. Try restart or start Spotify. Pytify is just a cli application which controls Spotify. So you can't use Pytify without Spotify.

How can I start Spotify music at 9 am automatically?

Thanks for the help and software! ❤️

bjarneo commented 2 years ago

@c7v Hi, and thank you for the issue.

I have a question: Is spotify running on the computer? Pytify is just a CLI that talks directly to the spotify application.

c7v commented 2 years ago

@bjarneo Hi! Yes, spotify running on the computer. Yes, I know that Pytify is a terminal control, but in a bash script I can execute commands, which is what I'm trying to do.

Без названия (3)

bjarneo commented 2 years ago

Alright, so, since you are running linux, try this command directly (pytify is using this command under the hood): dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

This will be the equivalent of running pytify -pp

Does that work?

If it works: Something is not OK with Pytify If it does not: Something is wrong at your end

bjarneo commented 2 years ago

@c7v and I believe cron is running as root, right? And the Spotify player is by your user? Might be causing this as well. 🤔

c7v commented 2 years ago

@bjarneo cron can run as root or as a different user, it already depends on which user you opened crontab -e under.

Tried to use your command through the terminal, the command worked and the music started.

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

But when I run the command in a cron task, I get an error:

Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
c7v commented 2 years ago

But running a cron task under a different user is more likely..

c7v commented 2 years ago

If you correct this command in the terminal, the username will be corrected in the file.

artem@MS-7991:~$ echo $USER >> /home/artem/cron.log

However, when this command is run in a cron job, the file is created at the specified time, as suggested by the cron job, but the file is empty.

It looks like the cron command is running under an invisible user. :rofl: :laughing:

bjarneo commented 2 years ago

Hm. Quite interesting read, I must say. Awesome debugging :)

Let me know if you figure out how to solve it.

Found this comment though: https://stackoverflow.com/a/70560980

c7v commented 2 years ago

После этого https://stackoverflow.com/a/70560980, только хуже получилось

artem@MS-7991:~$ dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.mpris.MediaPlayer2.spotify was not provided by any .service files

Хорошо, я попробую решить эту проблему и напишу о решении тут, не закрывайте эту задачу.

bjarneo commented 2 years ago

Хорошо, я попробую решить эту проблему и напишу о решении тут, не закрывайте эту задачу. Ok, I will try to solve this problem and write about the solution here, do not close this task.

Alright, cool :)

c7v commented 2 years ago

Hello, due to the sanctions against Russia, I can no longer work on your task, because I can not renew my subscription and include music.

I will return to this task when Spotify gets tired of sitting without money from Russia. 💸

bjarneo commented 2 years ago

aww, that sucks man, I will leave this issue open, and hope for you to one day come back to solve it 🤞