コード例 #1
0
ファイル: get_rooms.py プロジェクト: nickscript0/image_grid
def _save_room(bs, desc_file, room_id):
    tables = bs.find('div', attrs={'id': room_id}).findAll('table')
    rows = []
    for table in tables:
        rows.extend(DescTableRow.parseTable(table))

    for row in rows:
        desc_file.tagRoom(row.image_name, ROOMS[room_id])
    debug('Updated %s tags' % (room_id))
コード例 #2
0
def play_mirror(url):
    playing = False
    player = None
    orig_url = ''
    
    with common.busy_indicator():
        vidurl = common.resolve(url)
        orig_url = vidurl
        if vidurl:
            try:
                title, image = scrapers.title_image(url)
            except Exception:
                # we can proceed without the title and image
                title, image = ('', '')
            li = xbmcgui.ListItem(title)
            li.setArt({ 'thumb' : image })
            if 'User-Agent=' not in vidurl:
                vidurl = vidurl + '|User-Agent=' + urllib.quote(get_ua())
            
            # Instantiate own player class
            player = MyPlayer()
            
            player.play(vidurl, li)

            
            playing = True
    
    if player:
        counter = 0
        # Checks for a minimum of 60 seconds; keeps script alive for this time
        while player.alive and counter < 30:
            counter += 1
            xbmc.sleep(2000)
        
        if not player.hasStarted:
            common.debug('Icdrama: Player encountered a format that prevented it from starting')
            # Add to blacklist
            sourceutil.add_blacklist(orig_url)
            
            # Delete to free up reference
            del player
            
            # Try again
            play_mirror(url)
            
        else:
            # Delete to free up reference
            del player
    
    return playing
コード例 #3
0
    def get_media_url(self, host, media_id):
        url = self.get_url(host, media_id)
        cmn.debug('Icdrama: ' + url)

        if 'vidembed' in url or 'vb.icdrama' in url:
            headers = self.headers
            headers['Referer'] = 'http://adrama.to'

            response = requests.get(url, headers=headers)

            unwrapped_url = ''

            streams = self._extract_streams(response)
            cmn.debug("Icdrama: Extracted links... " + str(streams))

            unwrapped_url = ''
            if xbmcaddon.Addon().getSetting('auto_select_source') == 'true':
                unwrapped_url = sourceutil.pick_source(streams)
            else:
                unwrapped_url = helpers.pick_source(streams, False)

            if ('redirector.googlevideo.com' in unwrapped_url
                    or 'blogspot.com' in unwrapped_url
                    or 'googleusercontent.com' in unwrapped_url or 'fbcdn.net'
                    in unwrapped_url):  # for current Videobug source
                # Kodi can play directly, skip further resolve
                return unwrapped_url

            return resolveurl.resolve(unwrapped_url)
        else:
            try:
                html = self.net.http_GET(url, headers=self.headers).content

                iframe = BeautifulSoup(html,
                                       'html5lib').find(id='iframeplayer')
                if iframe:
                    iframe_url = urljoin(self.get_url(host, ''), iframe['src'])
                    return resolveurl.resolve(iframe_url)
                else:
                    cmn.popup(loc.getLocalizedString(33305))
                    return ''

            except Exception as e:
                if 'No link selected' in str(e):
                    return ''
                raise ResolverError('Icdrama resolver: ' + str(e) + ' : ' +
                                    self.get_url(host, media_id))
コード例 #4
0
ファイル: get_items.py プロジェクト: nickscript0/image_grid
def save_items(base_path='', bs=None):
    TABLE1_ID = "wikitable"

    if bs is None:
        bs = bs_from_url(BASE_URL + '/Collection_Page')

    # Loop through all wikitables on page
    wikitables = bs.findAll('table', attrs={'class': TABLE1_ID})
    desc_file = Desc(base_path)
    i = 1
    try:
        for current_table in wikitables:
            debug('Processing table ' + str(i))
            tds = current_table.findAll('td')
            save_table(tds, desc_file)
            i += 1
    finally:
        desc_file.write()
コード例 #5
0
ファイル: get_items.py プロジェクト: nickscript0/image_grid
def save_table(table_tds, desc_file):
    already_saved = get_already_saved(desc_file.base_path)
    # Loop through each table <td>
    skip_count = 0
    i = 0
    for td in table_tds:
        i += 1
        if (MAX_IMAGES and (i > MAX_IMAGES)):
            debug("Stopped at MAX_IMAGES: " + str(i))
            return
        img_item = td.find('img')
        # Last table ends with a td elemnt with no img, skip it
        if img_item is None:
            continue
        image_name = image_name_from_url(img_item['src'])
        if image_name not in already_saved:
            save_td(td, desc_file, already_saved)
        else:
            skip_count += 1
    debug('Skipped %s already saved images.' % (skip_count))
コード例 #6
0
    def do_GET(self):
        ## Make sure a query string exists
        try:
            path, qs = self.path.split('?', 1)
        except ValueError:
            #debug('Error pasring request URL')
            return
        get = parse_qs(qs)

        ## PRODUCTION ##
        ########
        ## SET CLIENT_ID AND CLIENT SECRET HERE FOR PRODUCTION
        ########
        client_id = ''
        client_secret = ''
        if hasattr(config, 'CLIENT_ID'):
            client_id = config.CLIENT_ID
        if hasattr(config, 'CLIENT_SECRET'):
            client_secret = config.CLIENT_SECRET

        ## Check for an abort request
        action = get.get('action', None)
        if action and action[0] == 'abort':
            self.send_response(200)
            self.send_header("Content-type", "text/html")
            self.end_headers()
            self.wfile.write('Authorization aborted'.encode('utf8'))
            return

        ## Twitch sends us a unique code that has to be sent back
        ## in the next request and has to match
        code = get.get('code', False)
        if not code:
            debug("Code does not exist in request")
            return
        code = code[0]

        ## This is the unique state that we sent to Twitch when we requested
        ## the Oauth authentication. If it doesn't match, something shady might
        ## be going on
        state = get.get('state', False)
        if not state:
            debug("State does not exist in request")
            return

        ## Don't do anything if the state doesn't match
        ## This could mean an attempt to fake a user login
        if state[0] != self.server.state:
            debug("State does not match!")
            return

        ## Everything looks good, so let's prepare the next request
        ## and validate everything
        body = {
            'client_id': client_id,
            'client_secret': client_secret,
            'code': code,
            'grant_type': 'authorization_code',
            'redirect_uri': 'http://localhost/'
        }
        req = requests.post('https://id.twitch.tv/oauth2/token', data=body)
        data = json.loads(req.text)

        ## If we get the expected response back, set the appropriate variables
        ## in self.server and send a 200 (success) response to the browser
        if 'access_token' in data and 'refresh_token' in data:
            self.server.auth_success = True
            self.server.access_token = data['access_token']
            self.server.refresh_token = data['refresh_token']
            self.server.expires_in = data['expires_in']

        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        self.wfile.write(
            'Authorization success! You can close this window.'.encode('utf8'))
コード例 #7
0
def save_oauth(oauth_token, refresh_token, expires_in, is_broadcaster):
    """
	Fetch all of the user information from the Twitch API and save it to the database

	Args:
		oauth_token (string): OAuth token received from Twitch
		refresh_token (string): Refresh token received from Twitch
		expires_in (int): Number of seconds until oauth_token expires
		is_broadcaster (bool): True if this is the broadcaster account
	"""
    ## PRODUCTION ##
    ########
    ## SET FERNET_KEY HERE FOR PRODUCTION
    ########
    fernet_key = ''
    if hasattr(config, 'FERNET_KEY'):
        fernet_key = config.FERNET_KEY
    ## Calcuate the exact expire time based off how many seconds the token
    ## is valid. Fetch all of the user information from the Twitch API
    ## and save it to our database
    expire_time = datetime.now() + timedelta(seconds=expires_in)
    cipher = Fernet(fernet_key)
    oauth_token = cipher.encrypt(oauth_token.encode())
    refresh_token = cipher.encrypt(refresh_token.encode())

    token = OauthTokens(oauth_token, refresh_token, expire_time)
    api = TwitchAPIHelper(token)
    user_info = api.get_this_user()

    data = user_info.get('data', [])
    if not data:
        debug('No user data found')
        return
    this_user = data[0]

    con, cur = get_db()

    ## If this is the broadcaster we need to check if a broadcaster already
    ## exists in the database
    if is_broadcaster:
        sql = "SELECT id, user_name FROM oauth WHERE is_broadcaster = 1"
        cur.execute(sql)
        res = cur.fetchone()
        if res:
            debug("Broadcaster Already Exists!")
            ## Broadcaster already exists and we should do somthing about it
            sql = "UPDATE oauth SET is_broadcaster = 0 WHERE is_broadcaster = 1"
            #sql = "DELETE FROM oauth WHERE is_broadcaster = 1"
            cur.execute(sql)
            con.commit()

    ## SQLite doesn't support booleans so convert to an integer
    is_broadcaster_int = int(is_broadcaster == True)

    ## If an account already exists for this twitch user, update the
    ## existing account
    existing = get_user_by_twitch_id(this_user['id'])
    new_user = None
    sql = 'SELECT id FROM oauth WHERE is_default = 1'
    cur.execute(sql)
    default = cur.fetchone()
    is_default = 0 if default else 1

    if existing:
        sql = "UPDATE oauth SET \
		user_name = ?, \
		login_time = datetime('now'), \
		display_name = ?, \
		oauth_token = ?, \
		refresh_token = ?, \
		token_expire_time = ?, \
		is_broadcaster = ?, \
		is_default = ? \
		WHERE id = ? \
		"

        cur.execute(sql, (this_user['login'], this_user['display_name'],
                          oauth_token, refresh_token, expire_time,
                          is_broadcaster_int, is_default, existing.id))
        con.commit()
        new_user = existing
        new_user.refresh()
    else:
        sql = "INSERT INTO oauth \
			(user_name, login_time, display_name, twitch_user_id, oauth_token, refresh_token, token_expire_time, is_broadcaster, is_default) \
			VALUES (?, datetime('now'), ?, ?, ?, ?, ?, ?, ?)"

        cur.execute(sql, (this_user['login'], this_user['display_name'],
                          this_user['id'], oauth_token, refresh_token,
                          expire_time, is_broadcaster_int, is_default))
        con.commit()
        new_user = User(cur.lastrowid)
    con.close()

    return new_user