forked from Arial-Z/Romaji-Renamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplex_movies_export.py
33 lines (30 loc) · 1.07 KB
/
plex_movies_export.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from plexapi.server import PlexServer
from dotenv import load_dotenv
from os import environ, path
import re
import pathlib
# Find .env file
basedir = path.abspath(path.dirname(__file__))
load_dotenv(path.join(basedir, '.env'))
# General Config
url = environ.get('plex_url')
token = environ.get('plex_token')
MOVIE_LIBRARY_NAME=environ.get('MOVIE_LIBRARY_NAME')
plex = PlexServer(url, token, timeout=300)
movies = plex.library.section(MOVIE_LIBRARY_NAME)
with open(path.join(basedir, "tmp/plex_movies_export.tsv"), "w") as export_plex, open(path.join(basedir, "tmp/plex_failed_movies.tsv"), "w") as export_fail:
for video in movies.search():
title = str(video.title)
ids = str(video.guids)
imdbid = re.search("(?<=imdb://)(tt\d+)", ids)
if ( imdbid ) :
imdb = str(imdbid.group(1))
location = str(video.locations)[2:-2]
path = pathlib.PurePath(location)
folder = str(path.parent.name)
export=(imdb + "\t" + title + "\t" + folder + "\n")
export_plex.write(export)
else :
export=(title + " no id found" + ids + "\n")
export_fail.write(export)
print(export)