1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-27 01:57:33 +00:00

Continuing development

This commit is contained in:
Louis Vézina 2019-02-07 22:34:54 -05:00
parent 33e4cfc758
commit ab8b070c68
3 changed files with 83 additions and 16 deletions

View file

@ -3,6 +3,7 @@ import os
import sqlite3 import sqlite3
import requests import requests
import logging import logging
import re
from queueconfig import q4ws from queueconfig import q4ws
from get_args import args from get_args import args
@ -82,6 +83,22 @@ def sync_episodes():
format = episode['episodeFile']['quality']['quality']['name'] format = episode['episodeFile']['quality']['quality']['name']
resolution = str(episode['episodeFile']['quality']['quality']['resolution']) + 'p' resolution = str(episode['episodeFile']['quality']['quality']['resolution']) + 'p'
videoCodec = episode['episodeFile']['mediaInfo']['videoCodec']
if videoCodec.startswith('x264'): videoCodec = 'h264'
elif videoCodec.startswith('XviD'): videoCodec = 'XviD'
elif videoCodec.startswith('DivX'): videoCodec = 'DivX'
elif videoCodec.startswith('MPEG-1 Video'): videoCodec = 'Mpeg'
elif videoCodec.startswith('MPEG-2 Video'): videoCodec = 'Mpeg2'
elif videoCodec.startswith('MPEG-4 Video'): videoCodec = 'Mpeg4'
elif videoCodec.endswith('VP6'): videoCodec = 'VP6'
elif videoCodec.endswith('VP7'): videoCodec = 'VP7'
elif videoCodec.endswith('VP8'): videoCodec = 'VP8'
elif videoCodec.endswith('VP9'): videoCodec = 'VP9'
audioCodec = episode['episodeFile']['mediaInfo']['audioCodec']
if audioCodec == 'AC-3': audioCodec = 'AC3'
elif audioCodec == 'MPEG Audio': audioCodec = 'MP3'
# Add episodes in sonarr to current episode list # Add episodes in sonarr to current episode list
current_episodes_sonarr.append(episode['id']) current_episodes_sonarr.append(episode['id'])
@ -90,16 +107,13 @@ def sync_episodes():
episode['seasonNumber'], episode['episodeNumber'], episode['seasonNumber'], episode['episodeNumber'],
sceneName, str(bool(episode['monitored'])), sceneName, str(bool(episode['monitored'])),
format, resolution, format, resolution,
episode['episodeFile']['mediaInfo']['videoCodec'], videoCodec, audioCodec, episode['id']))
episode['episodeFile']['mediaInfo']['audioCodec'],
episode['id']))
else: else:
episodes_to_add.append((episode['seriesId'], episode['id'], episode['title'], episodes_to_add.append((episode['seriesId'], episode['id'], episode['title'],
episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeFile']['path'], episode['seasonNumber'],
episode['episodeNumber'], sceneName, episode['episodeNumber'], sceneName,
str(bool(episode['monitored'])), format, resolution, str(bool(episode['monitored'])), format, resolution,
episode['episodeFile']['mediaInfo']['videoCodec'], videoCodec, audioCodec))
episode['episodeFile']['mediaInfo']['audioCodec']))
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))

View file

@ -83,6 +83,18 @@ def update_movies():
format = movie['movieFile']['quality']['quality']['name'] format = movie['movieFile']['quality']['quality']['name']
resolution = movie['movieFile']['quality']['quality']['resolution'].lstrip('r').lower() resolution = movie['movieFile']['quality']['quality']['resolution'].lstrip('r').lower()
videoFormat = movie['movieFile']['mediaInfo']['videoFormat']
videoCodecID = movie['movieFile']['mediaInfo']['videoCodecID']
videoProfile = movie['movieFile']['mediaInfo']['videoProfile']
videoCodecLibrary = movie['movieFile']['mediaInfo']['videoCodecLibrary']
videoCodec = RadarrFormatVideoCodec(videoFormat, videoCodecID, videoProfile, videoCodecLibrary)
audioFormat = movie['movieFile']['mediaInfo']['audioFormat']
audioCodecID = movie['movieFile']['mediaInfo']['audioCodecID']
audioProfile = movie['movieFile']['mediaInfo']['audioProfile']
audioAdditionalFeatures = movie['movieFile']['mediaInfo']['audioAdditionalFeatures']
audioCodec = RadarrFormatAudioCodec(audioFormat, audioCodecID, audioProfile, audioAdditionalFeatures)
# Add movies in radarr to current movies list # Add movies in radarr to current movies list
current_movies_radarr.append(unicode(movie['tmdbId'])) current_movies_radarr.append(unicode(movie['tmdbId']))
@ -99,9 +111,7 @@ def update_movies():
profile_id_to_language(movie['qualityProfileId']), sceneName, profile_id_to_language(movie['qualityProfileId']), sceneName,
unicode(bool(movie['monitored'])), movie['sortTitle'], unicode(bool(movie['monitored'])), movie['sortTitle'],
movie['year'], alternativeTitles, format, resolution, movie['year'], alternativeTitles, format, resolution,
movie['movieFile']['mediaInfo']['videoCodecLibrary'], videoCodec, audioCodec, movie["tmdbId"]))
movie['movieFile']['mediaInfo']['audioFormat'],
movie["tmdbId"]))
else: else:
if movie_default_enabled is True: if movie_default_enabled is True:
movies_to_add.append((movie["title"], movies_to_add.append((movie["title"],
@ -111,8 +121,7 @@ def update_movies():
profile_id_to_language(movie['qualityProfileId']), sceneName, profile_id_to_language(movie['qualityProfileId']), sceneName,
unicode(bool(movie['monitored'])), movie['sortTitle'], unicode(bool(movie['monitored'])), movie['sortTitle'],
movie['year'], alternativeTitles, format, resolution, movie['year'], alternativeTitles, format, resolution,
movie['movieFile']['mediaInfo']['videoCodecLibrary'], videoCodec, audioCodec))
movie['movieFile']['mediaInfo']['audioFormat']))
else: else:
movies_to_add.append((movie["title"], movies_to_add.append((movie["title"],
movie["path"] + separator + movie['movieFile'][ movie["path"] + separator + movie['movieFile'][
@ -121,8 +130,7 @@ def update_movies():
profile_id_to_language(movie['qualityProfileId']), sceneName, profile_id_to_language(movie['qualityProfileId']), sceneName,
unicode(bool(movie['monitored'])), movie['sortTitle'], unicode(bool(movie['monitored'])), movie['sortTitle'],
movie['year'], alternativeTitles, format, resolution, movie['year'], alternativeTitles, format, resolution,
movie['moviefile']['mediaInfo']['videoCodecLibrary'], videoCodec, audioCodec))
movie['moviefile']['mediaInfo']['audioFormat']))
else: else:
logging.error( logging.error(
'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + 'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator +
@ -201,5 +209,51 @@ def profile_id_to_language(id):
return profile[1] return profile[1]
def RadarrFormatAudioCodec(audioFormat, audioCodecID, audioProfile, audioAdditionalFeatures):
if audioFormat == "AC-3": return "AC3"
if audioFormat == "E-AC-3": return "EAC3"
if audioFormat == "AAC":
if audioCodecID == "A_AAC/MPEG4/LC/SBR":
return "HE-AAC"
else:
return "AAC"
if audioFormat.strip() == "mp3": return "MP3"
if audioFormat == "MPEG Audio":
if audioCodecID == "55" or audioCodecID == "A_MPEG/L3" or audioProfile == "Layer 3": return "MP3"
if audioCodecID == "A_MPEG/L2" or audioProfile == "Layer 2": return "MP2"
if audioFormat == "MLP FBA":
if audioAdditionalFeatures == "16-ch":
return "TrueHD Atmos"
else:
return "TrueHD"
return audioFormat
def RadarrFormatVideoCodec(videoFormat, videoCodecID, videoProfile, videoCodecLibrary):
if videoFormat == "x264": return "h264"
if videoFormat == "AVC" or videoFormat == "V.MPEG4/ISO/AVC": return "h264"
if videoFormat == "HEVC" or videoFormat == "V_MPEGH/ISO/HEVC":
if videoCodecLibrary.startswith("x265"): return "h265"
if videoFormat == "MPEG Video":
if videoCodecID == "2" or videoCodecID == "V_MPEG2":
return "Mpeg2"
else:
return "Mpeg"
if videoFormat == "MPEG-1 Video": return "Mpeg"
if videoFormat == "MPEG-2 Video": return "Mpeg2"
if videoFormat == "MPEG-4 Visual":
if videoCodecID.endswith("XVID") or videoCodecLibrary.startswith("XviD"): return "XviD"
if videoCodecID.endswith("DIV3") or videoCodecID.endswith("DIVX") or videoCodecID.endswith(
"DX50") or videoCodecLibrary.startswith("DivX"): return "DivX"
if videoFormat == "VC-1": return "VC1"
if videoFormat == "WMV2":
return "WMV"
if videoFormat == "DivX" or videoFormat == "div3":
return "DivX"
return videoFormat
if __name__ == '__main__': if __name__ == '__main__':
update_movies() update_movies()

View file

@ -689,7 +689,7 @@ def refine_from_db(path, video):
c = db.cursor() c = db.cursor()
data = c.execute("SELECT table_shows.title, table_episodes.season, table_episodes.episode, table_episodes.title, table_shows.year, table_shows.tvdbId, table_shows.alternateTitles, table_episodes.format, table_episodes.resolution, table_episodes.video_codec, table_episodes.audio_codec FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ?", (path_replace_reverse(path),)).fetchone() data = c.execute("SELECT table_shows.title, table_episodes.season, table_episodes.episode, table_episodes.title, table_shows.year, table_shows.tvdbId, table_shows.alternateTitles, table_episodes.format, table_episodes.resolution, table_episodes.video_codec, table_episodes.audio_codec FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ?", (path_replace_reverse(path),)).fetchone()
db.close() db.close()
if data != None: if data:
video.series = re.sub(r'(\(\d\d\d\d\))' , '', data[0]) video.series = re.sub(r'(\(\d\d\d\d\))' , '', data[0])
video.season = int(data[1]) video.season = int(data[1])
video.episode = int(data[2]) video.episode = int(data[2])
@ -702,8 +702,7 @@ def refine_from_db(path, video):
if not video.resolution: if not video.resolution:
video.resolution = str(data[8]) video.resolution = str(data[8])
if not video.video_codec: if not video.video_codec:
if data[9] == 'x264': video.video_codec = 'h264' if data[9]: video.video_codec = data[9]
elif data[9]: video.video_codec = data[9]
if not video.audio_codec: if not video.audio_codec:
if data[10]: video.audio_codec = data[10] if data[10]: video.audio_codec = data[10]
elif isinstance(video, Movie): elif isinstance(video, Movie):
@ -711,7 +710,7 @@ def refine_from_db(path, video):
c = db.cursor() c = db.cursor()
data = c.execute("SELECT title, year, alternativeTitles, format, resolution, video_codec, audio_codec FROM table_movies WHERE path = ?", (path_replace_reverse_movie(path),)).fetchone() data = c.execute("SELECT title, year, alternativeTitles, format, resolution, video_codec, audio_codec FROM table_movies WHERE path = ?", (path_replace_reverse_movie(path),)).fetchone()
db.close() db.close()
if data != None: if data:
video.title = re.sub(r'(\(\d\d\d\d\))' , '', data[0]) video.title = re.sub(r'(\(\d\d\d\d\))' , '', data[0])
if int(data[1]) > 0: video.year = int(data[1]) if int(data[1]) > 0: video.year = int(data[1])
video.alternative_titles = ast.literal_eval(data[2]) video.alternative_titles = ast.literal_eval(data[2])