Skip to content

Commit 9b8e430

Browse files
committed
Add imdbID to import CSV. Also upgrade to using pyproject.toml
1 parent 11c23dd commit 9b8e430

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

plex2letterboxd/plex2letterboxd.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import argparse
33
import configparser
44
import csv
5+
import re
56
import sys
67

78
from plexapi.server import PlexServer
@@ -37,25 +38,33 @@ def parse_config(ini):
3738
return auth
3839

3940

41+
def getImdbId(movie):
42+
for guid in (g.id for g in movie.guids):
43+
if guid.startswith('imdb'):
44+
return re.sub('^imdb://', '', guid)
45+
return None
46+
47+
4048
def write_csv(sections, output, args):
4149
"""Generate Letterboxd import CSV."""
4250
with open(output, 'w', newline='') as f:
4351
writer = csv.writer(f)
44-
writer.writerow(['Title', 'Year', 'Rating10', 'WatchedDate'])
52+
writer.writerow(['Title', 'Year', 'imdbID', 'Rating10', 'WatchedDate'])
4553

4654
count = 0
4755
for section in sections:
4856
filters = { 'unwatched': False }
4957
if args.watched_after:
5058
filters['lastViewedAt>>'] = args.watched_after
5159
for movie in section.search(sort='lastViewedAt', filters=filters):
60+
imdbID = getImdbId(movie)
5261
date = None
5362
if movie.lastViewedAt is not None:
5463
date = movie.lastViewedAt.strftime('%Y-%m-%d')
5564
rating = movie.userRating
5665
if rating is not None:
5766
rating = f'{movie.userRating:.0f}'
58-
writer.writerow([movie.title, movie.year, rating, date])
67+
writer.writerow([movie.title, movie.year, imdbID, rating, date])
5968
count += 1
6069
print(f'Exported {count} movies to {output}.')
6170

@@ -70,7 +79,7 @@ def main():
7079
user = myplex.user(args.managed_user)
7180
# Get the token for your machine.
7281
token = user.get_token(plex.machineIdentifier)
73-
# Login to your server using your friends credentials.
82+
# Login to your server using your friend's credentials.
7483
plex = PlexServer(auth['baseurl'], token)
7584

7685
sections = [plex.library.section(s) for s in args.sections]

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build-system]
2+
requires = ["setuptools >= 61.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "plex2letterboxd"
7+
version = "1.4"
8+
description = "Export watched Plex movies to the Letterboxd import format."
9+
authors = [
10+
{name = "Max Timkovich", email = "max@timkovi.ch"}
11+
]
12+
readme = "README.md"
13+
license = {file = "LICENSE"}
14+
15+
dependencies = [
16+
"plexapi>=4.15.7"
17+
]
18+
requires-python = ">=3"

setup.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)