forked from jkirkcaldy/plex-utills
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdv_test.py
126 lines (115 loc) · 4.1 KB
/
dv_test.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from PIL import Image, ImageFile
from plexapi.server import PlexServer
import plexapi
import numpy as np
import requests
import shutil
import os
import re
import imagehash
import logging
from logging.handlers import RotatingFileHandler
import sqlite3
from tmdbv3api import TMDb, Search, Movie, Discover
from pymediainfo import MediaInfo
import json
from tautulli.api import RawAPI
import sys
print("Test running")
try:
var = sys.argv[1]
var2 = sys.argv[2]
except IndexError as e:
print(e)
print("you must enter your film library and a film title")
def setup_logger(logger_name, log_file, level=logging.INFO):
l = logging.getLogger(logger_name)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(message)s")
fileHandler = RotatingFileHandler(
log_file, mode="w", maxBytes=100000, backupCount=5
)
fileHandler.setFormatter(formatter)
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
l.setLevel(level)
l.addHandler(fileHandler)
l.addHandler(streamHandler)
setup_logger("plex-utills", r"/logs/script_log.log")
logger = logging.getLogger("plex-utills")
banner_4k = Image.open("app/img/4K-Template.png")
mini_4k_banner = Image.open("app/img/4K-mini-Template.png")
banner_hdr = Image.open("app/img/hdr-poster.png")
banner_dv = Image.open("app/img/dolby_vision.png")
banner_hdr10 = Image.open("app/img/hdr10.png")
chk_banner = Image.open("app/img/chk-4k.png")
chk_mini_banner = Image.open("app/img/chk-mini-4k2.png")
chk_hdr = Image.open("app/img/chk_hdr.png")
chk_dolby_vision = Image.open("app/img/chk_dolby_vision.png")
chk_hdr10 = Image.open("app/img/chk_hdr10.png")
chk_new_hdr = Image.open("app/img/chk_hdr_new.png")
banner_new_hdr = Image.open("app/img/hdr.png")
atmos = Image.open("app/img/atmos.png")
dtsx = Image.open("app/img/dtsx.png")
atmos_box = Image.open("app/img/chk_atmos.png")
dtsx_box = Image.open("app/img/chk_dtsx.png")
size = (911, 1367)
tv_size = (1280, 720)
box = (0, 0, 911, 100)
mini_box = (0, 0, 150, 125)
hdr_box = (0, 605, 225, 731)
a_box = (0, 731, 225, 803)
tmdb = TMDb()
poster_url_base = "https://www.themoviedb.org/t/p/w600_and_h900_bestv2"
search = Search()
movie = Movie()
discover = Discover()
conn = sqlite3.connect("/config/app.db")
c = conn.cursor()
c.execute("SELECT * FROM plex_utills")
config = c.fetchall()
plex = PlexServer(config[0][1], config[0][2])
films = plex.library.section(var)
# films = plex.library.section("Films")
for i in films.search(title=var2):
t = re.sub(r'[\\/*?:"<>| ]', "_", i.title)
tmp_poster = re.sub(" ", "_", "/tmp/" + t + "_poster.png")
resolution = i.media[0].videoResolution
file = re.sub(config[0][5], "/films", i.media[0].parts[0].file)
m = MediaInfo.parse(file, output="JSON")
x = json.loads(m)
# print(x)
hdr_version = ""
try:
hdr_version = x["media"]["track"][1]["HDR_Format_String"]
except (KeyError, IndexError):
pass
if "dolby" not in str.lower(hdr_version):
try:
hdr_version = x["media"]["track"][1]["HDR_Format_Commercial"]
except (KeyError, IndexError):
try:
hdr_version = x["media"]["track"][1]["HDR_Format_Commercial_IfAny"]
except (KeyError, IndexError):
pass
audio = ""
try:
while True:
for f in range(10):
if "Audio" in x["media"]["track"][f]["@type"]:
if "Format_Commercial_IfAny" in x["media"]["track"][f]:
audio = x["media"]["track"][f]["Format_Commercial_IfAny"]
if (
"DTS" in audio
and "XLL X"
in x["media"]["track"][f]["Format_AdditionalFeatures"]
):
audio = "DTS:X"
break
elif "Format" in x["media"]["track"][f]:
audio = x["media"]["track"][f]["Format"]
break
if audio != "":
break
except IndexError as e:
print(e)
print(i.title + " - " + audio + " - " + hdr_version)