From 9b8e4301ce03f4684deaa258c1e2a9dfe80413c3 Mon Sep 17 00:00:00 2001 From: Max Timkovich Date: Sun, 9 Jun 2024 20:47:08 -0700 Subject: [PATCH] Add imdbID to import CSV. Also upgrade to using pyproject.toml --- plex2letterboxd/plex2letterboxd.py | 15 ++++++++++++--- pyproject.toml | 18 ++++++++++++++++++ setup.py | 20 -------------------- 3 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/plex2letterboxd/plex2letterboxd.py b/plex2letterboxd/plex2letterboxd.py index b50111e..524da60 100644 --- a/plex2letterboxd/plex2letterboxd.py +++ b/plex2letterboxd/plex2letterboxd.py @@ -2,6 +2,7 @@ import argparse import configparser import csv +import re import sys from plexapi.server import PlexServer @@ -37,11 +38,18 @@ def parse_config(ini): return auth +def getImdbId(movie): + for guid in (g.id for g in movie.guids): + if guid.startswith('imdb'): + return re.sub('^imdb://', '', guid) + return None + + def write_csv(sections, output, args): """Generate Letterboxd import CSV.""" with open(output, 'w', newline='') as f: writer = csv.writer(f) - writer.writerow(['Title', 'Year', 'Rating10', 'WatchedDate']) + writer.writerow(['Title', 'Year', 'imdbID', 'Rating10', 'WatchedDate']) count = 0 for section in sections: @@ -49,13 +57,14 @@ def write_csv(sections, output, args): if args.watched_after: filters['lastViewedAt>>'] = args.watched_after for movie in section.search(sort='lastViewedAt', filters=filters): + imdbID = getImdbId(movie) date = None if movie.lastViewedAt is not None: date = movie.lastViewedAt.strftime('%Y-%m-%d') rating = movie.userRating if rating is not None: rating = f'{movie.userRating:.0f}' - writer.writerow([movie.title, movie.year, rating, date]) + writer.writerow([movie.title, movie.year, imdbID, rating, date]) count += 1 print(f'Exported {count} movies to {output}.') @@ -70,7 +79,7 @@ def main(): user = myplex.user(args.managed_user) # Get the token for your machine. token = user.get_token(plex.machineIdentifier) - # Login to your server using your friends credentials. + # Login to your server using your friend's credentials. plex = PlexServer(auth['baseurl'], token) sections = [plex.library.section(s) for s in args.sections] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6ccde73 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[build-system] +requires = ["setuptools >= 61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "plex2letterboxd" +version = "1.4" +description = "Export watched Plex movies to the Letterboxd import format." +authors = [ + {name = "Max Timkovich", email = "max@timkovi.ch"} +] +readme = "README.md" +license = {file = "LICENSE"} + +dependencies = [ + "plexapi>=4.15.7" +] +requires-python = ">=3" diff --git a/setup.py b/setup.py deleted file mode 100644 index 96048e2..0000000 --- a/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -from setuptools import setup - -with open('README.md') as f: - README = f.read() - -setup( - name='plex2letterboxd', - url='https://github.com/mtimkovich/plex2letterboxd', - version='1.3', - author='Max Timkovich', - author_email='max@timkovi.ch', - license='MIT', - description='Export watched Plex movies to the Letterboxd import format.', - long_description=README, - install_requires=['plexapi==4.15.7'], - python_requires='>=3', - entry_points={'console_scripts': [ - 'plex_to_letterboxd=plex_to_letterboxd:main' - ]}, -)