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)
- [Radarr](#radarr)
- [Sonarr](#sonarr)
- [Tags](#tags)
- [Trakt](#trakt)
- [OMDb](#omdb)
- [Usage](#usage)
@ -335,7 +334,7 @@ You can repeat this process for as many users as you like.
"language": "English",
"quality": "HD-1080p",
"root_folder": "/tv/",
"tags": {},
"tags": [],
"url": "http://localhost:8989/"
},
"trakt": {
@ -982,7 +981,7 @@ Sonarr configuration.
"language": "English",
"quality": "HD-1080p",
"root_folder": "/tv/",
"tags": {},
"tags": [],
"url": "http://localhost:8989"
},
```
@ -995,55 +994,29 @@ Sonarr configuration.
`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.
- Examples:
```json
"tags": ["anime"]
```
```json
"tags": ["anime", "jap"]
```
```json
"tags": [
"anime",
"jap"
]
```
`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.
### 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:**
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": {
"amzn": [
"hbo",
"amc",
"usa network",
"tnt",
"starz",
"the cw",
"fx",
"fox",
"abc",
"nbc",
"cbs",
"tbs",
"amazon",
"syfy",
"cinemax",
"bravo",
"showtime",
"paramount network"
]
}
```
## Trakt
Trakt Authentication info:

@ -3,22 +3,21 @@ from misc.log import logger
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:
tags = []
for tag_name, tag_networks in network_tags.items():
for tag_network in tag_networks:
if tag_network.lower() in network.lower() and tag_name.lower() in profile_tags:
log.debug("Using %s tag for network: %s", tag_name, network)
tags.append(profile_tags[tag_name.lower()])
if tags:
return tags
tag_ids = []
for tag_name in config_tags:
if tag_name.lower() in profile_tags:
log.debug("Validated Tag: %s", tag_name)
tag_ids.append(profile_tags[tag_name.lower()])
if tag_ids:
return tag_ids
except Exception:
log.exception("Exception determining tag to use for network %s: ", network)
log.exception("Exception building Tags IDs list")
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:
if not chosen_tag_ids:
return None
@ -30,7 +29,7 @@ def readable_tag_from_ids(profile_tag_ids, chosen_tag_ids):
if tags:
return tags
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

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

@ -225,14 +225,21 @@ def show(
# profile tags
profile_tags = None
use_tags = None
readable_tags = None
tag_ids = None
tag_names = None
if cfg.sonarr.tags:
if cfg.sonarr.tags is not None:
profile_tags = get_profile_tags(sonarr)
# 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'])
readable_tags = sonarr_helper.readable_tag_from_ids(profile_tags, use_tags)
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,
)
# series type
if any('anime' in s.lower() for s in trakt_show['genres']):
@ -250,20 +257,20 @@ def show(
quality_profile_id,
language_profile_id,
cfg.sonarr.root_folder,
use_tags,
tag_ids,
not no_search,
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,
readable_tags)
tag_names)
else:
log.info("ADDED: \'%s (%s)\'", series_title, series_year)
else:
if profile_tags is not None:
log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags)
tag_names)
else:
log.info("FAILED ADDING: \'%s (%s)\'", series_title, series_year)
@ -435,7 +442,23 @@ def shows(
# language profile id
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)
@ -618,22 +641,6 @@ def shows(
(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
if sonarr.add_series(
series['show']['ids']['tvdb'],
@ -642,14 +649,14 @@ def shows(
quality_profile_id,
language_profile_id,
cfg.sonarr.root_folder,
use_tags,
tag_ids,
not no_search,
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,
readable_tags)
tag_names)
else:
log.info("ADDED: \'%s (%s)\'", series_title, series_year)
if notifications:
@ -658,7 +665,7 @@ def shows(
else:
if profile_tags is not None:
log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
readable_tags)
tag_names)
else:
log.info("FAILED ADDING: \'%s (%s)\'", series_title, series_year)
continue

Loading…
Cancel
Save