mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2025-02-16 13:58:25 +00:00
[126] use Cached Session
This commit is contained in:
parent
698a0d647e
commit
04e5f49903
3 changed files with 37 additions and 47 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
1.17.3-develop125
|
1.17.3-develop126
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import base64, os, requests
|
import base64, os
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from lxml import html
|
from lxml import html
|
||||||
from modules import util, radarr, sonarr, operations
|
from modules import util, radarr, sonarr, operations
|
||||||
from modules.anidb import AniDB
|
from modules.anidb import AniDB
|
||||||
|
@ -28,6 +28,7 @@ from modules.trakt import Trakt
|
||||||
from modules.tvdb import TVDb
|
from modules.tvdb import TVDb
|
||||||
from modules.util import Failed, NotScheduled, NotScheduledRange, YAML
|
from modules.util import Failed, NotScheduled, NotScheduledRange, YAML
|
||||||
from modules.webhooks import Webhooks
|
from modules.webhooks import Webhooks
|
||||||
|
from requests_cache import CachedSession
|
||||||
from retrying import retry
|
from retrying import retry
|
||||||
|
|
||||||
logger = util.logger
|
logger = util.logger
|
||||||
|
@ -83,7 +84,36 @@ mass_rating_options = {
|
||||||
"mal": "Use MyAnimeList Rating"
|
"mal": "Use MyAnimeList Rating"
|
||||||
}
|
}
|
||||||
reset_overlay_options = {"tmdb": "Reset to TMDb poster", "plex": "Reset to Plex Poster"}
|
reset_overlay_options = {"tmdb": "Reset to TMDb poster", "plex": "Reset to Plex Poster"}
|
||||||
|
urls_expire_after = {
|
||||||
|
"*.imdb.com": 60 * 60 * 6,
|
||||||
|
"www.omdbapi.com/": 60 * 60 * 24,
|
||||||
|
"ergast.com/api/f1/": 60 * 60 * 24,
|
||||||
|
"anidb.net": 60 * 60 * 24,
|
||||||
|
"api.anidb.net:9001/httpapi": 60 * 60 * 24,
|
||||||
|
"graphql.anilist.co": 60 * 60 * 24,
|
||||||
|
"raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Anime-IDs/master/pmm_anime_ids.json": 60 * 60 * 24,
|
||||||
|
"flixpatrol.com": 60 * 60 * 24,
|
||||||
|
"www.themoviedb.org": 60 * 60 * 24,
|
||||||
|
"raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Configs": 60 * 60 * 24,
|
||||||
|
"www.icheckmovies.com/lists/": 60 * 60 * 24,
|
||||||
|
"letterboxd.com": 60 * 60 * 24,
|
||||||
|
"api.myanimelist.net/v2/": 60 * 60 * 24,
|
||||||
|
"api.jikan.moe/v4/": 60 * 60 * 24,
|
||||||
|
"api.trakt.tv": 60 * 60 * 24,
|
||||||
|
"www.thetvdb.com": 60 * 60 * 6,
|
||||||
|
"thetvdb.com": 60 * 60 * 6,
|
||||||
|
"s3.amazonaws.com/popular-movies/movies.json": 60 * 60 * 24,
|
||||||
|
"mdblist.com/lists": 60 * 60 * 12,
|
||||||
|
"mdblist.com/api": 60 * 60 * 1,
|
||||||
|
"api.github.com/repos/meisnate12/Plex-Meta-Manager": 60 * 60 * 1,
|
||||||
|
"raw.githubusercontent.com/meisnate12/": 60 * 60 * 1,
|
||||||
|
"notifiarr.com/api/v1": 0,
|
||||||
|
"dev.notifiarr.com/api/v1": 0,
|
||||||
|
"discord.com": 0,
|
||||||
|
"hooks.slack.com": 0,
|
||||||
|
"raw.githubusercontent.com/meisnate12/Plex-Meta-Manager/**/VERSION": 0,
|
||||||
|
"*": 60 * 60 * 24,
|
||||||
|
}
|
||||||
class ConfigFile:
|
class ConfigFile:
|
||||||
def __init__(self, default_dir, attrs):
|
def __init__(self, default_dir, attrs):
|
||||||
logger.info("Locating config...")
|
logger.info("Locating config...")
|
||||||
|
@ -361,7 +391,8 @@ class ConfigFile:
|
||||||
self.check_nightly = self.general["check_nightly"]
|
self.check_nightly = self.general["check_nightly"]
|
||||||
self.latest_version = util.current_version(self.version, nightly=self.check_nightly)
|
self.latest_version = util.current_version(self.version, nightly=self.check_nightly)
|
||||||
|
|
||||||
self.session = requests.Session()
|
self.session = CachedSession("config/http_cache", expire_after=timedelta(days=1), allowable_methods=["GET"],
|
||||||
|
allowable_codes=[200], match_headers=True, urls_expire_after=urls_expire_after)
|
||||||
if not self.general["verify_ssl"]:
|
if not self.general["verify_ssl"]:
|
||||||
self.session.verify = False
|
self.session.verify = False
|
||||||
if self.session.verify is False:
|
if self.session.verify is False:
|
||||||
|
|
|
@ -1,49 +1,8 @@
|
||||||
import argparse, os, sys, time, uuid
|
import argparse, os, sys, time, uuid
|
||||||
from concurrent.futures import ProcessPoolExecutor
|
from concurrent.futures import ProcessPoolExecutor
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime
|
||||||
from modules.logs import MyLogger
|
from modules.logs import MyLogger
|
||||||
|
|
||||||
urls_expire_after = {
|
|
||||||
'*.imdb.com': 60 * 60 * 6,
|
|
||||||
'www.omdbapi.com/': 60 * 60 * 24,
|
|
||||||
'ergast.com/api/f1/': 60 * 60 * 24,
|
|
||||||
'anidb.net': 60 * 60 * 24,
|
|
||||||
'api.anidb.net:9001/httpapi': 60 * 60 * 24,
|
|
||||||
'graphql.anilist.co': 60 * 60 * 24,
|
|
||||||
'raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Anime-IDs/master/pmm_anime_ids.json': 60 * 60 * 24,
|
|
||||||
'flixpatrol.com': 60 * 60 * 24,
|
|
||||||
'www.themoviedb.org': 60 * 60 * 24,
|
|
||||||
'api.github.com/repos/meisnate12/Plex-Meta-Manager': 60 * 60 * 24,
|
|
||||||
'raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Configs': 60 * 60 * 24,
|
|
||||||
'www.icheckmovies.com/lists/': 60 * 60 * 24,
|
|
||||||
'letterboxd.com': 60 * 60 * 24,
|
|
||||||
'api.myanimelist.net/v2/': 60 * 60 * 24,
|
|
||||||
'api.jikan.moe/v4/': 60 * 60 * 24,
|
|
||||||
'api.trakt.tv': 60 * 60 * 24,
|
|
||||||
'www.thetvdb.com': 60 * 60 * 6,
|
|
||||||
'thetvdb.com': 60 * 60 * 6,
|
|
||||||
's3.amazonaws.com/popular-movies/movies.json': 60 * 60 * 24,
|
|
||||||
'mdblist.com/lists': 60 * 60 * 12,
|
|
||||||
'mdblist.com/api': 60 * 60 * 1,
|
|
||||||
'api.github.com/repos/meisnate12/Plex-Meta-Manager': 60 * 60 * 1,
|
|
||||||
'raw.githubusercontent.com/meisnate12/': 60 * 60 * 1,
|
|
||||||
'notifiarr.com/api/v1': 0,
|
|
||||||
'dev.notifiarr.com/api/v1': 0,
|
|
||||||
'discord.com': 0,
|
|
||||||
'hooks.slack.com': 0,
|
|
||||||
'raw.githubusercontent.com/meisnate12/Plex-Meta-Manager/**/VERSION': 0,
|
|
||||||
'*': 60 * 60 * 24,
|
|
||||||
}
|
|
||||||
|
|
||||||
from requests_cache import install_cache
|
|
||||||
install_cache(
|
|
||||||
'config/http_cache',
|
|
||||||
expire_after=timedelta(days=1), # Otherwise expire responses after one day
|
|
||||||
allowable_methods=['GET', 'POST'], # Cache POST requests to avoid sending the same data twice
|
|
||||||
allowable_codes=[200],
|
|
||||||
match_headers=True,
|
|
||||||
urls_expire_after=urls_expire_after,
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
import plexapi, requests, schedule
|
import plexapi, requests, schedule
|
||||||
from PIL import ImageFile
|
from PIL import ImageFile
|
||||||
|
|
Loading…
Add table
Reference in a new issue