|
15 | 15 | # You should have received a copy of the GNU General Public License |
16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
|
| 18 | +from nrk import Base |
18 | 19 | import time |
19 | 20 | import xbmc |
20 | 21 | import xbmcplugin |
|
26 | 27 | from xbmcgui import ListItem |
27 | 28 | import routing |
28 | 29 | import nrktv |
| 30 | +import nrkradio |
| 31 | +import nrk |
29 | 32 | import subs |
30 | 33 | import inputstreamhelper |
31 | 34 |
|
|
34 | 37 |
|
35 | 38 | @plugin.route('/') |
36 | 39 | def root(): |
| 40 | + items = [ |
| 41 | + (plugin.url_for(tv), ListItem("TV"), True), |
| 42 | + (plugin.url_for(radio), ListItem("Radio"), True), |
| 43 | + ] |
| 44 | + addDirectoryItems(plugin.handle, items) |
| 45 | + endOfDirectory(plugin.handle) |
| 46 | + |
| 47 | +@plugin.route('/tv') |
| 48 | +def tv(): |
37 | 49 | items = [ |
38 | 50 | (plugin.url_for(live_tv), ListItem("Direkte TV"), True), |
39 | | - (plugin.url_for(live_radio), ListItem("Direkte radio"), True), |
40 | 51 | (plugin.url_for(recommended), ListItem("Anbefalt"), True), |
41 | 52 | (plugin.url_for(popular), ListItem("Mest sett"), True), |
42 | 53 | (plugin.url_for(mostrecent), ListItem("Sist sendt"), True), |
@@ -221,6 +232,70 @@ def browse(): |
221 | 232 | urls = [plugin.url_for(category, item.id) for item in items] |
222 | 233 | view(items, urls=urls) |
223 | 234 |
|
| 235 | +@plugin.route('/radio') |
| 236 | +def radio(): |
| 237 | + items = [ |
| 238 | + (plugin.url_for(live_radio), ListItem("Direkte radio"), True), |
| 239 | + (plugin.url_for(radio_pages), ListItem("Kategorier"), True), |
| 240 | + ] |
| 241 | + addDirectoryItems(plugin.handle, items) |
| 242 | + endOfDirectory(plugin.handle) |
| 243 | + |
| 244 | + |
| 245 | +@plugin.route('/radio/pages') |
| 246 | +def radio_pages(): |
| 247 | + items: list[Base] = nrkradio.PagesOverview().children |
| 248 | + show_radio_list(items) |
| 249 | + |
| 250 | +@plugin.route('/radio/<string:type>/<path:url>') |
| 251 | +def radio_navigate_by_url(type: str, url: str) -> None: |
| 252 | + item_class = nrkradio.map_type_to_class(type) |
| 253 | + item: Base = item_class.from_url(url) |
| 254 | + children: list[Base] = item.children |
| 255 | + if children: |
| 256 | + show_radio_list(children) |
| 257 | + else: |
| 258 | + media_url = item.media_url |
| 259 | + if media_url: |
| 260 | + li = ListItem(item.title, path=media_url) |
| 261 | + set_common_properties(item, li) |
| 262 | + playable = True |
| 263 | + #if playable: |
| 264 | + # set_stream_details(podcastEpisode, li) |
| 265 | + li.setProperty('isplayable', 'true') |
| 266 | + xbmcplugin.setResolvedUrl(plugin.handle, True, listitem=li) |
| 267 | + addDirectoryItem(plugin.handle, media_url, li, not playable) |
| 268 | + endOfDirectory(plugin.handle) |
| 269 | + |
| 270 | + |
| 271 | +def show_radio_list(items: list[nrk.Base]): |
| 272 | + total: int = len(items) |
| 273 | + for item in items: |
| 274 | + # if not getattr(item, 'available', True): |
| 275 | + # continue |
| 276 | + li = ListItem(item.title) |
| 277 | + # set_common_properties(item, li) TODO: set metadata |
| 278 | + playable = item.is_playable |
| 279 | + if playable: |
| 280 | + li.setProperty('isplayable', 'true') |
| 281 | + child_type = item.type |
| 282 | + manifest_url = item.manifest_url |
| 283 | + url = plugin.url_for(radio_navigate_by_url, child_type, manifest_url) |
| 284 | + art: dict[str, str] = {} |
| 285 | + if item.fanart: |
| 286 | + xbmc.log(f"setting fanart {item.title}: {item.fanart}", xbmc.LOGINFO) |
| 287 | + art["fanart"] = item.fanart |
| 288 | + if item.thumb: |
| 289 | + art["thumb"] = item.thumb |
| 290 | + if art: |
| 291 | + li.setArt(art) |
| 292 | + #tag = li.getMusicInfoTag() |
| 293 | + |
| 294 | + #li.setInfo('video', {'count': i, 'title': item.title, 'mediatype': 'video'}) |
| 295 | + addDirectoryItem(plugin.handle, url, li, not playable, total) |
| 296 | + endOfDirectory(plugin.handle) |
| 297 | + |
| 298 | + |
224 | 299 |
|
225 | 300 | @plugin.route('/search') |
226 | 301 | def search(): |
|
0 commit comments