コード例 #1
0
ファイル: views.py プロジェクト: os2git/documentbroker
def acknowledge_document(user_authentication, document):
    """Acknowledge the retrieval of a document generated by a previous
    request. Deletes the generated document, so that it's no more
    available."""
    clid = get_client_id(user_authentication)
    broker = DocumentBroker(clid)
    return broker.acknowledge_document(document)
コード例 #2
0
ファイル: views.py プロジェクト: os2git/documentbroker
def generate_fo_template(user_authentication, template_id, fo_file):
    """Get template from template server and generates fo template.
    Store document in suitable place and return URL to retrieve it."""

    clid = get_client_id(user_authentication)
    broker = DocumentBroker(clid)
    return broker.generate_fo_template(template_id, fo_file)
コード例 #3
0
ファイル: views.py プロジェクト: os2git/documentbroker
def generate_preview(user_authentication, template_id, fields, return_format,
                     resolusion):
    """Get template from template server and generates a preview.
    Store preview in suitable place and return URL to retrieve it."""

    clid = get_client_id(user_authentication)
    broker = DocumentBroker(clid)
    return broker.generate_preview(template_id, fields, return_format,
                                   resolusion)
コード例 #4
0
ファイル: views.py プロジェクト: os2git/documentbroker
def generate_template_image(user_authentication, template_id, resolusion,
                            image_type, file_path):
    """Get template from template server and generates a preview.
    Store preview in suitable place and return URL to retrieve it."""

    clid = get_client_id(user_authentication)
    broker = DocumentBroker(clid)
    return broker.generate_template_image(template_id, resolusion, image_type,
                                          file_path)
コード例 #5
0
 def _watch_streams_loop(self):
     while self.kill is False:
         try:
             self._watch_streams()
         except Exception as e:
             print('Daemon crashed: ' + str(e))
             try:
                 client_id = get_client_id()
                 self.CLIENT = TwitchClient(client_id=client_id)
                 print('Daemon recovered success.')
             except Exception as e:
                 print('Daemon retry error.')
         time.sleep(self.check_interval)
コード例 #6
0
 def __init__(self, server_address, RequestHandlerClass):
     super().__init__(server_address, RequestHandlerClass)
     self.PORT = server_address[1]
     self.streamers = {}  # holds all streamers that need to be surveilled
     self.watched_streamers = {
     }  # holds all live streamers that are currently being recorded
     self.client_id = get_client_id()
     self.kill = False
     self.started = False
     self.download_folder = os.getcwd() + os.path.sep + "#streamer#"
     # ThreadPoolExecutor(max_workers): If max_workers is None or not given, it will default to the number of
     # processors on the machine, multiplied by 5
     self.pool = ThreadPoolExecutor()
コード例 #7
0
ファイル: api.py プロジェクト: chhe/Twitch.tv-on-XBMC
 def valid_token(self, client_id, token, scopes):  # client_id, token used for unique caching only
     token_check = self.root()
     while True:
         if not token_check['token']['valid']:
             result = kodi.Dialog().ok(heading=i18n('oauth_token'), line1=i18n('invalid_token'),
                                       line2=i18n('get_new_oauth_token') % (i18n('settings'), i18n('login'), i18n('get_oauth_token')))
             log_utils.log('Error: Current OAuth token is invalid.', log_utils.LOGERROR)
             return False
         else:
             if token_check['token']['client_id'] == self.client_id:
                 if token_check['token']['authorization']:
                     token_scopes = token_check['token']['authorization']['scopes']
                     missing_scopes = [value for value in scopes if value not in token_scopes]
                     if len(missing_scopes) > 0:
                         result = kodi.Dialog().ok(heading=i18n('oauth_token'), line1=i18n('missing_scopes') % missing_scopes,
                                                   line2=i18n('get_new_oauth_token') % (i18n('settings'), i18n('login'), i18n('get_oauth_token')))
                         log_utils.log('Error: Current OAuth token is missing required scopes |%s|' % missing_scopes, log_utils.LOGERROR)
                         return False
                     else:
                         return True
                 else:
                     return False
             else:
                 matches_default = token_check['token']['client_id'] == utils.get_client_id(default=True)
                 message = 'Token created using default Client-ID |%s|' % str(matches_default)
                 log_utils.log('Error: OAuth Client-ID mismatch: %s' % message, log_utils.LOGERROR)
                 if matches_default:
                     result = kodi.Dialog().ok(heading=i18n('oauth_token'), line1=i18n('client_id_mismatch'), line2=i18n('ok_to_resolve'))
                     utils.clear_client_id()
                     self.client_id = utils.get_client_id(default=True)
                     self.queries.CLIENT_ID = self.client_id
                     self.client = oauth.MobileClient(self.client_id)
                 else:
                     result = kodi.Dialog().ok(heading=i18n('oauth_token'), line1=i18n('client_id_mismatch'),
                                               line2=i18n('get_new_oauth_token') % (i18n('settings'), i18n('login'), i18n('get_oauth_token')))
                     return False
コード例 #8
0
ファイル: api.py プロジェクト: Tomalak/Twitch-on-Kodi
 def valid_token(self, client_id, token,
                 scopes):  # client_id, token used for unique caching only
     token_check = self.root()
     while True:
         if not token_check['token']['valid']:
             result = kodi.Dialog().ok(
                 heading=i18n('oauth_token'),
                 line1=i18n('invalid_token'),
                 line2=i18n('get_new_oauth_token') %
                 (i18n('settings'), i18n('login'), i18n('get_oauth_token')))
             log_utils.log('Error: Current OAuth token is invalid.',
                           log_utils.LOGERROR)
             return False
         else:
             if token_check['token']['client_id'] == self.client_id:
                 if token_check['token']['authorization']:
                     token_scopes = token_check['token']['authorization'][
                         'scopes']
                     missing_scopes = [
                         value for value in scopes
                         if value not in token_scopes
                     ]
                     if len(missing_scopes) > 0:
                         result = kodi.Dialog().ok(
                             heading=i18n('oauth_token'),
                             line1=i18n('missing_scopes') % missing_scopes,
                             line2=i18n('get_new_oauth_token') %
                             (i18n('settings'), i18n('login'),
                              i18n('get_oauth_token')))
                         log_utils.log(
                             'Error: Current OAuth token is missing required scopes |%s|'
                             % missing_scopes, log_utils.LOGERROR)
                         return False
                     else:
                         return True
                 else:
                     return False
             else:
                 matches_default = token_check['token'][
                     'client_id'] == utils.get_client_id(default=True)
                 message = 'Token created using default Client-ID |%s|' % str(
                     matches_default)
                 log_utils.log(
                     'Error: OAuth Client-ID mismatch: %s' % message,
                     log_utils.LOGERROR)
                 if matches_default:
                     result = kodi.Dialog().ok(
                         heading=i18n('oauth_token'),
                         line1=i18n('client_id_mismatch'),
                         line2=i18n('ok_to_resolve'))
                     utils.clear_client_id()
                     self.client_id = utils.get_client_id(default=True)
                     self.queries.CLIENT_ID = self.client_id
                     self.client = oauth.MobileClient(self.client_id)
                 else:
                     result = kodi.Dialog().ok(
                         heading=i18n('oauth_token'),
                         line1=i18n('client_id_mismatch'),
                         line2=i18n('get_new_oauth_token') %
                         (i18n('settings'), i18n('login'),
                          i18n('get_oauth_token')))
                     return False
コード例 #9
0
ファイル: api.py プロジェクト: Tomalak/Twitch-on-Kodi
class Twitch:
    api = twitch
    usher = usher
    queries = twitch_queries
    client_id = utils.get_client_id()
    access_token = utils.get_oauth_token(token_only=True, required=False)
    required_scopes = SCOPES

    def __init__(self):
        self.queries.CLIENT_ID = self.client_id
        self.queries.OAUTH_TOKEN = self.access_token
        self.client = oauth.MobileClient(self.client_id)
        if self.access_token:
            if not self.valid_token(self.client_id, self.access_token,
                                    self.required_scopes):
                self.queries.OAUTH_TOKEN = ''
                self.access_token = ''

    @cache.cache_method(cache_limit=1)
    def valid_token(self, client_id, token,
                    scopes):  # client_id, token used for unique caching only
        token_check = self.root()
        while True:
            if not token_check['token']['valid']:
                result = kodi.Dialog().ok(
                    heading=i18n('oauth_token'),
                    line1=i18n('invalid_token'),
                    line2=i18n('get_new_oauth_token') %
                    (i18n('settings'), i18n('login'), i18n('get_oauth_token')))
                log_utils.log('Error: Current OAuth token is invalid.',
                              log_utils.LOGERROR)
                return False
            else:
                if token_check['token']['client_id'] == self.client_id:
                    if token_check['token']['authorization']:
                        token_scopes = token_check['token']['authorization'][
                            'scopes']
                        missing_scopes = [
                            value for value in scopes
                            if value not in token_scopes
                        ]
                        if len(missing_scopes) > 0:
                            result = kodi.Dialog().ok(
                                heading=i18n('oauth_token'),
                                line1=i18n('missing_scopes') % missing_scopes,
                                line2=i18n('get_new_oauth_token') %
                                (i18n('settings'), i18n('login'),
                                 i18n('get_oauth_token')))
                            log_utils.log(
                                'Error: Current OAuth token is missing required scopes |%s|'
                                % missing_scopes, log_utils.LOGERROR)
                            return False
                        else:
                            return True
                    else:
                        return False
                else:
                    matches_default = token_check['token'][
                        'client_id'] == utils.get_client_id(default=True)
                    message = 'Token created using default Client-ID |%s|' % str(
                        matches_default)
                    log_utils.log(
                        'Error: OAuth Client-ID mismatch: %s' % message,
                        log_utils.LOGERROR)
                    if matches_default:
                        result = kodi.Dialog().ok(
                            heading=i18n('oauth_token'),
                            line1=i18n('client_id_mismatch'),
                            line2=i18n('ok_to_resolve'))
                        utils.clear_client_id()
                        self.client_id = utils.get_client_id(default=True)
                        self.queries.CLIENT_ID = self.client_id
                        self.client = oauth.MobileClient(self.client_id)
                    else:
                        result = kodi.Dialog().ok(
                            heading=i18n('oauth_token'),
                            line1=i18n('client_id_mismatch'),
                            line2=i18n('get_new_oauth_token') %
                            (i18n('settings'), i18n('login'),
                             i18n('get_oauth_token')))
                        return False

    @api_error_handler
    def root(self):
        results = self.api.root()
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=1)
    def get_user(self, token):  # token used for unique caching only
        results = self.api.users.user()
        return self.error_check(results)

    def get_user_id(self):
        results = self.get_user(self.access_token)
        return results.get(Keys._ID)

    def get_username(self):
        results = self.get_user(self.access_token)
        return results.get(Keys.NAME)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_featured_streams(self, offset, limit):
        results = self.api.streams.get_featured(offset=offset, limit=limit)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_top_games(self, offset, limit):
        results = self.api.games.get_top(offset=offset, limit=limit)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_top_communities(self, cursor, limit):
        results = self.api.communities.get_top(cursor=cursor, limit=limit)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_collections(self, channel_id, cursor, limit):
        results = self.api.collections.get_collections(channel_id=channel_id,
                                                       cursor=cursor,
                                                       limit=limit)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_all_streams(self,
                        stream_type,
                        platform,
                        offset,
                        limit,
                        language=Language.ALL):
        results = self.api.streams.get_all(stream_type=stream_type,
                                           platform=platform,
                                           offset=offset,
                                           limit=limit,
                                           language=language)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_all_teams(self, offset, limit):
        results = self.api.teams.get_active(offset=offset, limit=limit)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_followed_channels(self,
                              user_id,
                              offset,
                              limit,
                              direction=Direction.DESC,
                              sort_by=SortBy.LAST_BROADCAST):
        results = self.api.users.get_follows(user_id=user_id,
                                             limit=limit,
                                             offset=offset,
                                             direction=direction,
                                             sort_by=sort_by)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_top_videos(self,
                       offset,
                       limit,
                       broadcast_type,
                       period=Period.WEEK,
                       game=None):
        results = self.api.videos.get_top(limit=limit,
                                          offset=offset,
                                          game=game,
                                          broadcast_type=broadcast_type,
                                          period=period)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_followed_clips(self,
                           cursor,
                           limit,
                           trending=Boolean.TRUE,
                           language=Language.ALL):
        results = self.api.clips.get_followed(limit=limit,
                                              cursor=cursor,
                                              trending=trending,
                                              language=language)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_top_clips(self,
                      cursor,
                      limit,
                      channel=None,
                      game=None,
                      period=ClipPeriod.WEEK,
                      trending=Boolean.TRUE,
                      language=Language.ALL):
        results = self.api.clips.get_top(limit=limit,
                                         cursor=cursor,
                                         channels=channel,
                                         games=game,
                                         period=period,
                                         trending=trending,
                                         language=language)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_channel_videos(self,
                           channel_id,
                           offset,
                           limit,
                           broadcast_type,
                           sort_by=VideoSort.TIME,
                           language=Language.ALL):
        results = self.api.channels.get_videos(channel_id=channel_id,
                                               limit=limit,
                                               offset=offset,
                                               broadcast_type=broadcast_type,
                                               sort_by=sort_by,
                                               language=language)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_collection_videos(self, collection_id):
        results = self.api.collections.by_id(collection_id=collection_id,
                                             include_all=Boolean.FALSE)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_game_streams(self, game, offset, limit, language=Language.ALL):
        results = self.api.streams.get_all(game=game,
                                           limit=limit,
                                           offset=offset,
                                           language=language)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_community_streams(self,
                              community_id,
                              offset,
                              limit,
                              language=Language.ALL):
        results = self.api.streams.get_all(community_id=community_id,
                                           limit=limit,
                                           offset=offset,
                                           language=language)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_channel_search(self, search_query, offset, limit):
        results = self.api.search.channels(search_query=search_query,
                                           limit=limit,
                                           offset=offset)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_stream_search(self, search_query, offset, limit):
        results = self.api.search.streams(search_query=search_query,
                                          limit=limit,
                                          offset=offset)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_game_search(self, search_query):
        results = self.api.search.games(search_query=search_query)
        return self.error_check(results)

    @api_error_handler
    def check_follow(self, channel_id):
        user_id = self.get_user_id()
        results = self.api.users.check_follows(user_id=user_id,
                                               channel_id=channel_id)
        return self.return_boolean(results)

    @api_error_handler
    def follow(self, channel_id):
        user_id = self.get_user_id()
        results = self.api.users.follow_channel(user_id=user_id,
                                                channel_id=channel_id)
        return self.error_check(results)

    @api_error_handler
    def unfollow(self, channel_id):
        user_id = self.get_user_id()
        results = self.api.users.unfollow_channel(user_id=user_id,
                                                  channel_id=channel_id)
        return self.error_check(results)

    @api_error_handler
    def check_follow_game(self, game):
        username = self.get_username()
        results = self.api.games._check_follows(username=username, name=game)
        return self.return_boolean(results)

    @api_error_handler
    def follow_game(self, game):
        username = self.get_username()
        results = self.api.games._follow(username=username, name=game)
        return self.error_check(results)

    @api_error_handler
    def unfollow_game(self, game):
        username = self.get_username()
        results = self.api.games._unfollow(username=username, name=game)
        return self.error_check(results)

    @api_error_handler
    def check_subscribed(self, channel_id):
        user_id = self.get_user_id()
        results = self.api.users.check_subscription(channel_id=channel_id,
                                                    user_id=user_id)
        return self.return_boolean(results)

    @api_error_handler
    def blocks(self, offset, limit):
        user_id = self.get_user_id()
        results = self.api.users.get_blocks(user_id=user_id,
                                            limit=limit,
                                            offset=offset)
        return self.error_check(results)

    @api_error_handler
    def block_user(self, target_id):
        user_id = self.get_user_id()
        results = self.api.users.block_user(user_id=user_id,
                                            target_id=target_id)
        return self.error_check(results)

    @api_error_handler
    def unblock_user(self, target_id):
        user_id = self.get_user_id()
        results = self.api.users.unblock_user(user_id=user_id,
                                              target_id=target_id)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_video_by_id(self, video_id):
        results = self.api.videos.by_id(video_id=video_id)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def _get_video_by_id(self, video_id):
        results = self.api.videos._by_id(video_id=video_id)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_clip_by_slug(self, slug):
        results = self.api.clips.by_slug(slug=slug)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_channel_stream(self, channel_id):
        results = self.api.streams.by_id(channel_id=channel_id,
                                         stream_type=StreamType.ALL)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_streams_by_channels(self, names, offset, limit):
        query = self.queries.ApiQuery('streams')
        query.add_param('offset', offset)
        query.add_param('limit', limit)
        query.add_param('channel', names)
        results = query.execute()
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_followed_games(self, name):
        results = self.api.games._get_followed(username=name)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_followed_streams(self, stream_type, offset, limit):
        results = self.api.streams.get_followed(stream_type=stream_type,
                                                limit=limit,
                                                offset=offset)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_vod(self, video_id):
        results = self.usher.video(video_id)
        return self.error_check(results)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_clip(self, slug):
        return self.usher.clip(slug)

    @api_error_handler
    @cache.cache_method(cache_limit=cache.limit)
    def get_live(self, name):
        results = self.usher.live(name)
        return self.error_check(results)

    def get_user_blocks(self):
        limit = 100
        offset = 0

        user_blocks = []
        while True:
            temp = self.blocks(offset, limit)
            if len(temp[Keys.BLOCKS]) == 0:
                break
            for user in temp[Keys.BLOCKS]:
                user_blocks.append((user[Keys.USER][Keys._ID],
                                    user[Keys.USER][Keys.DISPLAY_NAME]
                                    if user[Keys.USER][Keys.DISPLAY_NAME] else
                                    user[Keys.USER][Keys.NAME]))
            offset += limit
            if temp[Keys.TOTAL] <= offset:
                break

        return user_blocks

    @staticmethod
    def error_check(results):
        if 'error' in results: raise TwitchException(results)
        return results

    @staticmethod
    def return_boolean(results):
        if ('error' in results) and (results['status'] == 404):
            return False
        elif 'error' in results:
            raise TwitchException(results)
        else:
            return True
コード例 #10
0
import requests

import utils

auth = {
    'Client-ID': str(utils.get_client_id()),
    'Authorization': 'Bearer ' + utils.get_app_access_token()
}


def get_user_info(user_login, *args: str) -> list:
    """
    Gets user info for user logins
    See https://dev.twitch.tv/docs/api/reference#get-users

    Parameters
    ----------
    user_login: str
        username string
    args: str
        additional string usernames (max. 99)

    Returns
    -------
    list
        contains user_info dicts
    """
    get_user_id_url = 'https://api.twitch.tv/helix/users?login=' + user_login
    if len(args) > 99:
        args = args[:99]
    for user_login_i in args:
コード例 #11
0
 def __init__(self):
     client_id = get_client_id()
     self.CLIENT = TwitchClient(client_id=client_id)
コード例 #12
0
import threading

import ATRHandler
import utils
from atr_cmd import AtrCmd
from daemon import Daemon

if __name__ == '__main__':
    utils.get_client_id()  # creates necessary config before launch
    server = Daemon(('127.0.0.1', 1234), ATRHandler.ATRHandler)
    threading.Thread(target=server.serve_forever).start()
    AtrCmd().cmdloop_with_keyboard_interrupt()