Sonarr: Simplifed the adding of tags to shows

- Not network based anymore
pull/132/head
desimaniac 5 years ago
parent 548fe7d17b
commit e551aa1cb9

@ -36,7 +36,6 @@
- [Slack](#slack) - [Slack](#slack)
- [Radarr](#radarr) - [Radarr](#radarr)
- [Sonarr](#sonarr) - [Sonarr](#sonarr)
- [Tags](#tags)
- [Trakt](#trakt) - [Trakt](#trakt)
- [OMDb](#omdb) - [OMDb](#omdb)
- [Usage](#usage) - [Usage](#usage)
@ -335,7 +334,7 @@ You can repeat this process for as many users as you like.
"language": "English", "language": "English",
"quality": "HD-1080p", "quality": "HD-1080p",
"root_folder": "/tv/", "root_folder": "/tv/",
"tags": {}, "tags": [],
"url": "http://localhost:8989/" "url": "http://localhost:8989/"
}, },
"trakt": { "trakt": {
@ -982,7 +981,7 @@ Sonarr configuration.
"language": "English", "language": "English",
"quality": "HD-1080p", "quality": "HD-1080p",
"root_folder": "/tv/", "root_folder": "/tv/",
"tags": {}, "tags": [],
"url": "http://localhost:8989" "url": "http://localhost:8989"
}, },
``` ```
@ -995,55 +994,29 @@ Sonarr configuration.
`root_folder` - Root folder for TV shows. `root_folder` - Root folder for TV shows.
`tags` - Assign tags to shows based the network it airs on. More details on this below. `tags` - Assign tags to shows. Tags need to be created in Sonarr first.
`url` - Sonarr's URL. - Examples:
- Note: If you have URL Base enabled in Sonarr's settings, you will need to add that into the URL as well.
### Tags
The `tags` option allows Sonarr to assign tags to shows from specific television networks, so that Sonarr can filter in/out certain keywords from releases.
**Example:** ```json
"tags": ["anime"]
To show how tags work, we will create a tag `AMZN` and assign it to certain television networks that usually have AMZN releases.
1. First, we will create a tag in Sonarr (Settings > Indexers > Restrictions).
```
Must contain: BluRay, Amazon, AMZN
Must not contain:
Tags: AMZN
``` ```
2. And, finally, we will edit the Traktarr config and assign the `AMZN` tag to some networks. ```json
"tags": ["anime", "jap"]
```
```json ```json
"tags": { "tags": [
"amzn": [ "anime",
"hbo", "jap"
"amc",
"usa network",
"tnt",
"starz",
"the cw",
"fx",
"fox",
"abc",
"nbc",
"cbs",
"tbs",
"amazon",
"syfy",
"cinemax",
"bravo",
"showtime",
"paramount network"
] ]
}
``` ```
`url` - Sonarr's URL.
- Note: If you have URL Base enabled in Sonarr's settings, you will need to add that into the URL as well.
## Trakt ## Trakt
Trakt Authentication info: Trakt Authentication info:

@ -3,22 +3,21 @@ from misc.log import logger
log = logger.get_logger(__name__) log = logger.get_logger(__name__)
def series_tag_id_from_network(profile_tags, network_tags, network): def series_tag_ids_list_builder(profile_tags, config_tags):
try: try:
tags = [] tag_ids = []
for tag_name, tag_networks in network_tags.items(): for tag_name in config_tags:
for tag_network in tag_networks: if tag_name.lower() in profile_tags:
if tag_network.lower() in network.lower() and tag_name.lower() in profile_tags: log.debug("Validated Tag: %s", tag_name)
log.debug("Using %s tag for network: %s", tag_name, network) tag_ids.append(profile_tags[tag_name.lower()])
tags.append(profile_tags[tag_name.lower()]) if tag_ids:
if tags: return tag_ids
return tags
except Exception: except Exception:
log.exception("Exception determining tag to use for network %s: ", network) log.exception("Exception building Tags IDs list")
return None return None
def readable_tag_from_ids(profile_tag_ids, chosen_tag_ids): def series_tag_names_list_builder(profile_tag_ids, chosen_tag_ids):
try: try:
if not chosen_tag_ids: if not chosen_tag_ids:
return None return None
@ -30,7 +29,7 @@ def readable_tag_from_ids(profile_tag_ids, chosen_tag_ids):
if tags: if tags:
return tags return tags
except Exception: except Exception:
log.exception("Exception building readable tag name list from ids %s: ", chosen_tag_ids) log.exception("Exception building Tag Names list from Tag IDs %s: ", chosen_tag_ids)
return None return None

@ -95,8 +95,7 @@ class Config(object, metaclass=Singleton):
'language': 'English', 'language': 'English',
'quality': 'HD-1080p', 'quality': 'HD-1080p',
'root_folder': '/tv/', 'root_folder': '/tv/',
'tags': { 'tags': [],
},
'url': 'http://localhost:8989/' 'url': 'http://localhost:8989/'
}, },
'omdb': { 'omdb': {

@ -225,14 +225,21 @@ def show(
# profile tags # profile tags
profile_tags = None profile_tags = None
use_tags = None tag_ids = None
readable_tags = None tag_names = None
if cfg.sonarr.tags: if cfg.sonarr.tags is not None:
profile_tags = get_profile_tags(sonarr) profile_tags = get_profile_tags(sonarr)
if profile_tags is not None:
# determine which tags to use when adding this series # determine which tags to use when adding this series
use_tags = sonarr_helper.series_tag_id_from_network(profile_tags, cfg.sonarr.tags, trakt_show['network']) tag_ids = sonarr_helper.series_tag_ids_list_builder(
readable_tags = sonarr_helper.readable_tag_from_ids(profile_tags, use_tags) profile_tags,
cfg.sonarr.tags,
)
tag_names = sonarr_helper.series_tag_names_list_builder(
profile_tags,
tag_ids,
)
# series type # series type
if any('anime' in s.lower() for s in trakt_show['genres']): if any('anime' in s.lower() for s in trakt_show['genres']):
@ -250,20 +257,20 @@ def show(
quality_profile_id, quality_profile_id,
language_profile_id, language_profile_id,
cfg.sonarr.root_folder, cfg.sonarr.root_folder,
use_tags, tag_ids,
not no_search, not no_search,
series_type, series_type,
): ):
if profile_tags is not None and readable_tags is not None: if profile_tags is not None and tag_names is not None:
log.info("ADDED: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year, log.info("ADDED: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags) tag_names)
else: else:
log.info("ADDED: \'%s (%s)\'", series_title, series_year) log.info("ADDED: \'%s (%s)\'", series_title, series_year)
else: else:
if profile_tags is not None: if profile_tags is not None:
log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year, log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags) tag_names)
else: else:
log.info("FAILED ADDING: \'%s (%s)\'", series_title, series_year) log.info("FAILED ADDING: \'%s (%s)\'", series_title, series_year)
@ -435,7 +442,23 @@ def shows(
# language profile id # language profile id
language_profile_id = get_language_profile_id(sonarr, cfg.sonarr.language) language_profile_id = get_language_profile_id(sonarr, cfg.sonarr.language)
profile_tags = get_profile_tags(sonarr) if cfg.sonarr.tags else None # profile tags
profile_tags = None
tag_ids = None
tag_names = None
if cfg.sonarr.tags is not None:
profile_tags = get_profile_tags(sonarr)
if profile_tags is not None:
# determine which tags to use when adding this series
tag_ids = sonarr_helper.series_tag_ids_list_builder(
profile_tags,
cfg.sonarr.tags,
)
tag_names = sonarr_helper.series_tag_names_list_builder(
profile_tags,
tag_ids,
)
pvr_objects_list = get_objects(sonarr, 'Sonarr', notifications) pvr_objects_list = get_objects(sonarr, 'Sonarr', notifications)
@ -618,22 +641,6 @@ def shows(
(series['show']['network'] or 'N/A').upper(), (series['show']['network'] or 'N/A').upper(),
) )
# profile tags
use_tags = None
readable_tags = None
if profile_tags is not None:
# determine which tags to use when adding this series
use_tags = sonarr_helper.series_tag_id_from_network(
profile_tags,
cfg.sonarr.tags,
series['show']['network'],
)
readable_tags = sonarr_helper.readable_tag_from_ids(
profile_tags,
use_tags,
)
# add show to sonarr # add show to sonarr
if sonarr.add_series( if sonarr.add_series(
series['show']['ids']['tvdb'], series['show']['ids']['tvdb'],
@ -642,14 +649,14 @@ def shows(
quality_profile_id, quality_profile_id,
language_profile_id, language_profile_id,
cfg.sonarr.root_folder, cfg.sonarr.root_folder,
use_tags, tag_ids,
not no_search, not no_search,
series_type, series_type,
): ):
if profile_tags is not None and readable_tags is not None: if profile_tags is not None and tag_names is not None:
log.info("ADDED: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year, log.info("ADDED: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags) tag_names)
else: else:
log.info("ADDED: \'%s (%s)\'", series_title, series_year) log.info("ADDED: \'%s (%s)\'", series_title, series_year)
if notifications: if notifications:
@ -658,7 +665,7 @@ def shows(
else: else:
if profile_tags is not None: if profile_tags is not None:
log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year, log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags) tag_names)
else: else:
log.info("FAILED ADDING: \'%s (%s)\'", series_title, series_year) log.info("FAILED ADDING: \'%s (%s)\'", series_title, series_year)
continue continue

Loading…
Cancel
Save