mirror of
https://github.com/ManiMatter/decluttarr.git
synced 2026-04-18 01:53:58 +02:00
Merge pull request #203 from ManiMatter/refresh-qbit-cookie
Added Cookie Refresh on every run
This commit is contained in:
8
main.py
8
main.py
@@ -62,6 +62,14 @@ async def main(settingsDict):
|
||||
# Start Cleaning
|
||||
while True:
|
||||
logger.verbose("-" * 50)
|
||||
|
||||
# Refresh qBit Cookie
|
||||
if settingsDict["QBITTORRENT_URL"]:
|
||||
await qBitRefreshCookie(settingsDict)
|
||||
if not settingsDict["QBIT_COOKIE"]:
|
||||
logger.error("Cookie Refresh failed - exiting decluttarr")
|
||||
exit()
|
||||
|
||||
# Cache protected (via Tag) and private torrents
|
||||
protectedDownloadIDs, privateDowloadIDs = await getProtectedAndPrivateFromQbit(
|
||||
settingsDict
|
||||
|
||||
@@ -6,6 +6,7 @@ logger = verboselogs.VerboseLogger(__name__)
|
||||
from dateutil.relativedelta import relativedelta as rd
|
||||
import requests
|
||||
from src.utils.rest import rest_get, rest_post #
|
||||
from src.utils.shared import qBitRefreshCookie
|
||||
import asyncio
|
||||
from packaging import version
|
||||
|
||||
@@ -189,18 +190,9 @@ async def instanceChecks(settingsDict):
|
||||
# Check Bittorrent
|
||||
if settingsDict['QBITTORRENT_URL']:
|
||||
# Checking if qbit can be reached, and checking if version is OK
|
||||
try:
|
||||
response = await asyncio.get_event_loop().run_in_executor(None, lambda: requests.post(settingsDict['QBITTORRENT_URL']+'/auth/login', data={'username': settingsDict['QBITTORRENT_USERNAME'], 'password': settingsDict['QBITTORRENT_PASSWORD']}, headers={'content-type': 'application/x-www-form-urlencoded'}, verify=settingsDict['SSL_VERIFICATION']))
|
||||
if response.text == 'Fails.':
|
||||
raise ConnectionError('Login failed.')
|
||||
response.raise_for_status()
|
||||
settingsDict['QBIT_COOKIE'] = {'SID': response.cookies['SID']}
|
||||
except Exception as error:
|
||||
await qBitRefreshCookie(settingsDict)
|
||||
if not settingsDict['QBIT_COOKIE']:
|
||||
error_occured = True
|
||||
logger.error('!! %s Error: !!', 'qBittorrent')
|
||||
logger.error('> %s', error)
|
||||
logger.error('> Details:')
|
||||
logger.error(response.text)
|
||||
|
||||
if not error_occured:
|
||||
qbit_version = await rest_get(settingsDict['QBITTORRENT_URL']+'/app/version',cookies=settingsDict['QBIT_COOKIE'])
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
# Import Libraries
|
||||
import asyncio
|
||||
import logging, verboselogs
|
||||
|
||||
logger = verboselogs.VerboseLogger(__name__)
|
||||
import json
|
||||
|
||||
# Import Functions
|
||||
from config.definitions import settingsDict
|
||||
from src.utils.loadScripts import *
|
||||
from src.decluttarr import queueCleaner
|
||||
from src.utils.rest import rest_get, rest_post
|
||||
from src.utils.trackers import Defective_Tracker, Download_Sizes_Tracker
|
||||
|
||||
# Hide SSL Verification Warnings
|
||||
if settingsDict["SSL_VERIFICATION"] == False:
|
||||
import warnings
|
||||
|
||||
warnings.filterwarnings("ignore", message="Unverified HTTPS request")
|
||||
|
||||
# Set up logging
|
||||
setLoggingFormat(settingsDict)
|
||||
|
||||
|
||||
# Main function
|
||||
async def main(settingsDict):
|
||||
# Adds to settings Dict the instances that are actually configures
|
||||
settingsDict["INSTANCES"] = []
|
||||
for arrApplication in settingsDict["SUPPORTED_ARR_APPS"]:
|
||||
if settingsDict[arrApplication + "_URL"]:
|
||||
settingsDict["INSTANCES"].append(arrApplication)
|
||||
|
||||
# Pre-populates the dictionaries (in classes) that track the items that were already caught as having problems or removed
|
||||
defectiveTrackingInstances = {}
|
||||
for instance in settingsDict["INSTANCES"]:
|
||||
defectiveTrackingInstances[instance] = {}
|
||||
defective_tracker = Defective_Tracker(defectiveTrackingInstances)
|
||||
download_sizes_tracker = Download_Sizes_Tracker({})
|
||||
|
||||
# Get name of arr-instances
|
||||
for instance in settingsDict["INSTANCES"]:
|
||||
settingsDict = await getArrInstanceName(settingsDict, instance)
|
||||
|
||||
# Check outdated
|
||||
upgradeChecks(settingsDict)
|
||||
|
||||
# Welcome Message
|
||||
showWelcome()
|
||||
|
||||
# Current Settings
|
||||
showSettings(settingsDict)
|
||||
|
||||
# Check Minimum Version and if instances are reachable and retrieve qbit cookie
|
||||
settingsDict = await instanceChecks(settingsDict)
|
||||
|
||||
# Create qBit protection tag if not existing
|
||||
await createQbitProtectionTag(settingsDict)
|
||||
|
||||
# Show Logger Level
|
||||
showLoggerLevel(settingsDict)
|
||||
|
||||
# Start Cleaning
|
||||
while True:
|
||||
logger.verbose("-" * 50)
|
||||
# Cache protected (via Tag) and private torrents
|
||||
protectedDownloadIDs, privateDowloadIDs = await getProtectedAndPrivateFromQbit(
|
||||
settingsDict
|
||||
)
|
||||
|
||||
# Run script for each instance
|
||||
for instance in settingsDict["INSTANCES"]:
|
||||
await queueCleaner(
|
||||
settingsDict,
|
||||
instance,
|
||||
defective_tracker,
|
||||
download_sizes_tracker,
|
||||
protectedDownloadIDs,
|
||||
privateDowloadIDs,
|
||||
)
|
||||
logger.verbose("")
|
||||
logger.verbose("Queue clean-up complete!")
|
||||
|
||||
# Wait for the next run
|
||||
await asyncio.sleep(settingsDict["REMOVE_TIMER"] * 60)
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main(settingsDict))
|
||||
@@ -1,6 +1,7 @@
|
||||
# Shared Functions
|
||||
import logging, verboselogs
|
||||
|
||||
import asyncio
|
||||
import requests
|
||||
logger = verboselogs.VerboseLogger(__name__)
|
||||
from src.utils.rest import rest_get, rest_delete, rest_post
|
||||
from src.utils.nest_functions import add_keys_nested_dict, nested_get
|
||||
@@ -398,3 +399,18 @@ async def qBitOffline(settingsDict, failType, NAME):
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
async def qBitRefreshCookie(settingsDict):
|
||||
try:
|
||||
response = await asyncio.get_event_loop().run_in_executor(None, lambda: requests.post(settingsDict['QBITTORRENT_URL']+'/auth/login', data={'username': settingsDict['QBITTORRENT_USERNAME'], 'password': settingsDict['QBITTORRENT_PASSWORD']}, headers={'content-type': 'application/x-www-form-urlencoded'}, verify=settingsDict['SSL_VERIFICATION']))
|
||||
if response.text == 'Fails.':
|
||||
raise ConnectionError('Login failed.')
|
||||
response.raise_for_status()
|
||||
settingsDict['QBIT_COOKIE'] = {'SID': response.cookies['SID']}
|
||||
logger.debug('qBit cookie refreshed!')
|
||||
except Exception as error:
|
||||
logger.error('!! %s Error: !!', 'qBittorrent')
|
||||
logger.error('> %s', error)
|
||||
logger.error('> Details:')
|
||||
logger.error(response.text)
|
||||
settingsDict['QBIT_COOKIE'] = {}
|
||||
Reference in New Issue
Block a user