Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play by a specific "video id" #23

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ Play one of the svt channels.
data:
channel: svt1 # Available channels: svt1, svt2, svtbarn, kunskapskanalen, svt24
```
### Play video id
If a specific video should be played, its "id" can be extracted from the url. For example `jXvZLoG` is the id found in the following url: `https://www.svtplay.se/video/jXvZLoG/ifs-invandrare-for-svenskar/avsnitt-3`
```yaml
- service: svt_play.play_videoid
entity_id: media_player.living_room_tv
data:
videoid: jXvZLoG
```

## Installation

Expand Down
37 changes: 37 additions & 0 deletions custom_components/svt_play/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CONF_CHANNEL = 'channel'
CONF_CATEGORY = 'category'
CONF_EXCLUDE_CATEGORY = 'exclude_category'
CONF_VIDEOID = 'videoid'

SERVICE_PLAY_SUGGESTED = 'play_suggested'
SERVICE_PLAY_SUGGESTED_SCHEMA = vol.Schema({
Expand Down Expand Up @@ -41,6 +42,13 @@
CONF_CHANNEL: str,
})

SERVICE_PLAY_VIDEOID = 'play_videoid'
SERVICE_PLAY_VIDEOID_SCHEMA = vol.Schema(
{
CONF_ENTITY_ID: cv.entity_ids,
CONF_VIDEOID: str,
}
)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -144,4 +152,33 @@ def fetch_video_url():
DOMAIN, SERVICE_PLAY_CHANNEL, play_channel, SERVICE_PLAY_CHANNEL_SCHEMA
)

async def play_videoid(service):
"""Play the specified video id"""

entity_id = service.data.get(CONF_ENTITY_ID)
videoid = service.data.get(CONF_VIDEOID)

def fetch_video_url():
return video_information_by_id(videoid)

video_info = await hass.async_add_executor_job(fetch_video_url)

await hass.services.async_call(
'media_player',
'play_media',
{
'entity_id': entity_id,
'media_content_id': video_info['url'],
'media_content_type': 'video',
'extra': {
'title': video_info['name'],
'thumb': video_info['thumbnail'],
},
},
)

hass.services.async_register(
DOMAIN, SERVICE_PLAY_VIDEOID, play_videoid, SERVICE_PLAY_VIDEOID_SCHEMA
)

return True
9 changes: 9 additions & 0 deletions custom_components/svt_play/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ play_channel:
entity_id:
description: Name(s) of entities to play on.
example: "media_player.living_room_chromecast"
play_videoid:
description: Play the specified video id
fields:
videoid:
description: The id of the video.
example: "jXvZLoG"
entity_id:
description: Name(s) of entities to play on.
example: "media_player.living_room_chromecast"
19 changes: 19 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Play the suggested video that is shown on svtplay.se. This is the recomended way

### Play Latest
Play the latest video or clip from a specific program. There exists two options to exclude or include videos matching specific categories.
```yaml
- service: svt_play.play_latest
entity_id: media_player.living_room_tv
data:
Expand All @@ -25,6 +26,16 @@ Play the latest video or clip from a specific program. There exists two options
exclude_category: utan filmer # Optional
```

### Play random
Play a random video or clip from a specific program. There exist an option to just random from specific categories.
```yaml
- service: svt_play.play_random
entity_id: media_player.living_room_tv
data:
program_name: skavlan
category: Intervjuer # Optional
```

### Play Channel
Play one of the svt channels.
```yaml
Expand All @@ -33,6 +44,14 @@ Play one of the svt channels.
data:
channel: svt1 # Available channels: svt1, svt2, svtbarn, kunskapskanalen, svt24
```
### Play video id
If a specific video should be played, its "id" can be extracted from the url. For example `jXvZLoG` is the id found in the following url: `https://www.svtplay.se/video/jXvZLoG/ifs-invandrare-for-svenskar/avsnitt-3`
```yaml
- service: svt_play.play_videoid
entity_id: media_player.living_room_tv
data:
videoid: jXvZLoG
```

## Installation

Expand Down
Loading