Skip to content

Commit ad72619

Browse files
committed
Add watched-after flag
Only search up to the given time for movies.
1 parent 5a4a5c7 commit ad72619

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $ pip install .
2121
Rename `config.ini.example` to `config.ini` and fill it with your Plex credentials.
2222

2323
```console
24-
$ python -m plex2letterboxd -i config.ini
24+
$ python -m plex2letterboxd
2525
```
2626

2727
```
@@ -30,8 +30,13 @@ optional arguments:
3030
-i INI, --ini INI config file (default: config.ini)
3131
-o OUTPUT, --output OUTPUT
3232
file to output to (default: letterboxd.csv)
33-
-s [SECTIONS [SECTIONS ...]], --sections [SECTIONS [SECTIONS ...]]
33+
-s SECTIONS [SECTIONS ...], --sections SECTIONS [SECTIONS ...]
3434
sections to grab from (default: ['Movies'])
35+
-m MANAGED_USER, --managed-user MANAGED_USER
36+
name of managed user to export (default: None)
37+
-w WATCHED_AFTER, --watched-after WATCHED_AFTER
38+
only return movies watched after the given time [format:
39+
YYYY-MM-DD or 30d] (default: None)
3540
```
3641

3742
The generated CSV file can be uploaded to Letterboxd at https://letterboxd.com/import/.

config.ini.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[auth]
22
# Rename this file to 'config.ini' before running the script.
3+
34
# Plex server URL e.g. http://localhost:32400
45
baseurl =
56
# https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/

plex2letterboxd/plex2letterboxd.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def parse_args():
2020
help='sections to grab from')
2121
parser.add_argument('-m', '--managed-user',
2222
help='name of managed user to export')
23+
parser.add_argument('-w', '--watched-after',
24+
help='only return movies watched after the given time [format: YYYY-MM-DD or 30d]')
2325
return parser.parse_args()
2426

2527

@@ -35,15 +37,18 @@ def parse_config(ini):
3537
return auth
3638

3739

38-
def write_csv(sections, output):
40+
def write_csv(sections, output, args):
3941
"""Generate Letterboxd import CSV."""
4042
with open(output, 'w', newline='') as f:
4143
writer = csv.writer(f)
4244
writer.writerow(['Title', 'Year', 'Rating10', 'WatchedDate'])
4345

4446
count = 0
4547
for section in sections:
46-
for movie in section.search(sort='lastViewedAt', unwatched=False):
48+
filters = { 'unwatched': False }
49+
if args.watched_after:
50+
filters['lastViewedAt>>'] = args.watched_after
51+
for movie in section.search(sort='lastViewedAt', filters=filters):
4752
date = None
4853
if movie.lastViewedAt is not None:
4954
date = movie.lastViewedAt.strftime('%Y-%m-%d')
@@ -69,4 +74,4 @@ def main():
6974
plex = PlexServer(auth['baseurl'], token)
7075

7176
sections = [plex.library.section(s) for s in args.sections]
72-
write_csv(sections, args.output)
77+
write_csv(sections, args.output, args)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
setup(
77
name='plex2letterboxd',
88
url='https://github.com/mtimkovich/plex2letterboxd',
9-
version='1.2',
9+
version='1.3',
1010
author='Max Timkovich',
1111
author_email='max@timkovi.ch',
1212
license='MIT',
1313
description='Export watched Plex movies to the Letterboxd import format.',
1414
long_description=README,
15-
install_requires=['plexapi==4.5.2'],
15+
install_requires=['plexapi==4.15.7'],
1616
python_requires='>=3',
1717
entry_points={'console_scripts': [
1818
'plex_to_letterboxd=plex_to_letterboxd:main'

0 commit comments

Comments
 (0)