Esempio n. 1
0
def get_comments_page():
    ctoken = request.args.get('ctoken', '')
    replies = request.args.get('replies', '0') == '1'

    comments_info = yt_data_extract.extract_comments_info(
        request_comments(ctoken, replies), ctoken=ctoken
    )
    post_process_comments_info(comments_info)

    if not replies:
        if comments_info['sort'] is None or comments_info['video_id'] is None:
            other_sort_url = None
        else:
            other_sort_url = (
                util.URL_ORIGIN
                + '/comments?ctoken='
                + make_comment_ctoken(comments_info['video_id'],
                                      sort=1-comments_info['sort'])
            )
        other_sort_text = 'Sort by ' + ('newest' if comments_info['sort'] == 0 else 'top')
        comments_info['comment_links'] = [(other_sort_text, other_sort_url)]

    return flask.render_template('comments_page.html',
        comments_info = comments_info,
        slim = request.args.get('slim', False)
    )
Esempio n. 2
0
def get_comments_page():
    ctoken = request.args.get('ctoken', '')
    replies = False
    if not ctoken:
        video_id = request.args['video_id']
        parent_id = request.args['parent_id']

        ctoken = comment_replies_ctoken(video_id, parent_id)
        replies = True

    comments_info = yt_data_extract.extract_comments_info(
        request_comments(ctoken, replies))
    post_process_comments_info(comments_info)

    if not replies:
        other_sort_url = util.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(
            comments_info['video_id'], sort=1 - comments_info['sort'])
        other_sort_text = 'Sort by ' + ('newest' if comments_info['sort'] == 0
                                        else 'top')
        comments_info['comment_links'] = [(other_sort_text, other_sort_url)]

    comment_posting_box_info = {
        'form_action': '' if replies else util.URL_ORIGIN + '/post_comment',
        'video_id': comments_info['video_id'],
        'accounts': accounts.account_list_data(),
        'include_video_id_input': not replies,
        'replying': replies,
    }

    return flask.render_template(
        'comments_page.html',
        comments_info=comments_info,
        comment_posting_box_info=comment_posting_box_info,
    )
Esempio n. 3
0
def video_comments(video_id, sort=0, offset=0, lc='', secret_key=''):
    if settings.comments_mode:
        comments_info = yt_data_extract.extract_comments_info(request_comments(make_comment_ctoken(video_id, sort, offset, lc, secret_key)))
        post_process_comments_info(comments_info)

        other_sort_url = util.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(video_id, sort=1 - sort, lc=lc)
        other_sort_text = 'Sort by ' + ('newest' if sort == 0 else 'top')
        comments_info['comment_links'] = [(other_sort_text, other_sort_url)]

        return comments_info

    return {}
Esempio n. 4
0
def video_comments(video_id, sort=0, offset=0, lc='', secret_key=''):
    try:
        if settings.comments_mode:
            comments_info = {'error': None}
            other_sort_url = (
                util.URL_ORIGIN + '/comments?ctoken='
                + make_comment_ctoken(video_id, sort=1 - sort, lc=lc)
            )
            other_sort_text = 'Sort by ' + ('newest' if sort == 0 else 'top')

            this_sort_url = (util.URL_ORIGIN
                             + '/comments?ctoken='
                             + make_comment_ctoken(video_id, sort=sort, lc=lc))

            comments_info['comment_links'] = [
                (other_sort_text, other_sort_url),
                ('Direct link', this_sort_url)
            ]

            ctoken = make_comment_ctoken(video_id, sort, offset, lc)
            comments_info.update(yt_data_extract.extract_comments_info(
                request_comments(ctoken), ctoken=ctoken
            ))
            post_process_comments_info(comments_info)

            return comments_info
        else:
            return {}
    except util.FetchError as e:
        if e.code == '429' and settings.route_tor:
            comments_info['error'] = 'Error: Youtube blocked the request because the Tor exit node is overutilized.'
            if e.error_message:
                comments_info['error'] += '\n\n' + e.error_message
            comments_info['error'] += '\n\nExit node IP address: %s' % e.ip
        else:
            comments_info['error'] = traceback.format_exc()

    except Exception as e:
        comments_info['error'] = traceback.format_exc()

    if comments_info.get('error'):
        print('Error retrieving comments for ' + str(video_id) + ':\n' +
              comments_info['error'])

    return comments_info
Esempio n. 5
0
def get_comments_page():
    ctoken = request.args.get('ctoken', '')
    replies = False
    if not ctoken:
        video_id = request.args['video_id']
        parent_id = request.args['parent_id']

        ctoken = comment_replies_ctoken(video_id, parent_id)
        replies = True

    comments_info = yt_data_extract.extract_comments_info(request_comments(ctoken, replies))
    post_process_comments_info(comments_info)

    if not replies:
        other_sort_url = util.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(comments_info['video_id'], sort=1 - comments_info['sort'])
        other_sort_text = 'Sort by ' + ('newest' if comments_info['sort'] == 0 else 'top')
        comments_info['comment_links'] = [(other_sort_text, other_sort_url)]

    return flask.render_template('comments_page.html',
        comments_info = comments_info,
        slim = request.args.get('slim', False)
    )