Skip to content

Commit a7f363c

Browse files
jptuomilindell
authored andcommitted
Added functionality option to skip categories via exclude_category
1 parent 83f6305 commit a7f363c

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ Play the suggested video that is shown on svtplay.se. This is the recomended way
1616
```
1717
1818
### Play Latest
19-
Play the latest video or clip from a specific program. There exist an option to just play the latest from specific categories.
19+
Play the latest video or clip from a specific program. There exists two options to exclude or include videos matching specific categories.
2020
```yaml
2121
- service: svt_play.play_latest
2222
entity_id: media_player.living_room_tv
2323
data:
2424
program_name: skavlan
2525
category: Intervjuer # Optional
26+
exclude_category: utan filmer # Optional
2627
```
2728
2829
### Play random

custom_components/svt_play/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
CONF_PROGRAM_NAME = 'program_name'
1313
CONF_CHANNEL = 'channel'
1414
CONF_CATEGORY = 'category'
15+
CONF_EXCLUDE_CATEGORY = 'exclude_category'
1516

1617
SERVICE_PLAY_SUGGESTED = 'play_suggested'
1718
SERVICE_PLAY_SUGGESTED_SCHEMA = vol.Schema({
@@ -23,6 +24,7 @@
2324
SERVICE_PLAY_LATEST_SCHEMA = vol.Schema({
2425
CONF_ENTITY_ID: cv.entity_ids,
2526
CONF_PROGRAM_NAME: str,
27+
CONF_EXCLUDE_CATEGORY: str,
2628
CONF_CATEGORY: category_names,
2729
})
2830

@@ -76,10 +78,11 @@ async def play_latest(service):
7678
entity_id = service.data.get(CONF_ENTITY_ID)
7779
program_name = service.data.get(CONF_PROGRAM_NAME)
7880
category = service.data.get(CONF_CATEGORY)
81+
exclude_category = service.data.get(CONF_EXCLUDE_CATEGORY)
7982

8083
def fetch_video_url():
8184
return video_information_by_id(
82-
video_id_by_time(program_name, categories=category)
85+
video_id_by_time(program_name, exclude_category, categories=category)
8386
)
8487
video_info = await hass.async_add_executor_job(fetch_video_url)
8588

custom_components/svt_play/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "svt_play",
33
"name": "SVT Play",
4-
"version": "1.0.4",
4+
"version": "1.1.0",
55
"documentation": "https://github.com/lindell/home-assistant-svt-play",
66
"issue_tracker": "https://github.com/lindell/home-assistant-svt-play/issues",
77
"iot_class": "cloud_polling",

custom_components/svt_play/services.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ play_latest:
1919
category:
2020
description: Name(s) of categories that should be used.
2121
example: "Klipp"
22+
exclude_category:
23+
description: Name(s) of categories that shouldn't be used.
24+
example: "utan filmer"
2225
play_channel:
2326
description: Play the a specified channel
2427
fields:

custom_components/svt_play/video_url_fetch/video_fetch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ def video_url_from_videoplayer_api(url, formats):
4747
"Could not find video url with any of the formats: {}".format(formats))
4848

4949

50-
def video_id_by_time(program_id, index=0, categories=None):
50+
def video_id_by_time(program_id, exclude_category=None, categories=None, index=0):
5151
"Get the video id of a video based on the time it became available"
5252
program_data = information_by_program_id(program_id)
5353

5454
videos = []
5555
for content in program_data['associatedContent']:
56-
if categories is None or content['name'] in categories:
56+
if ((categories is None or content['name'] in categories) and
57+
(exclude_category is None or exclude_category not in content['name'])):
5758
videos += content['items']
5859

5960
# Remove episodes with no validity date

info.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Play the suggested video that is shown on svtplay.se. This is the recomended way
1616
```
1717
1818
### Play Latest
19-
Play the latest video or clip from a specific program. There exist an option to just play the latest from specific categories.
20-
```yaml
19+
Play the latest video or clip from a specific program. There exists two options to exclude or include videos matching specific categories.
2120
- service: svt_play.play_latest
2221
entity_id: media_player.living_room_tv
2322
data:
2423
program_name: skavlan
2524
category: Intervjuer # Optional
25+
exclude_category: utan filmer # Optional
2626
```
2727

2828
### Play Channel

0 commit comments

Comments
 (0)