Пример #1
0
def index():
    try:
        req = __session__.get("http://www.rtp.pt/play/",
                              headers=__headers__).text
    except:
        kodiutils.ok(kodiutils.get_string(32000), kodiutils.get_string(32001))
        exit(0)

    match = re.compile(
        '<a title=".+?direto (.+?)" href="(.+?)" class="mask-live "><img alt=".+?" src="(.+?)" class="img-responsive">.+?<span class="small"><b>(.+?)</b>'
    ).findall(req)
    if match:
        for channel, rel_url, img, prog in match:
            liz = ListItem("[B][COLOR blue]{}[/B][/COLOR] ({})".format(
                kodiutils.smart_str(channel), kodiutils.smart_str(prog)))
            if img.startswith("/"):
                img = "http:{}".format(img)

            liz.setArt({"thumb": img, "icon": img, "fanart": kodiutils.FANART})
            liz.setProperty('IsPlayable', 'true')
            liz.setInfo("Video",
                        infoLabels={
                            "plot":
                            html_parser.unescape(kodiutils.smart_str(prog))
                        })

            addDirectoryItem(
                plugin.handle,
                plugin.url_for(play,
                               rel_url=kodiutils.smart_str(rel_url),
                               channel=kodiutils.smart_str(channel),
                               img=kodiutils.smart_str(img),
                               prog=kodiutils.smart_str(prog)), liz, False)

    endOfDirectory(plugin.handle)
Пример #2
0
def connect_openvpn(config, restart=False, sudopassword=None):
    log_debug('Connecting OpenVPN configuration: [%s]' % config)
    global _state

    if _sudo and _sudopwdrequired and sudopassword is None:
        sudopassword = utils.keyboard(
            heading=_settings.get_string(3012), hidden=True)
    openvpn = vpn.OpenVPN(_openvpn, _settings.get_datapath(
        config), ip=_ip, port=_port, args=_args, sudo=_sudo, sudopwd=sudopassword, debug=(_settings['debug'] == 'true'))
    try:
        if restart:
            openvpn.disconnect()
            _state = disconnected
        openvpn.connect()
        display_notification(_settings.get_string(4002) % os.path.splitext(os.path.basename(config))[0])
        _state = connected
    except vpn.OpenVPNError as exception:
        if exception.errno == 1:
            _state = connected
            if utils.yesno(_settings.get_string(3002), _settings.get_string(3009), _settings.get_string(3010)):
                log_debug('User has decided to restart OpenVPN')
                connect_openvpn(config, True, sudopassword)
            else:
                log_debug('User has decided not to restart OpenVPN')
        else:
            utils.ok(_settings.get_string(
                3002), _settings.get_string(3011), exception.string)
            _state = failed
Пример #3
0
def delete_ovpn():
    name = select_ovpn()
    if name is not None and len(name) > 0:
        ovpn = _settings.get_datapath(name)
        log_debug('Delete: [%s]' % ovpn)
        if os.path.exists(ovpn):
            if not utils.yesno(_settings.get_string(3002), _settings.get_string(3006)):
                utils.ok(_settings.get_string(
                    3002), _settings.get_string(3007))
            else:
                log_debug('Deleting: [%s]' % (ovpn))
                os.remove(ovpn)
    elif name is None:
        utils.ok(_settings.get_string(3002), _settings.get_string(3008))
Пример #4
0
def delete_ovpn():
    name = select_ovpn()
    if name is not None and len(name) > 0:
        ovpn = _settings.get_datapath(name)
        log_debug('Delete: [%s]' % ovpn)
        if os.path.exists(ovpn):
            if not utils.yesno(_settings.get_string(3002),
                               _settings.get_string(3006)):
                utils.ok(_settings.get_string(3002),
                         _settings.get_string(3007))
            else:
                log_debug('Deleting: [%s]' % (ovpn))
                os.remove(ovpn)
    elif name is None:
        utils.ok(_settings.get_string(3002), _settings.get_string(3008))
Пример #5
0
def import_ovpn():
    path = utils.browse_files(_settings.get_string(3000), mask='.ovpn|.conf')
    if path and os.path.exists(path) and os.path.isfile(path):
        log_debug('Import: [%s]' % path)
        name = utils.keyboard(heading=_settings.get_string(3001))
        if name and len(name) > 0:
            ovpn = _settings.get_datapath('%s.ovpn' % name)
            if os.path.exists(ovpn) and not utils.yesno(_settings.get_string(3002), _settings.get_string(3003)):
                    utils.ok(_settings.get_string(
                        3002), _settings.get_string(3004))
            else:
                log_debug('Copying [%s] to [%s]' % (path, ovpn))
                shutil.copyfile(path, ovpn)
        else:
            utils.ok(_settings.get_string(3002), _settings.get_string(3005))
Пример #6
0
def disconnect_openvpn():
    log_debug('Disconnecting OpenVPN')
    global _state
    try:
        _state = disconnecting
        response = vpn.is_running(_ip, _port)
        if response[0]:
            vpn.disconnect(_ip, _port)
            if response[1] is not None:
                display_notification(_settings.get_string(4001) % os.path.splitext(os.path.basename(response[1]))[0])
        _state = disconnected
        log_debug('Disconnect OpenVPN successful')
    except vpn.OpenVPNError as exception:
        utils.ok(_settings.get_string(
            3002), _settings.get_string(3011), exception.string)
        _state = failed
Пример #7
0
def import_ovpn():
    path = utils.browse_files(_settings.get_string(3000), mask='.ovpn|.conf')
    if path and os.path.exists(path) and os.path.isfile(path):
        log_debug('Import: [%s]' % path)
        name = utils.keyboard(heading=_settings.get_string(3001))
        if name and len(name) > 0:
            ovpn = _settings.get_datapath('%s.ovpn' % name)
            if os.path.exists(ovpn) and not utils.yesno(
                    _settings.get_string(3002), _settings.get_string(3003)):
                utils.ok(_settings.get_string(3002),
                         _settings.get_string(3004))
            else:
                log_debug('Copying [%s] to [%s]' % (path, ovpn))
                shutil.copyfile(path, ovpn)
        else:
            utils.ok(_settings.get_string(3002), _settings.get_string(3005))
Пример #8
0
def disconnect_openvpn():
    log_debug('Disconnecting OpenVPN')
    global _state
    try:
        _state = disconnecting
        response = vpn.is_running(_ip, _port)
        if response[0]:
            vpn.disconnect(_ip, _port)
            if response[1] is not None:
                display_notification(
                    _settings.get_string(4001) %
                    os.path.splitext(os.path.basename(response[1]))[0])
        _state = disconnected
        log_debug('Disconnect OpenVPN successful')
    except vpn.OpenVPNError as exception:
        utils.ok(_settings.get_string(3002), _settings.get_string(3011),
                 exception.string)
        _state = failed
Пример #9
0
def index():
	try:
		req = __session__.get("http://www.rtp.pt/play/", headers=__headers__).text
	except:
		kodiutils.ok(kodiutils.get_string(32000),kodiutils.get_string(32001))
		exit(0)

	match=re.compile('<a title=".+?direto (.+?)" href="(.+?)" class="mask-live "><img alt=".+?" src="(.+?)" class="img-responsive">.+?<span class="small"><b>(.+?)</b>').findall(req)
	if match:
		for channel,rel_url, img, prog in match:
			liz = ListItem("[B][COLOR blue]{}[/B][/COLOR] ({})".format(kodiutils.smart_str(channel), kodiutils.smart_str(prog)))
			if img.startswith("/"):
				img = "http:{}".format(img)
			
			liz.setArt({"thumb": img, "icon": img, "fanart": kodiutils.FANART})
			liz.setProperty('IsPlayable', 'true')
			liz.setInfo("Video", infoLabels={"plot": html_parser.unescape(kodiutils.smart_str(prog))})
			
			addDirectoryItem(plugin.handle, plugin.url_for(play, rel_url=kodiutils.smart_str(rel_url), channel=kodiutils.smart_str(channel), img=kodiutils.smart_str(img), prog=kodiutils.smart_str(prog) ), liz, False)
	
	endOfDirectory(plugin.handle)
Пример #10
0
def connect_openvpn(config, restart=False, sudopassword=None):
    log_debug('Connecting OpenVPN configuration: [%s]' % config)
    global _state

    if _sudo and _sudopwdrequired and sudopassword is None:
        sudopassword = utils.keyboard(heading=_settings.get_string(3012),
                                      hidden=True)
    openvpn = vpn.OpenVPN(_openvpn,
                          _settings.get_datapath(config),
                          ip=_ip,
                          port=_port,
                          args=_args,
                          sudo=_sudo,
                          sudopwd=sudopassword,
                          debug=(_settings['debug'] == 'true'))
    try:
        if restart:
            openvpn.disconnect()
            _state = disconnected
        openvpn.connect()
        display_notification(
            _settings.get_string(4002) %
            os.path.splitext(os.path.basename(config))[0])
        _state = connected
    except vpn.OpenVPNError as exception:
        if exception.errno == 1:
            _state = connected
            if utils.yesno(_settings.get_string(3002),
                           _settings.get_string(3009),
                           _settings.get_string(3010)):
                log_debug('User has decided to restart OpenVPN')
                connect_openvpn(config, True, sudopassword)
            else:
                log_debug('User has decided not to restart OpenVPN')
        else:
            utils.ok(_settings.get_string(3002), _settings.get_string(3011),
                     exception.string)
            _state = failed
Пример #11
0
def get_lastfm_similar_tracks(artist, track):
    base_url = 'http://ws.audioscrobbler.com/2.0/?'
    params = {'method': 'track.getsimilar', 'artist': artist, 'track':
              track, 'api_key': '5da513b631898f5372a5e5f863651212', 'format': 'json',
              'autocorrect': 1}
    url = '%s%s' % (base_url, urllib.urlencode(params))
    log_debug('Last.fm URL: %s' % url)

    try:
        f = urlopen(url)
    except URLError as exception:
        log_error(exception)
        utils.ok(_settings.get_string(1000), _settings.get_string(3007))
        return []

    json_query = unicode(f.read(), 'ascii', errors='ignore')
    f.close()
    json_response = simplejson.loads(json_query)
    lastfmtracks = []
    for track in json_response['similartracks']['track']:
        lastfmtracks.append({'title': track[
                            'name'], 'artist': track['artist']['name']})
    return lastfmtracks
Пример #12
0
def play():
    rel_url = plugin.args["rel_url"][0]
    channel = plugin.args["channel"][0]
    prog = plugin.args["prog"][0]
    icon = plugin.args["img"][0]
    try:
        req = __session__.get("{}{}".format(__base_url__, rel_url)).text
    except:
        kodiutils.ok(kodiutils.get_string(32000), kodiutils.get_string(32002))
        exit(0)

    is_pseudo_aes = bool(re.findall("var aes = true", req))

    streams = re.compile('new RTPPlayer\(.*file\:.+?"(.+?)"',
                         re.DOTALL).findall(req)

    if streams:
        print streams
        final_stream_url = None
        for stream in streams:
            if ".m3u8" in stream.split('/')[-1]:
                final_stream_url = stream
                break

    if is_pseudo_aes:
        try:
            req = __session__.post(
                "http://www.rtp.pt/services/playRequest.php",
                headers={"RTPPlayUrl": final_stream_url})
            final_stream_url = req.headers["RTPPlayWW"]
        except:
            kodiutils.ok(kodiutils.get_string(32000),
                         kodiutils.get_string(32002))
            exit(0)

    if final_stream_url:
        liz = ListItem("[B][COLOR blue]{}[/B][/COLOR] ({})".format(
            kodiutils.smart_str(channel), kodiutils.smart_str(prog)))
        liz.setArt({"thumb": icon, "icon": icon})
        liz.setProperty('IsPlayable', 'true')
        liz.setPath(
            "{}|User-Agent=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36&Referer=http://www.rtp.pt/play/"
            .format(final_stream_url))
        setResolvedUrl(plugin.handle, True, liz)
    else:
        kodiutils.ok(kodiutils.get_string(32000), kodiutils.get_string(32002))
        exit(0)
Пример #13
0
def play():
	rel_url = plugin.args["rel_url"][0]
	channel = plugin.args["channel"][0]
	prog = plugin.args["prog"][0]
	icon = plugin.args["img"][0]
	try:
		req = __session__.get("{}{}".format(__base_url__, rel_url)).text
	except:
		kodiutils.ok(kodiutils.get_string(32000),kodiutils.get_string(32002))
		exit(0)

	is_pseudo_aes = bool(re.findall("var aes = true", req))
		
	streams = re.compile('new RTPPlayer\(.*file\:.+?"(.+?)"', re.DOTALL).findall(req)
	
	if streams:
		print streams
		final_stream_url = None
		for stream in streams:
			if ".m3u8" in stream.split('/')[-1]: 
				final_stream_url = stream
				break

	if is_pseudo_aes:
		try:
			req = __session__.post("http://www.rtp.pt/services/playRequest.php", headers={"RTPPlayUrl":	final_stream_url})
			final_stream_url = req.headers["RTPPlayWW"]
		except:
			kodiutils.ok(kodiutils.get_string(32000),kodiutils.get_string(32002))
			exit(0)		

	if final_stream_url:
		liz = ListItem("[B][COLOR blue]{}[/B][/COLOR] ({})".format(kodiutils.smart_str(channel), kodiutils.smart_str(prog)))
		liz.setArt({"thumb": icon, "icon": icon})
		liz.setProperty('IsPlayable', 'true')
		liz.setPath("{}|User-Agent=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36&Referer=http://www.rtp.pt/play/".format(final_stream_url))
		setResolvedUrl(plugin.handle, True, liz)
	else:
		kodiutils.ok(kodiutils.get_string(32000),kodiutils.get_string(32002))
		exit(0)
Пример #14
0
log_debug('Addon: %s' % __addonname__, 1)
log_debug('Version: %s' % __version__, 1)
log_debug('Params: %s: %s' % (__path__, __params__), 1)

__category__ = utils.get_value(__params__, 'c')
__filter__ = utils.get_value(__params__, 'filter')
if __path__ == 'browse':
    try:
        __offset__ = utils.get_value(__params__, 'offset')
        __pivot__ = utils.get_value(__params__, 'pivot')

        # Display users presets.
        if __id__ == 'presets':
            if __username__ is None or len(__username__) == 0:
                utils.ok(__addonname__, __settings__.get_string(
                    3001), __settings__.get_string(3002))
            else:
                results = __tunein__.browse_presets(username=__username__)
                process_tunein_json(results)
                xbmcplugin.endOfDirectory(int(__settings__.get_argv(1)))

        # Browse for a station/show/topic/category.
        elif len(__id__) > 0:
            results = __tunein__.browse(
                id=__id__, filter=__filter__, offset=__offset__, pivot=__pivot__, username=__username__)
            process_tunein_json(results)
            xbmcplugin.endOfDirectory(int(__settings__.get_argv(1)))

        # Display local stations and shows.
        elif __category__ == 'local':
            results = __tunein__.browse_local(
Пример #15
0
    if currenttrackpos <= len(playlist):
        if _runinbackground:
            display_notification(_settings.get_string(1000), _settings.get_string(4000) % (artist.decode('ascii', 'ignore'), title.decode('ascii', 'ignore')))
        else:
            pDialog.update(25, _settings.get_string(3005), '%s - %s' % (artist.decode('ascii', 'ignore'), title.decode('ascii', 'ignore')))

        count, playlisttracks = get_similar_tracks(artist, title)
        log_debug('Found %d similar tracks in Kodi library' % count)

        if _runinbackground or not pDialog.iscanceled():
            index = 0
            if count > 0:
                while xbmc.PlayList(0).size() > currenttrackpos:
                    xbmc.PlayList(0).remove(xbmc.PlayList(0)[currenttrackpos].getfilename())
                index = add_tracks_to_playlist(artist, playlisttracks)

            if not _runinbackground:
                pDialog.close()

            log_debug('Added %d songs to playlist' % index)
            if _runinbackground:
                display_notification(_settings.get_string(1000), _settings.get_string(4001) % (index, artist.decode('ascii', 'ignore'), title.decode('ascii', 'ignore')))
            else:
                utils.ok(_settings.get_string(1000), _settings.get_string(3006) % index, '%s - %s' % (artist.decode('ascii', 'ignore'), title.decode('ascii', 'ignore')))
        else:
            log_debug('Script was cancelled')
    else:
        log_debug('Unable to get currently playing track')
else:
    utils.ok(_settings.get_string(1000), _settings.get_string(3008))
Пример #16
0
    def onAction(self, action):
        actionid = action.getId()
        # if actionid != 107:
        #    print 'onAction: %s' % actionid

        if actionid == _action_previous_menu or actionid == _action_nav_back:
            self.close()

        elif actionid == _action_select_item:
            if self._layertype == _layer_type_hybrid:
                self._layertype = 0
            else:
                self._layertype += 1
            self.set_tiles()

        elif actionid == _action_move_left or actionid == _action_move_right or actionid == _action_move_up or actionid == _action_move_down:
            if actionid == _action_move_left:
                self._centre_tilex -= 1
            elif actionid == _action_move_right:
                self._centre_tilex += 1
            elif actionid == _action_move_up:
                self._centre_tiley -= 1
            elif actionid == _action_move_down:
                self._centre_tiley += 1
            self._lat_deg, self._lon_deg = self.num2deg(
                self._centre_tilex, self._centre_tiley, self._zoom)
            self.set_tiles()

        elif actionid == _action_page_up or actionid == _action_page_down:
            if actionid == _action_page_up:
                if self._zoom < _map_max_zoom:
                    self._zoom += 1
            elif actionid == _action_page_down:
                if self._zoom > _map_min_zoom:
                    self._zoom -= 1
            self._centre_tilex, self._centre_tiley, self._home_pixelx, self._home_pixely = self.deg2num(
                self._lat_deg, self._lon_deg, self._zoom)
            self._home_column, self._home_row, self._home_pixelx, self._home_pixely = self.deg2num(
                self._home_lat_deg, self._home_lon_deg, self._zoom)
            self.set_tiles()

        elif actionid == _action_context_menu:
            query = utils.keyboard('', heading=self._settings.get_string(3001))
            if query and len(query) > 0:
                if self._settings.get('api') == 0:
                    osm = mapsapi.OpenStreetMapApi()
                else:
                    osm = mapsapi.MapQuestOpenApi()
                response = osm.search(query)
                if len(response) > 0:
                    index = 0
                    if len(response) > 1:
                        displaynames = []
                        for result in response:
                            displaynames.append(result['display_name'])
                        index = utils.select(self._settings.get_string(3002),
                                             displaynames)
                    if index >= 0 and index < len(response):
                        self._home_lat_deg = self._lat_deg = float(
                            response[index]['lat'])
                        self._home_lon_deg = self._lon_deg = float(
                            response[index]['lon'])
                        self._centre_tilex, self._centre_tiley, self._home_pixelx, self._home_pixely = self.deg2num(
                            self._lat_deg, self._lon_deg, self._zoom)
                        self._home_column = self._centre_tilex
                        self._home_row = self._centre_tiley
                        self.set_tiles()
                else:
                    utils.ok(self._settings.get_string(3000),
                             self._settings.get_string(3003) % query,
                             self._settings.get_string(3004))
Пример #17
0
def raise_notification():
	kodiutils.ok(kodiutils.get_string(32000),kodiutils.get_string(32002))
	exit(0)
    def onAction(self, action):
        actionid = action.getId()
        # if actionid != 107:
        #    print 'onAction: %s' % actionid

        if actionid == _action_previous_menu or actionid == _action_nav_back:
            self.close()

        elif actionid == _action_select_item:
            if self._layertype == _layer_type_hybrid:
                self._layertype = 0
            else:
                self._layertype += 1
            self.set_tiles()

        elif actionid == _action_move_left or actionid == _action_move_right or actionid == _action_move_up or actionid == _action_move_down:
            if actionid == _action_move_left:
                self._centre_tilex -= 1
            elif actionid == _action_move_right:
                self._centre_tilex += 1
            elif actionid == _action_move_up:
                self._centre_tiley -= 1
            elif actionid == _action_move_down:
                self._centre_tiley += 1
            self._lat_deg, self._lon_deg = self.num2deg(
                self._centre_tilex, self._centre_tiley, self._zoom)
            self.set_tiles()

        elif actionid == _action_page_up or actionid == _action_page_down:
            if actionid == _action_page_up:
                if self._zoom < _map_max_zoom:
                    self._zoom += 1
            elif actionid == _action_page_down:
                if self._zoom > _map_min_zoom:
                    self._zoom -= 1
            self._centre_tilex, self._centre_tiley, self._home_pixelx, self._home_pixely = self.deg2num(
                self._lat_deg, self._lon_deg, self._zoom)
            self._home_column, self._home_row, self._home_pixelx, self._home_pixely = self.deg2num(
                self._home_lat_deg, self._home_lon_deg, self._zoom)
            self.set_tiles()

        elif actionid == _action_context_menu:
            query = utils.keyboard('', heading=self._settings.get_string(3001))
            if query and len(query) > 0:
                if self._settings.get('api') == 0:
                    osm = mapsapi.OpenStreetMapApi()
                else:
                    osm = mapsapi.MapQuestOpenApi()
                response = osm.search(query)
                if len(response) > 0:
                    index = 0
                    if len(response) > 1:
                        displaynames = []
                        for result in response:
                            displaynames.append(result['display_name'])
                        index = utils.select(self._settings.get_string(3002), displaynames)
                    if index >= 0 and index < len(response):
                        self._home_lat_deg = self._lat_deg = float(
                            response[index]['lat'])
                        self._home_lon_deg = self._lon_deg = float(
                            response[index]['lon'])
                        self._centre_tilex, self._centre_tiley, self._home_pixelx, self._home_pixely = self.deg2num(
                            self._lat_deg, self._lon_deg, self._zoom)
                        self._home_column = self._centre_tilex
                        self._home_row = self._centre_tiley
                        self.set_tiles()
                else:
                    utils.ok(self._settings.get_string(3000), self._settings.get_string(3003) % query, self._settings.get_string(3004))
def raise_notification():
    kodiutils.ok(kodiutils.get_string(32000),kodiutils.get_string(32002))
    exit(0)
Пример #20
0
                                         '/p' + podcast['id'] + '-' +
                                         podcast['hash']
                                     })
                ok = xbmcplugin.addDirectoryItem(handle=int(
                    __settings__.get_argv(1)),
                                                 url=u,
                                                 listitem=liz,
                                                 isFolder=True)
            xbmcplugin.endOfDirectory(int(__settings__.get_argv(1)))

    # except __overcast__.TuneInError as e:
    #     utils.ok(__addonname__, __settings__.get_string(3004),
    #              __settings__.get_string(3003))
    #     log_error('TuneInError: %s %s' % (e.status, e.fault))
    except urllib2.URLError as e:
        utils.ok(__addonname__, __settings__.get_string(3002),
                 __settings__.get_string(3003))
        log_error('URLError: %s' % e)

# Display main menu.
else:
    __overcast__.login(__email__, __password__)

    contextmenu = [
        (__settings__.get_string(1001),
         'XBMC.RunPlugin(%s?path=refresh)' % (__settings__.get_argv(0)))
    ]

    for episode in __overcast__.active_episodes():
        liz = xbmcgui.ListItem(episode['title'],
                               iconImage=episode['thumbURL'],
                               thumbnailImage=episode['thumbURL'])