XaF / TraktForVLC

Automatically trakt.tv what you're watching on VLC
300 stars 49 forks source link

[Tutorial] Installing TraktForVLC on MacOS #75

Closed Francis2b closed 6 years ago

Francis2b commented 7 years ago

Hi, @thebluepotato

I need your opinion on my tutorial if nothing is missing maybe @XaF can add it in the ReadMe:

https://francisuniverse.wordpress.com/2017/07/22/install-traktforvlc-on-macos/

thebluepotato commented 7 years ago

I think it's a very good base to start with, and makes a perfect tutorial. However, this should not be in the README since it's quite "directive" or "conversational" in tone and style, which isn't really the neutral and informative style one aims for in a README. Your instructions also might be too complete for a basic user's needs. What I mean by this is that the lines I told you to add in the plist for example, they create the logs which not everyone might want or need and the loglevel INFO is for debugging and not really for general usage (we should assume TraktForVLC works and no that it's buggy). Specifically on what you've written, I think the first step in section 4 isn't necessary since the script runs and replaces the PIN with the tokens even if the first run is with launchctl. To sum it up : I think your instructions make an excellent tutorial for your website and I think the README should point to this post or your website. However for the README itself, I'll make my own pull request with more succinct directions.

Francis2b commented 7 years ago

I hope it'll be usefull. When I'll publish the article on my webbsite I'll add a link here if someone want to use my tutorial or a part of it to put in the README go for it I'll be happy if it can help someone

Lorek162 commented 7 years ago

This "Tuto" helped me, because readme instruction for mac are not that great but i'm still having issue with the .plist file not working. I need to manually launch the TraktForVLC.py

Francis2b commented 7 years ago

Did you check all your directories in your .plist they have to match your installation in order to work?

Lorek162 commented 7 years ago

Yes i don't think this is where is screwed up. My folder is in the "Document" i just replaced my username to "XX" in order to post this here

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>

<plist version=”1.0″>

<dict>

<key>Label</key>

<string>org.user.TraktForVLC</string>

<key>ProgramArguments</key>

<array>

<string>/Library/Frameworks/Python.framework/Versions/2.7/bin/python</string>

<string>/Users/XX/Documents/TraktForVLC/TraktClient.py</string>
<string>–loglevel=INFO</string>

</array>

<key>WorkingDirectory</key>

<string>/Users/XX/Documents/TraktForVLC</string>

<key>StandardOutPath</key>

<string>/Users/XX/Documents/TraktForVLC/logs/agentlog.log</string>
<key>StandardErrorPath</key>

<string>/Users/XX/Documents/TraktForVLC/logs/agentlog.log</string>
<key>RunAtLoad</key>

<true/>

<key>LaunchOnlyOnce</key>

<true/>

<key>KeepAlive</key>

<true/>

</dict>

</plist>
Francis2b commented 7 years ago

Is the directory correct for your python installation

Lorek162 commented 7 years ago

i'm not sure but here's a screen of my /Library/Frameworks/Python.framework/Versions/2.7/bin/ folder

capture d ecran 2017-08-27 a 21 27 18
Francis2b commented 7 years ago

The directory is ok for your Python. And did you save your .plist in /Users/YourUserName/Library/LaunchAgents ?

Also, did you restart your computer after?

Lorek162 commented 7 years ago

Yes and Yes :(

Lorek162 commented 7 years ago

Well i restarted my macbook for the 4th time and now it work's .. what the hell, thank's Casper :)

Francis2b commented 7 years ago

You welcome ;) I'm happy my tutorial helped you! Don't hesitate to let a comment over there if you need more help.

thebluepotato commented 7 years ago

Being the one who wrote the plist I kinda need to step in here to correct one of my mistakes. The LaunchOnlyOnce doesn't make sure there's only one instance running but prevents the agent from starting more than once per boot. This means that if it crashes for some reason, it won't start again until you restart your computer. Sooooo, I'll have to correct it and I'll make a cute script to install the plist automatically. And also instructions to stop/run the agent without needing to restart your computer.

Lorek162 commented 7 years ago

That's why it didn't show up, i messed up the first time when i made the .plist and when attempting to launch it again it wouldn't. I understand i little bit more but still i've restarted the computer a couple of time at first but probably not after i made the correct .plist i assume. Thank's for the explanation

Francis2b commented 7 years ago

@thebluepotato Let me know when you do it like that I can update the tutorial ;)

thebluepotato commented 7 years ago

Basically, copy and paste the following code into a file named install_service_macos.sh (or whatever you like), move that file inside TraktForVLC's directory and run it form Terminal using cd /path/to/TraktForVLC and then ./install_service_macos.sh.

#!/bin/bash

# Stop and unload the service if it's running
launchctl remove org.user.TraktForVLC

# Check if we're running from TraktForVLC's directory
if [ ! -f ./TraktForVLC.py ]; then
    echo "Couldn't locate TraktForVLC.py. Are you running from the right directory?"
    exit 1
fi
traktvlcdir="$(pwd)"

# Check if python is installed
command -v python >/dev/null 2>&1 || { echo >&2 "TraktForVLC requires Python but it couldn't be found. Aborting."; exit 1; }
pythonpath="$(command -v python)"

# Check that no other service called TraktForVLC is already running
if [[ $(launchctl list | grep org.user.TraktForVLC) ]]; then
    echo "TraktForVLC already seems to be running as a service. Please stop it before running this script again."
    exit 1
fi

# Write the plist to LaunchAgents
cat >~/Library/LaunchAgents/org.user.TraktForVLC.plist <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>org.user.TraktForVLC</string>
    <key>ProgramArguments</key>
    <array>
        <string>${pythonpath}</string>
        <string>${traktvlcdir}/TraktForVLC.py</string>
        <string>--loglevel=INFO</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>${traktvlcdir}/logs/agentlog.log</string>
    <key>StandardOutPath</key>
    <string>${traktvlcdir}/logs/agentlog.log</string>
    <key>WorkingDirectory</key>
    <string>${traktvlcdir}</string>
</dict>
</plist>

EOL

# Run the agent
launchctl load ~/Library/LaunchAgents/org.user.TraktForVLC.plist

# Check that it's running
if [[ $(launchctl list | grep org.user.TraktForVLC) ]]; then
    echo "Agent successfully installed and launched!"
else
    cat << EOL
Could not launch agent. The installation might have failed.
Please check that these paths are correct:
Python directory: \`${pythonpath}\`
TraktForVLC directory: \`${traktvlcdir}\`
EOL
fi

If you're unsure about anything I wrote or unfamiliar with Terminal, I'll expand the explanation if needed. The script just does some checks then writes the plist for you with all the correct paths.

Note to those who have already made their own plist: I've slightly changed the name of the plist for uniformity reasons so if you run it, you'll end up with a second plist... Please delete the first one first if you want to run this script.

If you couldn't care less about scripts or thingies, just use this plist and edit accordingly:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>org.user.TraktForVLC</string>
    <key>ProgramArguments</key>
    <array>
        <string>/PATH/TO/python</string>
        <string>/PATH/TO/TraktForVLC.py</string>
        <string>--loglevel=INFO</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/PATH/TO/TraktForVLC/logs/agentlog.log</string>
    <key>StandardOutPath</key>
    <string>/PATH/TO/TraktForVLC/logs/agentlog.log</string>
    <key>WorkingDirectory</key>
    <string>/PATH/TO/TraktForVLC/</string>
</dict>
</plist>

Note that the path to python most likely is /usr/bin/python for most uses.

Lorek162 commented 7 years ago

Wow that was fast

"/usr/bin/python" for mac ? when i first looked at this i didn't found the right folder it's only with Casper tutorial that i found my python directory "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"

thebluepotato commented 7 years ago

@Francis2b Oh yeah and the script also launches the agent too! Note that in your tutorial as it is, you should remove the step of running TraktForVLC before using launchctl, since launchctl's purpose is to launch TraktForVLC for you and handle everything in the background. If you launch it beforehand, you'll have two instances running or one of them will fail. Moreover, you should replace launchctl list with launchctl list | grep org.user.TraktForVLC so you'll immediately get the line concerning us if it is running.

thebluepotato commented 7 years ago

@Lorek162 try running which python in Terminal and you'll see the path your system uses for python when you call it from the command line. For most users it will be /usr/bin/python but it might be different on your setup.

Francis2b commented 7 years ago

Great might be useful for the next people ! @thebluepotato what's launchctl list | grep org.user.TraktForVLC for?

Lorek162 commented 7 years ago

MacBook-Pro-de-XX:~ XX$ which python /Library/Frameworks/Python.framework/Versions/2.7/bin/python

is it because macOS is in French ?

thebluepotato commented 7 years ago

@Francis2b it's for checking if the agent is running. The first part of the command is already mentioned in your tutorial but instead of scrolling through the potentially long and confusing list, the second part of the command catches the line containing the words org.user.TraktForVLC. If it's empty, then the service isn't running.

@Lorek162 Non, mon mac est aussi en français mais j'imagine que tu as un jour installé ta propre version de Python et c'est désormais le chemin utilisé par le système par défaut. Ça marchera tout autant!

Francis2b commented 7 years ago

@Lorek162 nope my macOS is in English and it's the same path. I think it depends on the python version you're using. One day I read there is a python already installed with macOS, maybe that's why.

thebluepotato commented 7 years ago

@Francis2b true, it comes with Mac and sometimes some programs require a specific version of Python which, when installed, will overwrite the standard path for the command. Note that the version I'm running with /usr/bin/python is 2.7.10. But whichever version you're running, you should simply use the path provided by which python, which is basically what the script does using a different command.

Lorek162 commented 7 years ago

" but instead of scrolling through the potentially long and confusing list" Yes it's a long list i watched it more than 20 times :)

Yeah maybe it's because i first installed python 3.5 and then when it didn't work i installed the 2.7 version as mention in Francis2b's tutorial

Francis2b commented 7 years ago

Thanks @thebluepotato I updated the tutorial. By the way do you want me to credit you for the .plist on the tutorial ? I totaly forgot to asked you last time :/

thebluepotato commented 7 years ago

@Francis2b Meh, if you feel like it, please credit me, but please add a line somewhere that the code is provided as is, without any implicit guarantees, etc., etc. (I'm a lawyer so I cover my back).

Francis2b commented 7 years ago

@thebluepotato yep good idea!

Francis2b commented 7 years ago

@thebluepotato at the end of the tutorial I added: "(All the above code and files are provided as is, without any implicit guarantees of any kind. If something is not working you can still ask for help in the comments but I'm not a programmer so my knowledge is limited and so is my time 😉)"

thebluepotato commented 7 years ago

@Francis2b Splendid! Glad I could help

XaF commented 6 years ago

TraktForVLC 2.x makes that issue obsolete - #88