Skip to content

Commit

Permalink
Merge pull request #32 from ManiMatter/21-feature-request-readarr-sup…
Browse files Browse the repository at this point in the history
…port

BETA TEST - Added Readarr Support (completely untested)
  • Loading branch information
ManiMatter authored Feb 18, 2024
2 parents 87999f5 + 75670d9 commit 845942f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,4 @@ jobs:
run: |
docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE_NAME:$IMAGE_TAG -t $IMAGE_NAME:latest -f docker/Dockerfile --push .
# - name: "Build, Tag, and push the Docker image"
# env:
# IMAGE_NAME: ghcr.io/manimatter/decluttarr
# IMAGE_TAG: latest
# run: |
# docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE_NAME:$IMAGE_TAG -f docker/Dockerfile --push .
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ services:
# Lidarr
- LIDARR_URL=http://lidarr:8686
- LIDARR_KEY=$LIDARR_API_KEY
# Readarr
- READARR_URL=http://readarr:8787
- READARR_KEY=$READARR_API_KEY
# qBittorrent
- QBITTORRENT_URL=http://qbittorrent:8080
#- QBITTORRENT_USERNAME=Your name
Expand Down Expand Up @@ -227,6 +230,18 @@ Note: The `config.conf` is disregarded when running via docker-compose.yml

---

### **-Readarr section**
- Defines readarr instance on which download queue should be decluttered

**READARR_URL**
- URL under which the instance can be reached
- If not defined, this instance will not be monitored

**READARR_KEY**
- Your API key for readarr

---

### **qBittorrent section**
- Defines settings to connect with qBittorrent

Expand Down
4 changes: 4 additions & 0 deletions config/config.conf-Example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ SONARR_KEY = $SONARR_API_KEY
LIDARR_URL = http://lidarr:8686
LIDARR_KEY = $LIDARR_API_KEY

[readarr]
READARR_URL = http://lidarr:8787
READARR_KEY = $READARR_API_KEY

[qbittorrent]
QBITTORRENT_URL = http://qbittorrent:8080
QBITTORRENT_USERNAME = Your name (or empty)
Expand Down
10 changes: 8 additions & 2 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,27 @@ def get_config_value(key, config_section, is_mandatory, datatype, default_value
LIDARR_KEY = None if LIDARR_URL == None else \
get_config_value('LIDARR_KEY', 'lidarr', True, str)

# Readarr
READARR_URL = get_config_value('READARR_URL', 'readarr', False, str)
READARR_KEY = None if READARR_URL == None else \
get_config_value('READARR_KEY', 'readarr', True, str)

# qBittorrent
QBITTORRENT_URL = get_config_value('QBITTORRENT_URL', 'qbittorrent', False, str, '')
QBITTORRENT_USERNAME = get_config_value('QBITTORRENT_USERNAME', 'qbittorrent', False, str, '')
QBITTORRENT_PASSWORD = get_config_value('QBITTORRENT_PASSWORD', 'qbittorrent', False, str, '')

########################################################################################################################
########### Validate settings
if not (RADARR_URL or SONARR_URL or LIDARR_URL):
print(f'[ ERROR ]: No Radarr/Sonarr/Lidarr URLs specified (nothing to monitor)')
if not (RADARR_URL or SONARR_URL or LIDARR_URL or READARR_URL):
print(f'[ ERROR ]: No Radarr/Sonarr/Lidarr/Readarr URLs specified (nothing to monitor)')
sys.exit(0)

########### Enrich setting variables
if RADARR_URL: RADARR_URL += '/api/v3'
if SONARR_URL: SONARR_URL += '/api/v3'
if LIDARR_URL: LIDARR_URL += '/api/v1'
if READARR_URL: READARR_URL += '/api/v1'
if QBITTORRENT_URL: QBITTORRENT_URL += '/api/v2'

########### Add Variables to Dictionary
Expand Down
19 changes: 18 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ async def main():
except:
settings_dict['LIDARR_NAME'] = 'Lidarr'

try:
if settings_dict['READARR_URL']:
settings_dict['READARR_NAME'] = (await rest_get(settings_dict['READARR_URL']+'/system/status', settings_dict['READARR_KEY']))['instanceName']
except:
settings_dict['READARR_NAME'] = 'Readarr'

# Print Settings
fmt = '{0.days} days {0.hours} hours {0.minutes} minutes'
logger.info('#' * 50)
Expand Down Expand Up @@ -76,6 +82,7 @@ async def main():
if settings_dict['RADARR_URL']: logger.info('%s: %s', settings_dict['RADARR_NAME'], settings_dict['RADARR_URL'])
if settings_dict['SONARR_URL']: logger.info('%s: %s', settings_dict['SONARR_NAME'], settings_dict['SONARR_URL'])
if settings_dict['LIDARR_URL']: logger.info('%s: %s', settings_dict['LIDARR_NAME'], settings_dict['LIDARR_URL'])
if settings_dict['READARR_URL']: logger.info('%s: %s', settings_dict['READARR_NAME'], settings_dict['READARR_URL'])
if settings_dict['QBITTORRENT_URL']: logger.info('qBittorrent: %s', settings_dict['QBITTORRENT_URL'])

logger.info('')
Expand Down Expand Up @@ -117,6 +124,14 @@ async def main():
error_occured = True
logger.error('-- | %s *** Error: %s ***', settings_dict['LIDARR_NAME'], error)

if settings_dict['READARR_URL']:
try:
await asyncio.get_event_loop().run_in_executor(None, lambda: requests.get(settings_dict['READARR_URL']+'/system/status', params=None, headers={'X-Api-Key': settings_dict['READARR_KEY']}))
logger.info('OK | %s', settings_dict['READARR_NAME'])
except Exception as error:
error_occured = True
logger.error('-- | %s *** Error: %s ***', settings_dict['READARR_NAME'], error)

if settings_dict['QBITTORRENT_URL']:
# Checking if qbit can be reached, and checking if version is OK
try:
Expand Down Expand Up @@ -186,6 +201,7 @@ async def main():
if settings_dict['RADARR_URL']: await queueCleaner(settings_dict, 'radarr', defective_tracker, download_sizes_tracker, protectedDownloadIDs, privateDowloadIDs)
if settings_dict['SONARR_URL']: await queueCleaner(settings_dict, 'sonarr', defective_tracker, download_sizes_tracker, protectedDownloadIDs, privateDowloadIDs)
if settings_dict['LIDARR_URL']: await queueCleaner(settings_dict, 'lidarr', defective_tracker, download_sizes_tracker, protectedDownloadIDs, privateDowloadIDs)
if settings_dict['READARR_URL']: await queueCleaner(settings_dict, 'readarr', defective_tracker, download_sizes_tracker, protectedDownloadIDs, privateDowloadIDs)
logger.verbose('')
logger.verbose('Queue clean-up complete!')
await asyncio.sleep(settings_dict['REMOVE_TIMER']*60)
Expand All @@ -194,7 +210,8 @@ async def main():
if __name__ == '__main__':
instances = {settings_dict['RADARR_URL']: {}} if settings_dict['RADARR_URL'] else {} + \
{settings_dict['SONARR_URL']: {}} if settings_dict['SONARR_URL'] else {} + \
{settings_dict['LIDARR_URL']: {}} if settings_dict['LIDARR_URL'] else {}
{settings_dict['LIDARR_URL']: {}} if settings_dict['LIDARR_URL'] else {} + \
{settings_dict['READARR_URL']: {}} if settings_dict['READARR_URL'] else {}
defective_tracker = Defective_Tracker(instances)
download_sizes_tracker = Download_Sizes_Tracker({})
asyncio.run(main())
Expand Down
5 changes: 5 additions & 0 deletions src/decluttarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ async def queueCleaner(settings_dict, arr_type, defective_tracker, download_size
API_KEY = settings_dict['LIDARR_KEY']
NAME = settings_dict['LIDARR_NAME']
full_queue_param = 'includeUnknownArtistItems'
elif arr_type == 'readarr':
BASE_URL = settings_dict['READARR_URL']
API_KEY = settings_dict['READARR_KEY']
NAME = settings_dict['READARR_NAME']
full_queue_param = 'includeUnknownAuthorItems'
else:
logger.error('Unknown arr_type specified, exiting: %s', str(arr_type))
sys.exit()
Expand Down
4 changes: 3 additions & 1 deletion src/remove_unmonitored.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ async def remove_unmonitored(settings_dict, BASE_URL, API_KEY, NAME, deleted_dow
elif arr_type == 'radarr':
isMonitored = (await rest_get(f'{BASE_URL}/movie/{str(queueItem["movieId"])}', API_KEY))['monitored']
elif arr_type == 'lidarr':
isMonitored = (await rest_get(f'{BASE_URL}/album/{str(queueItem["albumId"])}', API_KEY))['monitored']
isMonitored = (await rest_get(f'{BASE_URL}/album/{str(queueItem["albumId"])}', API_KEY))['monitored']
elif arr_type == 'readarr':
isMonitored = (await rest_get(f'{BASE_URL}/book/{str(queueItem["bookId"])}', API_KEY))['monitored']
if isMonitored:
monitoredDownloadIDs.append(queueItem['downloadId'])

Expand Down

0 comments on commit 845942f

Please sign in to comment.