def add_index_directory_items(self): xbmcplugin.addDirectoryItem(self._handle, self.url_for(self.channels_route), xbmcgui.ListItem(label=_('live_tv')), True) xbmcplugin.addDirectoryItem(self._handle, self.url_for(self.archive_route), xbmcgui.ListItem(label=_('archive')), True)
def configure_iptvsimple(m3u_file, xmltv_file, plugin_name): try: xbmc.executebuiltin('InstallAddon({})'.format(IPTV_SIMPLE_ID), True) xbmc.executeJSONRPC('{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":true}}}}'.format(IPTV_SIMPLE_ID)) addon = xbmcaddon.Addon(IPTV_SIMPLE_ID) except: xbmcgui.Dialog().ok(plugin_name, _('iptv_simple_not_installed')) return if not ((m3u_file and (addon.getSetting('m3uPath') != m3u_file)) or (xmltv_file and (addon.getSetting('epgPath') != xmltv_file))): return if not xbmcgui.Dialog().yesno(plugin_name, _('iptv_simple_configure').format(plugin_name)): return xbmc.executeJSONRPC('{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":false}}}}'.format(IPTV_SIMPLE_ID)) if m3u_file: addon.setSetting('m3uPathType', '0') addon.setSetting('m3uPath', m3u_file) addon.setSetting('startNum', '1') if xmltv_file: addon.setSetting('epgPath', xmltv_file) addon.setSetting('epgPathType', '0') addon.setSetting('epgTimeShift', '0') addon.setSetting('epgTSOverride', 'false') xbmc.executeJSONRPC('{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":true}}}}'.format(IPTV_SIMPLE_ID))
def _update(self, configure, callback): # type: (bool, Callable[[str, int], None] or None) -> None or int result = None _playlist_path = self.playlist_path() _epg_path = self.epg_path() if not _playlist_path or (not (_playlist_path or _epg_path)): return result self.prepare_update() callback(_('creating_playlist'), 0) channels = self.fetch_channels(lambda percent: callback( _('creating_playlist'), int(percent // 2.5))) try: log('Creating playlist [%d channels]' % len(channels)) iptv.exports.create_m3u(_playlist_path, channels, self.make_url) result = 1 except IOError as e: log(str(e)) raise PlaylistNotCreated() if _epg_path: try: callback(_('creating_epg'), 40) epg = self.fetch_epg( channels, lambda percent: callback(_('creating_epg'), 40 + (percent // 2))) log('Creating XMLTV EPG') iptv.exports.create_epg(_epg_path, epg) result = 2 except IOError as e: log(str(e)) raise EpgNotCreated() if configure: callback(_('configuring_addon'), 90) self.updated_after_settings_changed() callback('', 100) return result
def archive_days_route(self, channel_id, channel_name): now = datetime.now() xbmcplugin.setPluginCategory(self._handle, 'Replay' + ' / ' + channel_name) for day in range(0, self.client.archive_days() + 1): d = now - timedelta(days=day) title = _('today') if day == 0 else _( 'yesterday') if day == 1 else d.strftime('%d. %m.') list_item = xbmcgui.ListItem( label=_('day_%d' % (d.weekday() + 1)) + ', ' + title) list_item.setArt({'icon': 'DefaultAddonPVRClient.png'}) url = self.url_for(self.archive_programmes_route, channel_id, channel_name, d.strftime("%m-%d-%Y")) xbmcplugin.addDirectoryItem(self._handle, url, list_item, True) xbmcplugin.endOfDirectory(self._handle)
def onSettingsChanged(self): if self.updating: return self.updating = True try: self.addon = self.create_addon() # refresh for updated settings! if not self.abortRequested(): try: res = self._update(True, self.notification_process) if res == 1: self.notify(_('playlist_created'), False) if res == 2: self.notify(_('playlist_and_epg_created'), False) except Exception as e: log(str(e)) self.notify(_('playlist_or_epg_not_created'), True) finally: self.updating = False
def channels_route(self): channels = self.channels() xbmcplugin.setPluginCategory(self._handle, _('live_tv')) for channel in channels: list_item = xbmcgui.ListItem(label=channel.name) list_item.setInfo('video', {'title': channel.name}) list_item.setArt({'thumb': channel.logo}) list_item.setProperty('IsPlayable', 'true') xbmcplugin.addDirectoryItem( self._handle, self.url_for(self.play_channel_route, channel.id), list_item, False) xbmcplugin.endOfDirectory(self._handle)
def archive_route(self): channels = self.channels() xbmcplugin.setPluginCategory(self._handle, _('archive')) for channel in channels: if channel.archive_days > 0: list_item = xbmcgui.ListItem(label=channel.name) list_item.setInfo('video', {'title': channel.name}) list_item.setArt({'thumb': channel.logo}) xbmcplugin.addDirectoryItem( self._handle, self.url_for(self.archive_days_route, channel.id, channel.name), list_item, True) xbmcplugin.endOfDirectory(self._handle)
def tick(self): if datetime.datetime.now() > self._next_update: try: self._schedule_next(self.update_interval()) self._update(False, self.dummy_notification_progress if xbmc.Player().isPlaying() else self.notification_process) except UserNotDefinedException: pass except NetConnectionError: self._schedule_next(60) log('Can''t update, no internet connection') pass except Exception as e: log(str(e)) self.notify(_('playlist_or_epg_not_created'), True)
def archive_programmes_route(self, channel_id, channel_name, day): day = self._strptime(day, '%m-%d-%Y') next_day = day + timedelta(days=1) prev_day = day + timedelta(days=-1) epg = self.epg([channel_id], day, day) xbmcplugin.setPluginCategory(self._handle, _('archive') + ' / ' + channel_name) if day > datetime.today() - timedelta(days=self.client.archive_days()): list_item = xbmcgui.ListItem(label=_('day_before')) list_item.setArt({'icon': 'DefaultVideoPlaylists.png'}) url = self.url_for(self.archive_programmes_route, channel_id, channel_name, prev_day.strftime("%m-%d-%Y")) xbmcplugin.addDirectoryItem(self._handle, url, list_item, True) if epg: for programme in epg[channel_id]: if programme.is_replyable: title = self._utc2local(programme.start_time).strftime( '%H:%M') + ' - ' + programme.title list_item = xbmcgui.ListItem(label=title) video_info = { 'title': programme.title, 'plot': programme.description, 'duration': programme.duration } if programme.episodeNo: video_info['episode'] = programme.episodeNo if programme.seasonNo: video_info['season'] = programme.seasonNo if programme.year: video_info['year'] = programme.year if programme.actors: video_info['cast'] = programme.actors if programme.directors: video_info['director'] = programme.directors[0] list_item.setInfo('video', video_info) art_info = {} if programme.thumbnail: art_info = { 'thumb': programme.thumbnail, 'icon': programme.thumbnail } if programme.poster: art_info['poster'] = programme.poster list_item.setArt(art_info) url = self.url_for(self.play_programme_route, programme.id) list_item.setProperty('IsPlayable', 'true') xbmcplugin.addDirectoryItem(self._handle, url, list_item, False) if day.date() < datetime.today().date(): list_item = xbmcgui.ListItem(label=_('day_after')) list_item.setArt({'icon': 'DefaultVideoPlaylists.png'}) url = self.url_for(self.archive_programmes_route, channel_id, channel_name, next_day.strftime("%m-%d-%Y")) xbmcplugin.addDirectoryItem(self._handle, url, list_item, True) xbmcplugin.endOfDirectory(self._handle)