22import argparse
33import configparser
44import csv
5+ import re
56import sys
67
78from 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+
4048def 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 ]
0 commit comments