Skip to content

Commit

Permalink
[25] add requests module
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed May 28, 2024
1 parent 7d51741 commit 2ad6771
Show file tree
Hide file tree
Showing 39 changed files with 894 additions and 792 deletions.
5 changes: 5 additions & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AAC
accessModes
Addon
Adlib
AFI's
Amblin
analytics
AniDB
Expand All @@ -19,6 +20,7 @@ Arrowverse
Atmos
Avenir
BAFTA
Bambara
BBFC
bearlikelion
Berlinale
Expand Down Expand Up @@ -56,6 +58,7 @@ customizable
customizations
César
dbader
d'Or
de
deva
DIIIVOY
Expand Down Expand Up @@ -177,6 +180,7 @@ microsoft
mikenobbs
minikube
mnt
Mojo's
monetization
Mossi
MPAA
Expand All @@ -202,6 +206,7 @@ OMDb
oscar
OSX
ozzy
Palme
pathing
PCM
PersistentVolumeClaim
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1-develop24
2.0.1-develop25
25 changes: 0 additions & 25 deletions docs/config/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -934,31 +934,6 @@ The available setting attributes which can be set at each level are outlined bel
- metadata
```

??? blank "`verify_ssl` - Turn SSL Verification on or off.<a class="headerlink" href="#verify-ssl" title="Permanent link">¶</a>"

<div id="verify-ssl" />Turn SSL Verification on or off.

???+ note

set to false if your log file shows any errors similar to "SSL: CERTIFICATE_VERIFY_FAILED"

<hr style="margin: 0px;">

**Attribute:** `verify_ssl`

**Levels with this Attribute:** Global

**Accepted Values:** `true` or `false`

**Default Value:** `true`

???+ example "Example"
```yaml
settings:
verify_ssl: false
```

??? blank "`custom_repo` - Used to set up the custom `repo` [file block type](files.md#location-types-and-paths).<a class="headerlink" href="#custom-repo" title="Permanent link">¶</a>"

<div id="custom-repo" />Specify where the `repo` attribute's base is when defining `collection_files`, `metadata_files`, `playlist_file` and `overlay_files`.
Expand Down
26 changes: 26 additions & 0 deletions docs/kometa/environmental.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,32 @@ different ways to specify these things.
docker run -it -v "X:\Media\Kometa\config:/config:rw" kometateam/kometa --timeout 360
```

??? blank "No Verify SSL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`-nv`/`--no-verify-ssl`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`KOMETA_NO_VERIFY_SSL`<a class="headerlink" href="#no-verify-ssl" title="Permanent link">¶</a>"

<div id="no-verify-ssl" />Turn SSL Verification off.

???+ note

set to false if your log file shows any errors similar to "SSL: CERTIFICATE_VERIFY_FAILED"

<hr style="margin: 0px;">

**Accepted Values:** Integer (value is in seconds)

**Shell Flags:** `-nv` or `--no-verify-ssl` (ex. `--no-verify-ssl`)

**Environment Variable:** `KOMETA_NO_VERIFY_SSL` (ex. `KOMETA_NO_VERIFY_SSL=true`)

!!! example
=== "Local Environment"
```
python kometa.py --no-verify-ssl
```
=== "Docker Environment"
```
docker run -it -v "X:\Media\Kometa\config:/config:rw" kometateam/kometa --no-verify-ssl
```

??? blank "Collections Only&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`-co`/`--collections-only`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`KOMETA_COLLECTIONS_ONLY`<a class="headerlink" href="#collections-only" title="Permanent link">¶</a>"

<div id="collections-only" />Only run collection YAML files, skip library operations, metadata, overlays, and playlists.
Expand Down
336 changes: 169 additions & 167 deletions kometa.py

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions modules/anidb.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def _parse(attr, xpath, is_list=False, is_dict=False, is_int=False, is_float=Fal


class AniDB:
def __init__(self, config, data):
self.config = config
def __init__(self, requests, cache, data):
self.requests = requests
self.cache = cache
self.language = data["language"]
self.expiration = 60
self.client = None
Expand All @@ -104,19 +105,19 @@ def authorize(self, client, version, expiration):
self.version = version
self.expiration = expiration
logger.secret(self.client)
if self.config.Cache:
value1, value2, success = self.config.Cache.query_testing("anidb_login")
if self.cache:
value1, value2, success = self.cache.query_testing("anidb_login")
if str(value1) == str(client) and str(value2) == str(version) and success:
return
try:
self.get_anime(69, ignore_cache=True)
if self.config.Cache:
self.config.Cache.update_testing("anidb_login", self.client, self.version, "True")
if self.cache:
self.cache.update_testing("anidb_login", self.client, self.version, "True")
except Failed:
self.client = None
self.version = None
if self.config.Cache:
self.config.Cache.update_testing("anidb_login", self.client, self.version, "False")
if self.cache:
self.cache.update_testing("anidb_login", self.client, self.version, "False")
raise

@property
Expand All @@ -137,9 +138,9 @@ def _request(self, url, params=None, data=None):
if params:
logger.trace(f"Params: {params}")
if data:
return self.config.post_html(url, data=data, headers=util.header(self.language))
return self.requests.post_html(url, data=data, language=self.language)
else:
return self.config.get_html(url, params=params, headers=util.header(self.language))
return self.requests.get_html(url, params=params, language=self.language)

def _popular(self):
response = self._request(urls["popular"])
Expand Down Expand Up @@ -184,8 +185,8 @@ def _tag(self, tag, limit):
def get_anime(self, anidb_id, ignore_cache=False):
expired = None
anidb_dict = None
if self.config.Cache and not ignore_cache:
anidb_dict, expired = self.config.Cache.query_anidb(anidb_id, self.expiration)
if self.cache and not ignore_cache:
anidb_dict, expired = self.cache.query_anidb(anidb_id, self.expiration)
if expired or not anidb_dict:
time_check = time.time()
if self._delay is not None:
Expand All @@ -200,8 +201,8 @@ def get_anime(self, anidb_id, ignore_cache=False):
})
self._delay = time.time()
obj = AniDBObj(self, anidb_id, anidb_dict)
if self.config.Cache and not ignore_cache:
self.config.Cache.update_anidb(expired, anidb_id, obj, self.expiration)
if self.cache and not ignore_cache:
self.cache.update_anidb(expired, anidb_id, obj, self.expiration)
return obj

def get_anidb_ids(self, method, data):
Expand Down
6 changes: 3 additions & 3 deletions modules/anilist.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
]

class AniList:
def __init__(self, config):
self.config = config
def __init__(self, requests):
self.requests = requests
self._options = None

@property
Expand All @@ -79,7 +79,7 @@ def options(self):
def _request(self, query, variables, level=1):
logger.trace(f"Query: {query}")
logger.trace(f"Variables: {variables}")
response = self.config.post(base_url, json={"query": query, "variables": variables})
response = self.requests.post(base_url, json={"query": query, "variables": variables})
json_obj = response.json()
logger.trace(f"Response: {json_obj}")
if "errors" in json_obj:
Expand Down
31 changes: 12 additions & 19 deletions modules/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from modules.util import Failed, FilterFailed, NonExisting, NotScheduled, NotScheduledRange, Deleted
from modules.overlay import Overlay
from modules.poster import KometaImage
from modules.request import quote
from plexapi.audio import Artist, Album, Track
from plexapi.exceptions import NotFound
from plexapi.video import Movie, Show, Season, Episode
from requests.exceptions import ConnectionError
from urllib.parse import quote

logger = util.logger

Expand Down Expand Up @@ -559,9 +558,7 @@ def apply_vars(input_str, var_set, var_key, var_limit):
self.obj = getter(self.name)
break
except Failed as e:
error = e
else:
logger.error(error)
logger.error(e)
raise Deleted(self.delete())
else:
self.libraries.append(self.library)
Expand Down Expand Up @@ -1182,11 +1179,9 @@ def _poster(self, method_name, method_data):
if method_name == "url_poster":
try:
if not method_data.startswith("https://theposterdb.com/api/assets/"):
image_response = self.config.get(method_data, headers=util.header())
if image_response.status_code >= 400 or image_response.headers["Content-Type"] not in util.image_content_types:
raise ConnectionError
self.config.Requests.get_image(method_data)
self.posters[method_name] = method_data
except ConnectionError:
except Failed:
logger.warning(f"{self.Type} Warning: No Poster Found at {method_data}")
elif method_name == "tmdb_list_poster":
self.posters[method_name] = self.config.TMDb.get_list(util.regex_first_int(method_data, "TMDb List ID")).poster_url
Expand All @@ -1209,11 +1204,9 @@ def _poster(self, method_name, method_data):
def _background(self, method_name, method_data):
if method_name == "url_background":
try:
image_response = self.config.get(method_data, headers=util.header())
if image_response.status_code >= 400 or image_response.headers["Content-Type"] not in util.image_content_types:
raise ConnectionError
self.config.Requests.get_image(method_data)
self.backgrounds[method_name] = method_data
except ConnectionError:
except Failed:
logger.warning(f"{self.Type} Warning: No Background Found at {method_data}")
elif method_name == "tmdb_background":
self.backgrounds[method_name] = self.config.TMDb.get_movie_show_or_collection(util.regex_first_int(method_data, 'TMDb ID'), self.library.is_movie).backdrop_url
Expand Down Expand Up @@ -2875,7 +2868,7 @@ def sync_collection(self):
if self.details["changes_webhooks"]:
self.notification_removals.append(util.item_set(item, self.library.get_id_from_maps(item.ratingKey)))
if self.playlist and items_removed:
self.library._reload(self.obj)
self.library.item_reload(self.obj)
self.obj.removeItems(items_removed)
elif items_removed:
self.library.alter_collection(items_removed, self.name, smart_label_collection=self.smart_label_collection, add=False)
Expand Down Expand Up @@ -3328,7 +3321,7 @@ def update_details(self):
logger.error("Metadata: Failed to Update Please delete the collection and run again")
logger.info("")
else:
self.library._reload(self.obj)
self.library.item_reload(self.obj)
#self.obj.batchEdits()
batch_display = "Collection Metadata Edits"
if summary[1] and str(summary[1]) != str(self.obj.summary):
Expand Down Expand Up @@ -3449,8 +3442,8 @@ def update_details(self):
elif style_data and "tpdb_background" in style_data and style_data["tpdb_background"]:
self.backgrounds["style_data"] = f"https://theposterdb.com/api/assets/{style_data['tpdb_background']}"

self.collection_poster = util.pick_image(self.obj.title, self.posters, self.library.prioritize_assets, self.library.download_url_assets, asset_location)
self.collection_background = util.pick_image(self.obj.title, self.backgrounds, self.library.prioritize_assets, self.library.download_url_assets, asset_location, is_poster=False)
self.collection_poster = self.library.pick_image(self.obj.title, self.posters, self.library.prioritize_assets, self.library.download_url_assets, asset_location)
self.collection_background = self.library.pick_image(self.obj.title, self.backgrounds, self.library.prioritize_assets, self.library.download_url_assets, asset_location, is_poster=False)

clean_temp = False
if isinstance(self.collection_poster, KometaImage):
Expand Down Expand Up @@ -3520,7 +3513,7 @@ def sync_trakt_list(self):
logger.separator(f"Syncing {self.name} {self.Type} to Trakt List {self.sync_to_trakt_list}", space=False, border=False)
logger.info("")
if self.obj:
self.library._reload(self.obj)
self.library.item_reload(self.obj)
self.load_collection_items()
current_ids = []
for item in self.items:
Expand Down Expand Up @@ -3597,7 +3590,7 @@ def exclude_admin_from_playlist(self):
def send_notifications(self, playlist=False):
if self.obj and self.details["changes_webhooks"] and \
(self.created or len(self.notification_additions) > 0 or len(self.notification_removals) > 0):
self.library._reload(self.obj)
self.library.item_reload(self.obj)
try:
self.library.Webhooks.collection_hooks(
self.details["changes_webhooks"],
Expand Down
Loading

0 comments on commit 2ad6771

Please sign in to comment.