PEP improvements.

This commit is contained in:
morpheus65535 2021-09-28 00:20:22 -04:00
parent bdbf762331
commit e537cd131c
22 changed files with 269 additions and 383 deletions

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import pickle
import random
@ -9,7 +7,7 @@ import os
import logging
import codecs
from pyga.requests import Event, Page, Tracker, Session, Visitor, Config
from pyga.requests import Event, Tracker, Session, Visitor, Config
from pyga.entities import CustomVariable
from get_args import args

View File

@ -1,11 +1,10 @@
# coding=utf-8
# pylama:ignore=W0611,W0401
# TODO unignore and fix W0611,W0401
import sys
import os
import io
import ast
from datetime import timedelta
from datetime import timedelta, datetime
from dateutil import rrule
import pretty
import time
@ -15,10 +14,9 @@ from functools import reduce
import platform
import re
import json
import hashlib
import apprise
import gc
from peewee import fn, Value
from peewee import fn
import requests
from bs4 import BeautifulSoup as bso
@ -26,13 +24,12 @@ from get_args import args
from config import settings, base_url, save_settings, get_settings
from logger import empty_log
from init import *
import logging
from database import get_exclusion_clause, get_profiles_list, get_desired_languages, get_profile_id_name, \
get_audio_profile_languages, update_profile_id_list, convert_list_to_clause, TableEpisodes, TableShows, \
TableMovies, TableSettingsLanguages, TableSettingsNotifier, TableLanguagesProfiles, TableHistory, \
TableHistoryMovie, TableBlacklist, TableBlacklistMovie, TableShowsRootfolder, TableMoviesRootfolder
from get_languages import language_from_alpha2, language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2
from database import get_exclusion_clause, get_profiles_list, get_desired_languages, get_audio_profile_languages, \
update_profile_id_list, TableEpisodes, TableShows, TableMovies, TableSettingsLanguages, TableSettingsNotifier, \
TableLanguagesProfiles, TableHistory, TableHistoryMovie, TableBlacklist, TableBlacklistMovie, \
TableShowsRootfolder, TableMoviesRootfolder
from get_languages import language_from_alpha2, alpha2_from_alpha3, alpha3_from_alpha2
from get_subtitle import download_subtitle, series_download_subtitles, manual_search, manual_download_subtitle, \
manual_upload_subtitle, wanted_search_missing_subtitles_series, wanted_search_missing_subtitles_movies, \
episode_download_subtitles, movies_download_subtitles
@ -43,7 +40,7 @@ from utils import history_log, history_log_movie, blacklist_log, blacklist_delet
blacklist_log_movie, blacklist_delete_movie, blacklist_delete_all_movie, delete_subtitles, subtitles_apply_mods, \
translate_subtitles_file, check_credentials, get_health_issues
from get_providers import get_providers, get_providers_auth, list_throttled_providers, reset_throttled_providers, \
get_throttled_providers, set_throttled_providers
get_throttled_providers
from event_handler import event_stream
from scheduler import scheduler
from subsyncer import subsync
@ -53,7 +50,7 @@ from indexer.movies.local.movies_indexer import list_movies_directories, get_mov
from subliminal_patch.core import SUBTITLE_EXTENSIONS, guessit
from flask import Flask, jsonify, request, Response, Blueprint, url_for, make_response, session
from flask import jsonify, request, Blueprint, session
from flask_restful import Resource, Api, abort
from functools import wraps
@ -328,7 +325,7 @@ class Languages(Resource):
languages += list(TableHistoryMovie.select(TableHistoryMovie.language)
.where(TableHistoryMovie.language is not None)
.dicts())
languages_list = list(set([l['language'].split(':')[0] for l in languages]))
languages_list = list(set([lang['language'].split(':')[0] for lang in languages]))
languages_dicts = []
for language in languages_list:
code2 = None
@ -872,18 +869,16 @@ class EpisodesSubtitles(Resource):
hi = request.form.get('hi')
subtitlesPath = request.form.get('path')
result = delete_subtitles(media_type='series',
language=language,
forced=forced,
hi=hi,
media_path=episodePath,
subtitles_path=subtitlesPath,
series_id=seriesId,
episode_id=episodeId)
delete_subtitles(media_type='series',
language=language,
forced=forced,
hi=hi,
media_path=episodePath,
subtitles_path=subtitlesPath,
series_id=seriesId,
episode_id=episodeId)
return '', 204
result # TODO Placing this after the return doesn't hurt the code flow, but helps ignore
# W0612 local variable X is assigned to but never used
class SeriesRootfolders(Resource):

View File

@ -1,8 +1,6 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
from flask import Flask, redirect, render_template, request, url_for
from flask import Flask
from flask_socketio import SocketIO
import os

View File

@ -1,9 +1,6 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import os
import shutil
import re
import logging
import json

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import hashlib
import os
@ -281,13 +279,9 @@ def get_settings():
def save_settings(settings_items):
from database import database
configure_debug = False
configure_captcha = False
update_schedule = False
# update_path_map = False
# TODO W0612 local variable 'update_path_map' is assigned to but never used
configure_proxy = False
exclusion_updated = False
series_exclusion_updated = False

View File

@ -1,17 +1,12 @@
# pylama:ignore=W0611,W0401
# TODO unignore and fix W0611,W0401
import os
import atexit
import json
import ast
import logging
import gevent
from peewee import *
from peewee import Model, TextField, IntegerField, ForeignKeyField, BlobField, BooleanField
from playhouse.sqliteq import SqliteQueueDatabase
from playhouse.shortcuts import model_to_dict
from playhouse.sqlite_ext import AutoIncrementField
from playhouse.migrate import *
from playhouse.migrate import SqliteMigrator
from config import settings, get_array_from
from get_args import args

View File

@ -1,14 +1,8 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import os
import requests
import logging
import string
from config import settings
headers = {"User-Agent": os.environ["SZ_USER_AGENT"]}

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=E203,W0611
# TODO unignore and fix E203,W0611
import os
import datetime
@ -10,7 +8,6 @@ import pretty
import time
import socket
import requests
import ast
from get_args import args
from config import settings, get_array_from
@ -41,42 +38,42 @@ VALID_COUNT_EXCEPTIONS = ('TooManyRequests', 'ServiceUnavailable', 'APIThrottled
requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout, socket.timeout)
PROVIDER_THROTTLE_MAP = {
"default" : {
TooManyRequests : (datetime.timedelta(hours=1), "1 hour"),
DownloadLimitExceeded : (datetime.timedelta(hours=3), "3 hours"),
ServiceUnavailable : (datetime.timedelta(minutes=20), "20 minutes"),
APIThrottled : (datetime.timedelta(minutes=10), "10 minutes"),
ParseResponseError : (datetime.timedelta(hours=6), "6 hours"),
requests.exceptions.Timeout : (datetime.timedelta(hours=1), "1 hour"),
socket.timeout : (datetime.timedelta(hours=1), "1 hour"),
"default": {
TooManyRequests: (datetime.timedelta(hours=1), "1 hour"),
DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"),
ServiceUnavailable: (datetime.timedelta(minutes=20), "20 minutes"),
APIThrottled: (datetime.timedelta(minutes=10), "10 minutes"),
ParseResponseError: (datetime.timedelta(hours=6), "6 hours"),
requests.exceptions.Timeout: (datetime.timedelta(hours=1), "1 hour"),
socket.timeout: (datetime.timedelta(hours=1), "1 hour"),
requests.exceptions.ConnectTimeout: (datetime.timedelta(hours=1), "1 hour"),
requests.exceptions.ReadTimeout : (datetime.timedelta(hours=1), "1 hour"),
requests.exceptions.ReadTimeout: (datetime.timedelta(hours=1), "1 hour"),
},
"opensubtitles" : {
TooManyRequests : (datetime.timedelta(hours=3), "3 hours"),
"opensubtitles": {
TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
DownloadLimitExceeded: (datetime.timedelta(hours=6), "6 hours"),
DownloadLimitReached : (datetime.timedelta(hours=6), "6 hours"),
APIThrottled : (datetime.timedelta(seconds=15), "15 seconds"),
DownloadLimitReached: (datetime.timedelta(hours=6), "6 hours"),
APIThrottled: (datetime.timedelta(seconds=15), "15 seconds"),
},
"opensubtitlescom": {
TooManyRequests : (datetime.timedelta(minutes=1), "1 minute"),
TooManyRequests: (datetime.timedelta(minutes=1), "1 minute"),
DownloadLimitExceeded: (
datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
},
"addic7ed" : {
"addic7ed": {
DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"),
TooManyRequests : (datetime.timedelta(minutes=5), "5 minutes"),
IPAddressBlocked : (datetime.timedelta(hours=1), "1 hours"),
TooManyRequests: (datetime.timedelta(minutes=5), "5 minutes"),
IPAddressBlocked: (datetime.timedelta(hours=1), "1 hours"),
},
"titulky" : {
"titulky": {
DownloadLimitExceeded: (
datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day)))
},
"legendasdivx" : {
TooManyRequests : (datetime.timedelta(hours=3), "3 hours"),
"legendasdivx": {
TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
DownloadLimitExceeded: (
datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
IPAddressBlocked : (
IPAddressBlocked: (
datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
}
}
@ -124,74 +121,75 @@ def get_providers():
def get_providers_auth():
return {
'addic7ed' : {
'addic7ed': {
'username': settings.addic7ed.username,
'password': settings.addic7ed.password,
},
'opensubtitles' : {
'username' : settings.opensubtitles.username,
'password' : settings.opensubtitles.password,
'opensubtitles': {
'username': settings.opensubtitles.username,
'password': settings.opensubtitles.password,
'use_tag_search': settings.opensubtitles.getboolean(
'use_tag_search'
),
'only_foreign' : False, # TODO
'also_foreign' : False, # TODO
'is_vip' : settings.opensubtitles.getboolean('vip'),
'use_ssl' : settings.opensubtitles.getboolean('ssl'),
'timeout' : int(settings.opensubtitles.timeout) or 15,
'only_foreign': True,
'also_foreign': False,
'is_vip': settings.opensubtitles.getboolean('vip'),
'use_ssl': settings.opensubtitles.getboolean('ssl'),
'timeout': int(settings.opensubtitles.timeout) or 15,
'skip_wrong_fps': settings.opensubtitles.getboolean(
'skip_wrong_fps'
),
},
'opensubtitlescom': {'username': settings.opensubtitlescom.username,
'password': settings.opensubtitlescom.password,
'use_hash': settings.opensubtitlescom.getboolean('use_hash'),
'api_key' : 's38zmzVlW7IlYruWi7mHwDYl2SfMQoC1'
},
'podnapisi' : {
'only_foreign': False, # TODO
'also_foreign': False, # TODO
'opensubtitlescom': {
'username': settings.opensubtitlescom.username,
'password': settings.opensubtitlescom.password,
'use_hash': settings.opensubtitlescom.getboolean('use_hash'),
'api_key': 's38zmzVlW7IlYruWi7mHwDYl2SfMQoC1'
},
'subscene' : {
'username' : settings.subscene.username,
'password' : settings.subscene.password,
'only_foreign': False, # TODO
'podnapisi': {
'only_foreign': True,
'also_foreign': False
},
'legendasdivx' : {
'username' : settings.legendasdivx.username,
'password' : settings.legendasdivx.password,
'skip_wrong_fps': settings.legendasdivx.getboolean(
'skip_wrong_fps'
),
'subscene': {
'username': settings.subscene.username,
'password': settings.subscene.password,
'only_foreign': True
},
'legendastv' : {
'legendasdivx': {
'username': settings.legendasdivx.username,
'password': settings.legendasdivx.password,
'skip_wrong_fps': settings.legendasdivx.getboolean('skip_wrong_fps'),
},
'legendastv': {
'username': settings.legendastv.username,
'password': settings.legendastv.password,
'featured_only': settings.legendastv.getboolean(
'featured_only'
'featured_only'
),
},
'xsubs' : {
'xsubs': {
'username': settings.xsubs.username,
'password': settings.xsubs.password,
},
'assrt' : {
'assrt': {
'token': settings.assrt.token,
},
'napisy24' : {
'napisy24': {
'username': settings.napisy24.username,
'password': settings.napisy24.password,
},
'betaseries' : {'token': settings.betaseries.token},
'titulky' : {
'betaseries': {
'token': settings.betaseries.token
},
'titulky': {
'username': settings.titulky.username,
'password': settings.titulky.password,
},
'titlovi' : {
'titlovi': {
'username': settings.titlovi.username,
'password': settings.titlovi.password,
},
'ktuvit' : {
'ktuvit': {
'email': settings.ktuvit.email,
'hashed_password': settings.ktuvit.hashed_password,
},
@ -259,8 +257,6 @@ def throttled_count(name):
def update_throttled_provider():
# changed = False
# TODO W0612 local variable 'changed' is assigned to but never used
existing_providers = provider_registry.names()
providers_list = [x for x in get_array_from(settings.general.enabled_providers) if x in existing_providers]
@ -268,8 +264,6 @@ def update_throttled_provider():
if provider not in providers_list:
del tp[provider]
settings.general.throtteled_providers = str(tp)
# changed = True
# TODO W0612 local variable 'changed' is assigned to but never used
reason, until, throttle_desc = tp.get(provider, (None, None, None))

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import os
import sys
@ -11,7 +9,6 @@ import time
import pickle
import codecs
import re
import subliminal
import copy
import operator
from functools import reduce
@ -19,26 +16,23 @@ from peewee import fn
from datetime import datetime, timedelta
from subzero.language import Language
from subzero.video import parse_video
from subliminal import region, score as subliminal_scores, \
list_subtitles, Episode, Movie
from subliminal_patch.core import SZAsyncProviderPool, download_best_subtitles, save_subtitles, download_subtitles, \
list_all_subtitles, get_subtitle_path
from subliminal import region, Episode, Movie
from subliminal_patch.core import download_best_subtitles, save_subtitles, download_subtitles, list_all_subtitles
from subliminal_patch.score import compute_score
from subliminal_patch.subtitle import Subtitle
from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2, language_from_alpha2, \
alpha2_from_language, alpha3_from_language
from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2, alpha2_from_language, \
alpha3_from_language
from config import settings, get_array_from
from helper import pp_replace, get_target_folder, force_unicode
from list_subtitles import store_subtitles, list_missing_subtitles, store_subtitles_movie, list_missing_subtitles_movies
from utils import history_log, history_log_movie, get_binary, get_blacklist
from list_subtitles import store_subtitles, store_subtitles_movie
from utils import history_log, history_log_movie, get_blacklist
from notifier import send_notifications, send_notifications_movie
from get_providers import get_providers, get_providers_auth, provider_throttle, provider_pool
from knowit import api
from subsyncer import subsync
from guessit import guessit
from custom_lang import CustomLanguage
from database import get_exclusion_clause, get_profiles_list, get_audio_profile_languages, \
get_desired_languages, TableShows, TableEpisodes, TableMovies, TableHistory, TableHistoryMovie
from database import get_exclusion_clause, get_profiles_list, get_audio_profile_languages, TableShows, TableEpisodes, \
TableMovies, TableHistory, TableHistoryMovie
from event_handler import event_stream, show_progress, hide_progress
from embedded_subs_reader import parse_video_metadata
@ -92,11 +86,7 @@ def download_subtitle(path, language, audio_language, hi, forced, providers, pro
else:
hi = "force non-HI"
if forced == "True":
providers_auth['podnapisi']['only_foreign'] = True # TODO: This is also in get_providers_auth()
providers_auth['subscene']['only_foreign'] = True # TODO: This is also in get_providers_auth()
providers_auth['opensubtitles']['only_foreign'] = True # TODO: This is also in get_providers_auth()
else:
if forced != "True":
providers_auth['podnapisi']['only_foreign'] = False
providers_auth['subscene']['only_foreign'] = False
providers_auth['opensubtitles']['only_foreign'] = False
@ -273,7 +263,7 @@ def download_subtitle(path, language, audio_language, hi, forced, providers, pro
logging.debug('BAZARR No Subtitles were found for this file: ' + path)
return None
subliminal.region.backend.sync()
region.backend.sync()
logging.debug('BAZARR Ended searching Subtitles for file: ' + path)
@ -292,8 +282,6 @@ def manual_search(path, profileId, providers, providers_auth, title, media_type)
for language in language_items:
forced = language['forced']
hi = language['hi']
# audio_exclude = language['audio_exclude']
# TODO W0612 local variable 'audio_exclude' is assigned to but never used
language = language['language']
lang = alpha3_from_alpha2(language)
@ -325,12 +313,6 @@ def manual_search(path, profileId, providers, providers_auth, title, media_type)
minimum_score = settings.general.minimum_score
minimum_score_movie = settings.general.minimum_score_movie
# use_postprocessing = settings.general.getboolean('use_postprocessing')
# TODO W0612 local variable 'use_postprocessing' is assigned to but never used
# postprocessing_cmd = settings.general.postprocessing_cmd
# TODO W0612 local variable 'postprocessing_cmd' is assigned to but never used
if providers:
video = get_video(force_unicode(path), title, providers=providers, media_type=media_type)
else:
@ -444,7 +426,7 @@ def manual_search(path, profileId, providers, providers_auth, title, media_type)
logging.debug('BAZARR ' + str(len(final_subtitles)) + " Subtitles have been found for this file: " + path)
logging.debug('BAZARR Ended searching Subtitles for this file: ' + path)
subliminal.region.backend.sync()
region.backend.sync()
return final_subtitles
@ -587,7 +569,7 @@ def manual_download_subtitle(path, language, audio_language, hi, forced, subtitl
subtitle.provider_name) + ". Please retry later or select a Subtitles from another provider.")
return None
subliminal.region.backend.sync()
region.backend.sync()
logging.debug('BAZARR Ended manually downloading Subtitles for file: ' + path)
@ -693,7 +675,7 @@ def manual_upload_subtitle(path, language, forced, hi, title, media_type, subtit
episode_id, hi=hi)
postprocessing(command, path)
return message, path, subtitles_path # TODO E0602 undefined name 'subtitles_path'
return message, path, subtitle_path
def series_download_subtitles(no):

View File

@ -1,39 +1,15 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import ast
import os
import re
import logging
from charamel import Detector
from bs4 import UnicodeDammit
from config import settings, get_array_from
from config import settings
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3, episode_language, episode_language_code2, episode_language_code3, forced, score, subtitle_id, provider, series_id, episode_id, hi):
if hi:
modifier_string = " HI"
elif forced:
modifier_string = " forced"
else:
modifier_string = ""
modifier_string # TODO W0612 local variable 'modifier_string' is assigned to but never used
if hi:
modifier_code = ":hi"
modifier_code_dot = ".hi"
elif forced:
modifier_code = ":forced"
modifier_code_dot = ".forced"
else:
modifier_code = ""
modifier_code_dot = ""
modifier_code # TODO W0612 local variable 'modifier_code' is assigned to but never used
modifier_code_dot # TODO W0612 local variable 'modifier_code_dot' is assigned to but never used
pp_command = pp_command.replace('{{directory}}', os.path.dirname(episode))
pp_command = pp_command.replace('{{episode}}', episode)
pp_command = pp_command.replace('{{episode_name}}', os.path.splitext(os.path.basename(episode))[0])

View File

@ -1,13 +1,8 @@
# -*- coding: utf-8 -*-
# pylama:ignore=W0611
# TODO unignore and fix W0611
import os
import time
import logging
import gevent
from watchdog.events import PatternMatchingEventHandler
from watchdog.utils import WatchdogShutdown
from config import settings
from bazarr.database import TableShowsRootfolder, TableMoviesRootfolder, TableShows, TableEpisodes, TableMovies
@ -120,8 +115,9 @@ class FileWatcher:
TableEpisodes.update(episode_metadata).where(TableEpisodes.path == event.src_path).execute()
store_subtitles(event.src_path, use_cache=False)
else:
# here we'll deal with movies
# TODO: here we'll deal with movies
pass
TableMovies.select() # prevent unused import until I deal with this part of code
def find_root_dir(self, path):
# return the parent root folder for that episode/movie path

View File

@ -1,14 +1,11 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import os
import re
import logging
from indexer.tmdb_caching_proxy import tmdb
from guessit import guessit
from requests.exceptions import HTTPError
from database import TableShowsRootfolder, TableShows, TableEpisodes
from database import TableShows, TableEpisodes
from indexer.video_prop_reader import video_prop_reader
from indexer.tmdb_caching_proxy import tmdb_func_cache
from indexer.utils import VIDEO_EXTENSION

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import os
import re
@ -10,7 +8,6 @@ from database import TableShowsRootfolder, TableShows
from indexer.tmdb_caching_proxy import tmdb_func_cache
from indexer.utils import normalize_title
from .episodes_indexer import update_series_episodes
from event_handler import show_progress, hide_progress
def list_series_directories(root_dir):

View File

@ -1,13 +1,10 @@
# -*- coding: utf-8 -*-
# pylama:ignore=W0611
# TODO unignore and fix W0611
import datetime
import time
import pickle
import tmdbsimple as tmdb
from subliminal.cache import region
from database import TableTmdbCache
# the cache is marked to expire after 1 day. This could be fine tuned in the future.

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import logging
import os
@ -9,8 +7,7 @@ import enzyme
from enzyme.exceptions import MalformedMKVError
from utils import get_binary
from database import TableEpisodes, TableMovies
from get_languages import create_languages_dict, language_from_alpha3
from get_languages import language_from_alpha3
from indexer.utils import VIDEO_EXTENSION
@ -37,7 +34,7 @@ def video_prop_reader(file):
try:
mkv = enzyme.MKV(f)
except MalformedMKVError:
logger.error( # TODO E0602 undefined name 'logger'
logging.error(
"BAZARR cannot analyze this MKV with our built-in MKV parser, you should install "
"ffmpeg/ffprobe: " + file
)

View File

@ -1,192 +1,186 @@
# coding=utf-8
# pylama:ignore=E401,E402,W0611
# TODO unignore and fix E401,E402,W0611
import os
import datetime
import io
import rarfile
import sys
import os
import subprocess
import sys
import rarfile
import subliminal
from dogpile.cache.region import register_backend as register_cache_backend
from config import settings, configure_captcha_func
from get_args import args
from logger import configure_logging
from dogpile.cache.region import register_backend as register_cache_backend
import subliminal
import datetime
# set subliminal_patch user agent
os.environ["SZ_USER_AGENT"] = "Bazarr/{}".format(os.environ["BAZARR_VERSION"])
def init():
# set subliminal_patch user agent
os.environ["SZ_USER_AGENT"] = "Bazarr/{}".format(os.environ["BAZARR_VERSION"])
# set anti-captcha provider and key
configure_captcha_func()
# set anti-captcha provider and key
configure_captcha_func()
# Check if args.config_dir exist
if not os.path.exists(args.config_dir):
# Create config_dir directory tree
try:
os.mkdir(os.path.join(args.config_dir))
except OSError:
print("BAZARR The configuration directory doesn't exist and Bazarr cannot create it (permission issue?).")
exit(2)
if not os.path.exists(os.path.join(args.config_dir, 'config')):
os.mkdir(os.path.join(args.config_dir, 'config'))
if not os.path.exists(os.path.join(args.config_dir, 'db')):
os.mkdir(os.path.join(args.config_dir, 'db'))
if not os.path.exists(os.path.join(args.config_dir, 'log')):
os.mkdir(os.path.join(args.config_dir, 'log'))
if not os.path.exists(os.path.join(args.config_dir, 'cache')):
os.mkdir(os.path.join(args.config_dir, 'cache'))
configure_logging(settings.general.getboolean('debug') or args.debug)
import logging
def is_virtualenv():
# return True if Bazarr have been start from within a virtualenv or venv
base_prefix = getattr(sys, "base_prefix", None)
# real_prefix will return None if not in a virtualenv enviroment or the default python path
real_prefix = getattr(sys, "real_prefix", None) or sys.prefix
return base_prefix != real_prefix
# deploy requirements.txt
if not args.no_update:
try:
import lxml, numpy, webrtcvad, gevent, geventwebsocket, setuptools
except ImportError:
# Check if args.config_dir exist
if not os.path.exists(args.config_dir):
# Create config_dir directory tree
try:
import pip
os.mkdir(os.path.join(args.config_dir))
except OSError:
print("BAZARR The configuration directory doesn't exist and Bazarr cannot create it (permission issue?).")
exit(2)
if not os.path.exists(os.path.join(args.config_dir, 'config')):
os.mkdir(os.path.join(args.config_dir, 'config'))
if not os.path.exists(os.path.join(args.config_dir, 'db')):
os.mkdir(os.path.join(args.config_dir, 'db'))
if not os.path.exists(os.path.join(args.config_dir, 'log')):
os.mkdir(os.path.join(args.config_dir, 'log'))
if not os.path.exists(os.path.join(args.config_dir, 'cache')):
os.mkdir(os.path.join(args.config_dir, 'cache'))
configure_logging(settings.general.getboolean('debug') or args.debug)
import logging
def is_virtualenv():
# return True if Bazarr have been start from within a virtualenv or venv
base_prefix = getattr(sys, "base_prefix", None)
# real_prefix will return None if not in a virtualenv environment or the default python path
real_prefix = getattr(sys, "real_prefix", None) or sys.prefix
return base_prefix != real_prefix
# deploy requirements.txt
if not args.no_update:
try:
import lxml, numpy, webrtcvad, gevent, geventwebsocket, setuptools # noqa
except ImportError:
logging.info('BAZARR unable to install requirements (pip not installed).')
else:
if os.path.expanduser("~") == '/':
logging.info('BAZARR unable to install requirements (user without home directory).')
try:
import pip # noqa
except ImportError:
logging.info('BAZARR unable to install requirements (pip not installed).')
else:
logging.info('BAZARR installing requirements...')
try:
pip_command = [sys.executable, '-m', 'pip', 'install', '-qq', '--disable-pip-version-check',
'-r', os.path.join(os.path.dirname(os.path.dirname(__file__)), 'requirements.txt')]
if not is_virtualenv():
# --user only make sense if not running under venv
pip_command.insert(4, '--user')
subprocess.check_output(pip_command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
logging.exception('BAZARR requirements.txt installation result: {}'.format(e.stdout))
os._exit(1)
if os.path.expanduser("~") == '/':
logging.info('BAZARR unable to install requirements (user without home directory).')
else:
logging.info('BAZARR requirements installed.')
logging.info('BAZARR installing requirements...')
try:
pip_command = [sys.executable, '-m', 'pip', 'install', '-qq', '--disable-pip-version-check',
'-r', os.path.join(os.path.dirname(os.path.dirname(__file__)), 'requirements.txt')]
if not is_virtualenv():
# --user only make sense if not running under venv
pip_command.insert(4, '--user')
subprocess.check_output(pip_command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
logging.exception('BAZARR requirements.txt installation result: {}'.format(e.stdout))
os._exit(1)
else:
logging.info('BAZARR requirements installed.')
try:
restart_file = io.open(os.path.join(args.config_dir, "bazarr.restart"), "w", encoding='UTF-8')
except Exception as e:
logging.error('BAZARR Cannot create bazarr.restart file: ' + repr(e))
else:
logging.info('Bazarr is being restarted...')
restart_file.write(str(''))
restart_file.close()
os._exit(0)
try:
restart_file = io.open(os.path.join(args.config_dir, "bazarr.restart"), "w", encoding='UTF-8')
except Exception as e:
logging.error('BAZARR Cannot create bazarr.restart file: ' + repr(e))
else:
logging.info('Bazarr is being restarted...')
restart_file.write(str(''))
restart_file.close()
os._exit(0)
# create random api_key if there's none in config.ini
if not settings.auth.apikey or settings.auth.apikey.startswith("b'"):
from binascii import hexlify
settings.auth.apikey = hexlify(os.urandom(16)).decode()
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
# create random Flask secret_key if there's none in config.ini
if not settings.general.flask_secret_key:
from binascii import hexlify
settings.general.flask_secret_key = hexlify(os.urandom(16)).decode()
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
# change default base_url to ''
settings.general.base_url = settings.general.base_url.rstrip('/')
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
# migrate enabled_providers from comma separated string to list
if isinstance(settings.general.enabled_providers, str) and not settings.general.enabled_providers.startswith('['):
settings.general.enabled_providers = str(settings.general.enabled_providers.split(","))
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
# make sure settings.general.branch is properly set when running inside a docker container
package_info_file = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'package_info')
if os.path.isfile(package_info_file):
try:
splitted_lines = []
package_info = {}
with open(package_info_file) as file:
lines = file.readlines()
for line in lines:
splitted_lines += line.split(r'\n')
for line in splitted_lines:
splitted_line = line.split('=')
if len(splitted_line) == 2:
package_info[splitted_line[0].lower()] = splitted_line[1].replace('\n', '')
else:
continue
if 'branch' in package_info:
settings.general.branch = package_info['branch']
except Exception:
pass
else:
# create random api_key if there's none in config.ini
if not settings.auth.apikey or settings.auth.apikey.startswith("b'"):
from binascii import hexlify
settings.auth.apikey = hexlify(os.urandom(16)).decode()
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
# Configure dogpile file caching for Subliminal request
register_cache_backend("subzero.cache.file", "subzero.cache_backends.file", "SZFileBackend")
subliminal.region.configure('subzero.cache.file', expiration_time=datetime.timedelta(days=30),
arguments={'appname': "sz_cache", 'app_cache_dir': args.config_dir})
subliminal.region.backend.sync()
# create random Flask secret_key if there's none in config.ini
if not settings.general.flask_secret_key:
from binascii import hexlify
settings.general.flask_secret_key = hexlify(os.urandom(16)).decode()
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
if not os.path.exists(os.path.join(args.config_dir, 'config', 'releases.txt')):
from check_update import check_releases
check_releases()
logging.debug("BAZARR Created releases file")
config_file = os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini'))
# Move GA visitor from config.ini to dedicated file
if settings.analytics.visitor:
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat')), 'w+') as handle:
handle.write(settings.analytics.visitor)
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini')), 'w+') as handle:
settings.remove_option('analytics', 'visitor')
# change default base_url to ''
settings.general.base_url = settings.general.base_url.rstrip('/')
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
# Clean unused settings from config.ini
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini')), 'w+') as handle:
settings.remove_option('general', 'throtteled_providers')
settings.remove_option('general', 'update_restart')
settings.write(handle)
# migrate enabled_providers from comma separated string to list
if isinstance(settings.general.enabled_providers, str) and not settings.general.enabled_providers.startswith('['):
settings.general.enabled_providers = str(settings.general.enabled_providers.split(","))
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
# make sure settings.general.branch is properly set when running inside a docker container
package_info_file = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'package_info')
if os.path.isfile(package_info_file):
try:
splitted_lines = []
package_info = {}
with open(package_info_file) as file:
lines = file.readlines()
for line in lines:
splitted_lines += line.split(r'\n')
for line in splitted_lines:
splitted_line = line.split('=')
if len(splitted_line) == 2:
package_info[splitted_line[0].lower()] = splitted_line[1].replace('\n', '')
else:
continue
if 'branch' in package_info:
settings.general.branch = package_info['branch']
except Exception:
pass
else:
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
def init_binaries():
from utils import get_binary
exe = get_binary("unrar")
# Configure dogpile file caching for Subliminal request
register_cache_backend("subzero.cache.file", "subzero.cache_backends.file", "SZFileBackend")
subliminal.region.configure('subzero.cache.file', expiration_time=datetime.timedelta(days=30),
arguments={'appname': "sz_cache", 'app_cache_dir': args.config_dir})
subliminal.region.backend.sync()
rarfile.UNRAR_TOOL = exe
rarfile.ORIG_UNRAR_TOOL = exe
try:
rarfile.custom_check([rarfile.UNRAR_TOOL], True)
except Exception:
logging.debug("custom check failed for: %s", exe)
if not os.path.exists(os.path.join(args.config_dir, 'config', 'releases.txt')):
from check_update import check_releases
check_releases()
logging.debug("BAZARR Created releases file")
rarfile.OPEN_ARGS = rarfile.ORIG_OPEN_ARGS
rarfile.EXTRACT_ARGS = rarfile.ORIG_EXTRACT_ARGS
rarfile.TEST_ARGS = rarfile.ORIG_TEST_ARGS
logging.debug("Using UnRAR from: %s", exe)
unrar = exe
# Move GA visitor from config.ini to dedicated file
if settings.analytics.visitor:
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat')), 'w+') as handle:
handle.write(settings.analytics.visitor)
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini')), 'w+') as handle:
settings.remove_option('analytics', 'visitor')
settings.write(handle)
return unrar
# Clean unused settings from config.ini
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini')), 'w+') as handle:
settings.remove_option('general', 'throtteled_providers')
settings.remove_option('general', 'update_restart')
settings.write(handle)
def init_binaries():
from utils import get_binary
exe = get_binary("unrar")
from database import init_db, migrate_db
init_db()
migrate_db()
init_binaries()
rarfile.UNRAR_TOOL = exe
rarfile.ORIG_UNRAR_TOOL = exe
try:
rarfile.custom_check([rarfile.UNRAR_TOOL], True)
except Exception:
logging.debug("custom check failed for: %s", exe)
rarfile.OPEN_ARGS = rarfile.ORIG_OPEN_ARGS
rarfile.EXTRACT_ARGS = rarfile.ORIG_EXTRACT_ARGS
rarfile.TEST_ARGS = rarfile.ORIG_TEST_ARGS
logging.debug("Using UnRAR from: %s", exe)
unrar = exe
return unrar
from database import init_db, migrate_db
init_db()
migrate_db()
init_binaries()

View File

@ -18,7 +18,3 @@ def clean_libs():
def set_libs():
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../libs/'))
clean_libs()
set_libs()

View File

@ -1,10 +1,9 @@
# coding=utf-8
# pylama:ignore=E402,W0401,W0611
# TODO unignore and fix W0401,E402,W0611
# pylama:ignore=E402
# Gevent monkey patch if gevent available. If not, it will be installed on during the init process.
try:
from gevent import monkey, Greenlet, joinall
from gevent import monkey, Greenlet
except ImportError:
pass
else:
@ -22,22 +21,24 @@ if os.path.isfile(version_file):
os.environ["BAZARR_VERSION"] = bazarr_version.lstrip('v')
import libs
from libs import clean_libs, set_libs
clean_libs()
set_libs()
from get_args import args
from config import settings, configure_proxy_func, base_url
from init import *
from init import init
init()
from database import System
from notifier import update_notifier
from urllib.parse import unquote
from get_languages import load_language_in_db
from flask import make_response, request, redirect, abort, render_template, Response, session, flash, url_for, \
send_file, stream_with_context
from flask import request, redirect, abort, render_template, session, send_file
from check_update import apply_update, check_if_new_update, check_releases
from check_update import apply_update, check_releases
from server import app, webserver
from functools import wraps
from utils import check_credentials

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=E402
# TODO unignore and fix E402
from config import settings
from get_subtitle import wanted_search_missing_subtitles_series, wanted_search_missing_subtitles_movies, \

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=E402
# TODO unignore and fix E402
import warnings
import logging
@ -16,7 +14,7 @@ from database import database
from app import create_app
app = create_app()
from api import api_bp
from api import api_bp # noqa
app.register_blueprint(api_bp)

View File

@ -1,6 +1,3 @@
# pylama:ignore=W0611
# TODO unignore and fix W0611
import logging
import os
from ffsubsync.ffsubsync import run, make_parser
@ -19,7 +16,7 @@ class SubSyncer:
self.ffmpeg_path = None
self.args = None
try:
import webrtcvad
import webrtcvad # noqa
except ImportError:
self.vad = 'subs_then_auditok'
else:

View File

@ -1,6 +1,4 @@
# coding=utf-8
# pylama:ignore=W0611
# TODO unignore and fix W0611
import os
import time
@ -16,10 +14,9 @@ from whichcraft import which
from get_args import args
from config import settings
from custom_lang import CustomLanguage
from database import TableHistory, TableHistoryMovie, TableBlacklist, TableBlacklistMovie, TableShowsRootfolder, \
TableMoviesRootfolder
from database import TableHistory, TableHistoryMovie, TableBlacklist, TableBlacklistMovie
from event_handler import event_stream
from get_languages import alpha2_from_alpha3, language_from_alpha3, language_from_alpha2, alpha3_from_alpha2
from get_languages import language_from_alpha2, alpha3_from_alpha2
from list_subtitles import store_subtitles, store_subtitles_movie
from subliminal_patch.subtitle import Subtitle
from subliminal_patch.core import get_subtitle_path
@ -31,7 +28,6 @@ import datetime
import glob
region = make_region().configure('dogpile.cache.memory')
# headers = {"User-Agent": os.environ["SZ_USER_AGENT"]}
class BinaryNotFound(Exception):
@ -374,8 +370,7 @@ def check_health():
if settings.general.getboolean('use_series'):
pass
if settings.general.getboolean('use_movies'):
check_movies_rootfolder() # TODO E0602 undefined name 'check_movies_rootfolder'
pass
pass
def get_health_issues():