Skip to content

Commit

Permalink
Add imdbID to import CSV. Also upgrade to using pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
mtimkovich committed Jun 10, 2024
1 parent 11c23dd commit 9b8e430
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
15 changes: 12 additions & 3 deletions plex2letterboxd/plex2letterboxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import configparser
import csv
import re
import sys

from plexapi.server import PlexServer
Expand Down Expand Up @@ -37,25 +38,33 @@ 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:
filters = { 'unwatched': False }
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}.')

Expand All @@ -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]
Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"}
]
readme = "README.md"
license = {file = "LICENSE"}

dependencies = [
"plexapi>=4.15.7"
]
requires-python = ">=3"
20 changes: 0 additions & 20 deletions setup.py

This file was deleted.

0 comments on commit 9b8e430

Please sign in to comment.