Skip to content

Commit

Permalink
直播资源由语音助手提供
Browse files Browse the repository at this point in the history
  • Loading branch information
shaonianzhentan committed May 25, 2023
1 parent 7581092 commit 72f9a61
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 143 deletions.
31 changes: 21 additions & 10 deletions custom_components/xiaomi_tv/browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@

from urllib.parse import urlparse, parse_qs, parse_qsl, quote
from .manifest import manifest
from .iptv import IPTV

tv = IPTV()

protocol = 'xiaomi://'
tv_protocol = 'xiaomi://tv/'
Expand All @@ -78,8 +75,19 @@ def parse_query(url_query):

async def async_browse_media(media_player, media_content_type, media_content_id):
hass = media_player.hass
# 初始化直播源
await tv.get_list()
iptv = hass.data.get('conversation_iptv')
if iptv is None:
return BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_content_id=media_content_id,
media_content_type=MEDIA_TYPE_CHANNEL,
title="请安装语音小助手",
can_play=False,
can_expand=False,
children=[],
)

playlist = await iptv.get_list()

# 主界面
if media_content_id in [None, XiaomiRouter.tv_home]:
Expand All @@ -93,7 +101,7 @@ async def async_browse_media(media_player, media_content_type, media_content_id)
children=[],
)
# 分组列表
for item in tv.groups:
for item in iptv.groups:
library_info.children.append(
BrowseMedia(
title=item,
Expand Down Expand Up @@ -122,8 +130,9 @@ async def async_browse_media(media_player, media_content_type, media_content_id)
can_expand=False,
children=[],
)
channels = filter(lambda x: x.group == group, tv.playlist)
channels = filter(lambda x: x.group == group, playlist)
for item in channels:
print(item.path)
library_info.children.append(
BrowseMedia(
title=item.title,
Expand All @@ -141,8 +150,10 @@ async def async_play_media(media_player, media_content_type, media_content_id):
if media_content_id is None or media_content_id.startswith(protocol) == False:
return

# 初始化直播源
await tv.get_list()
iptv = media_player.hass.data.get('conversation_iptv')
if iptv is None:
return None
await iptv.get_list()

# 协议转换
url = urlparse(media_content_id)
Expand All @@ -151,4 +162,4 @@ async def async_play_media(media_player, media_content_type, media_content_id):
if media_content_id.startswith(XiaomiRouter.tv_search):
kv = query.get('kv')
# 电视搜索
return await tv.search_url(kv)
return await iptv.search_url(kv)
132 changes: 0 additions & 132 deletions custom_components/xiaomi_tv/iptv.py

This file was deleted.

2 changes: 1 addition & 1 deletion custom_components/xiaomi_tv/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "xiaomi_tv",
"name": "\u5C0F\u7C73\u7535\u89C6",
"version": "2023.5.16",
"version": "2023.5.25",
"config_flow": true,
"documentation": "https://github.com/shaonianzhentan/xiaomi_tv",
"requirements": [
Expand Down

0 comments on commit 72f9a61

Please sign in to comment.