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

Add more documentation, clean up launchd plist, upgrade dependencies #1

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2

# 3 space indentation
[*.js]
indent_style = space
indent_size = 3
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PLEX_TOKEN=
PLEX_IP=
USERNAME=
PLEX_USER=
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
# plex-letterboxd

Syncs your letterboxd watchlist with movies on you plex

## Installation

1. `git clone https://github.com/slgoetz/plex-letterboxd-sync.git`
2. `cd plex-letterboxd-sync`
3. `yarn install`
```bash
git clone https://github.com/slgoetz/plex-letterboxd-sync.git
cd plex-letterboxd-sync
yarn install
```

## Usage
If you want this to run in the background and sync once a day you can add it as a launch script on your mac. To do so you will need to fill in the blanks (`{path-for-your-file}` and `{username}`) in `launched.plexletterboxdsync.plist`. Then check to see if you have a directory at `~/Library/LaunchAgents`. If not, create one and copy the launch file there. This should run at midnight every day and output a log file for synced movies as well as errors.
## Setup

*Make sure the `PATH` set the start.sh file is replaced with your `PATH`*
Copy `.env.sample` to `.env` and fill in the environment variables.

* `$PLEX_TOKEN` - See [this Plex support article](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/)
* `$PLEX_IP` - Can be an IP address (e.g., `192.168.1.2`) or a hostname (e.g., `plex.example.com`)
* `$PLEX_USER` - Your username with Plex (e.g., how you log in to plex.tv)

## Usage

### Run Once
If you would like to run this once, you can run with `node ./index.js`

If you would like to run this once:

```bash
cd plex-letterboxd-sync
./start.sh
```

### Run On A Schedule

If you want this to run in the background on a regular interval (e.g., once a day), you can add it as a launchd script on your Mac.

1. Edit `com.slgoetz.plexletterboxdsync.plist` and replace `/path/to/plex-letterboxd-sync` with the absolute path to where you cloned this repository. E.g., `/Users/username/plex-letterboxd-sync`
2. *Make sure the `PATH` set in `~/Library/LaunchAgents/com.slgoetz.plexletterboxdsync.plist` is valid for your user,* it should ensure that `node` is available to launchd to run the script.
* E.g., if `node` is at `/usr/local/bin` or `/opt/homebrew/bin` (the default locations for Homebrew-installed Node.js, depending on if you have an Intel or Apple Silicon Mac), you should be good with the default value.
3. Check if you have a directory at `~/Library/LaunchAgents`. If not, create it.
4. Copy the launchd plist file, `com.slgoetz.plexletterboxdsync.plist`, to `~/Library/LaunchAgents`

This will enable the script to run at midnight every day and output a log file for synced movies as well as errors to the `WorkingDirectory` you set in step 1 above.

If you’d like to run it on a different schedule, the `StartCalendarInterval` stanza can be modified. You can do this by hand, or using a utility application like [LaunchControl](https://www.soma-zone.com/LaunchControl/).

## Roadmap

- [ ] Sync ratings
- [ ] Sync Watched

26 changes: 26 additions & 0 deletions com.slgoetz.plexletterboxdsync.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>Label</key>
<string>com.slgoetz.plexletterboxdsync</string>
<key>Program</key>
<string>start.sh</string>
<key>StandardErrorPath</key>
<string>plex-letterboxd-sync-error.log</string>
<key>StandardOutPath</key>
<string>plex-letterboxd-sync.log</string>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>WorkingDirectory</key>
<string>/path/to/plex-letterboxd-sync</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const getAllLibraries = async () => {
};

const letterboxd = async () => {
return await fetch(`https://letterboxd.com/${process.env.USERNAME}/watchlist/`)
return await fetch(`https://letterboxd.com/${process.env.PLEX_USER}/watchlist/`)
.then((response) => response.text())
.then((html) => {
let $ = cheerio.load(html);
Expand All @@ -67,7 +67,7 @@ const letterboxd = async () => {
};
const getLbMovieInfo = async (movies) => {
const getFilm = async ({ filmId, filmSlug }) => {
return await fetch(`https://letterboxd.com${filmSlug}`)
return await fetch(`https://letterboxd.com/${filmSlug}`)
.then((response) => response.text())
.then((html) => {
let $ = cheerio.load(html);
Expand Down
28 changes: 0 additions & 28 deletions launched.plexletterboxdsync.plist

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Sync your Letterboxd watchlist with your Plex media server.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"sync": "node index.js"
},
"author": "",
"type": "module",
Expand All @@ -19,6 +20,6 @@
"node-schedule": "^2.1.1",
"plex-api": "^5.3.2",
"url-join": "^5.0.0",
"xml2js": "^0.4.23"
"xml2js": "^0.6.2"
}
}
4 changes: 2 additions & 2 deletions start.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export PATH=/opt/homebrew/opt/node@14/bin:/opt/homebrew/opt/node@14/bin:/opt/homebrew/opt/node@16/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
#!/usr/bin/env bash

yarn install
node ./index.js
yarn sync
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ domutils@^3.0.1:
domhandler "^5.0.1"

dotenv@^16.0.3:
version "16.0.3"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==
version "16.4.5"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

duplexer@~0.1.1:
version "0.1.2"
Expand Down Expand Up @@ -967,9 +967,9 @@ node-domexception@^1.0.0:
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==

node-fetch@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.0.tgz#37e71db4ecc257057af828d523a7243d651d91e4"
integrity sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA==
version "3.3.2"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.2.tgz#d1e889bacdf733b4ff3b2b243eb7a12866a0b78b"
integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==
dependencies:
data-uri-to-buffer "^4.0.0"
fetch-blob "^3.1.4"
Expand Down Expand Up @@ -1252,9 +1252,9 @@ safer-buffer@^2.0.2, safer-buffer@^2.1.0, safer-buffer@~2.1.0:
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

sax@>=0.6.0:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
version "1.4.1"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.4.1.tgz#44cc8988377f126304d3b3fc1010c733b929ef0f"
integrity sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==

set-value@^2.0.0, set-value@^2.0.1:
version "2.0.1"
Expand Down Expand Up @@ -1513,10 +1513,10 @@ [email protected]:
sax ">=0.6.0"
xmlbuilder "~9.0.1"

xml2js@^0.4.23:
version "0.4.23"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.23.tgz#a0c69516752421eb2ac758ee4d4ccf58843eac66"
integrity sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==
xml2js@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.6.2.tgz#dd0b630083aa09c161e25a4d0901e2b2a929b499"
integrity sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==
dependencies:
sax ">=0.6.0"
xmlbuilder "~11.0.0"
Expand Down