Exemplo n.º 1
0
def get_channel_search_json(channel_id, query, page):
    offset = proto.unpadded_b64encode(proto.uint(3, (page-1)*30))
    params = proto.string(2, 'search') + proto.string(15, offset)
    params = proto.percent_b64encode(params)
    ctoken = proto.string(2, channel_id) + proto.string(3, params) + proto.string(11, query)
    ctoken = base64.urlsafe_b64encode(proto.nested(80226972, ctoken)).decode('ascii')

    key = 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8'
    url = 'https://www.youtube.com/youtubei/v1/browse?key=' + key

    data = {
        'context': {
            'client': {
                'hl': 'en',
                'gl': 'US',
                'clientName': 'WEB',
                'clientVersion': '2.20180830',
            },
        },
        'continuation': ctoken,
    }

    content_type_header = (('Content-Type', 'application/json'),)
    polymer_json = util.fetch_url(
        url, headers_desktop + content_type_header,
        data=json.dumps(data), debug_name='channel_search')

    return polymer_json
Exemplo n.º 2
0
def comment_replies_ctoken(video_id, comment_id, max_results=500):

    params = proto.string(2, comment_id) + proto.uint(9, max_results)
    params = proto.nested(3, params)

    result = proto.nested(2, proto.string(2, video_id)) + proto.uint(3,6) + proto.nested(6, params)
    return base64.urlsafe_b64encode(result).decode('ascii')
Exemplo n.º 3
0
def get_channel_search_json(channel_id, query, page):
    params = proto.string(2, 'search') + proto.string(15, str(page))
    params = proto.percent_b64encode(params)
    ctoken = proto.string(2, channel_id) + proto.string(3, params) + proto.string(11, query)
    ctoken = base64.urlsafe_b64encode(proto.nested(80226972, ctoken)).decode('ascii')

    polymer_json = util.fetch_url("https://www.youtube.com/browse_ajax?ctoken=" + ctoken, util.desktop_ua + headers_1, debug_name='channel_search')

    return polymer_json
Exemplo n.º 4
0
def make_comment_ctoken(video_id, sort=0, offset=0, secret_key=''):
    video_id = proto.as_bytes(video_id)
    secret_key = proto.as_bytes(secret_key)

    page_info = proto.string(4, video_id) + proto.uint(6, sort)
    offset_information = proto.nested(4, page_info) + proto.uint(5, offset)
    if secret_key:
        offset_information = proto.string(1, secret_key) + offset_information

    result = proto.nested(2, proto.string(2, video_id)) + proto.uint(
        3, 6) + proto.nested(6, offset_information)
    return base64.urlsafe_b64encode(result).decode('ascii')
Exemplo n.º 5
0
def channel_ctoken(channel_id, page, sort, tab, view=1):  
    
    tab = proto.string(2, tab )
    sort = proto.uint(3, int(sort))
    page = proto.string(15, str(page) )
    view = proto.uint(6, int(view))
    continuation_info = proto.string( 3, proto.percent_b64encode(tab + view + sort + page) )
    
    channel_id = proto.string(2, channel_id )
    pointless_nest = proto.string(80226972, channel_id + continuation_info)

    return base64.urlsafe_b64encode(pointless_nest).decode('ascii')
Exemplo n.º 6
0
def get_channel_search_json(channel_id, query, page):
    params = proto.string(2, 'search') + proto.string(15, str(page))
    params = proto.percent_b64encode(params)
    ctoken = proto.string(2, channel_id) + proto.string(3, params) + proto.string(11, query)
    ctoken = base64.urlsafe_b64encode(proto.nested(80226972, ctoken)).decode('ascii')

    polymer_json = common.fetch_url("https://www.youtube.com/browse_ajax?ctoken=" + ctoken, headers_1)
    '''with open('debug/channel_search_debug', 'wb') as f:
        f.write(polymer_json)'''
    polymer_json = json.loads(polymer_json)

    return polymer_json
Exemplo n.º 7
0
def channel_ctoken_v1(channel_id, page, sort, tab, view=1):
    tab = proto.string(2, tab )
    sort = proto.uint(3, int(sort))
    page = proto.string(15, str(page) )
    # example with shelves in videos tab: https://www.youtube.com/channel/UCNL1ZadSjHpjm4q9j2sVtOA/videos
    shelf_view = proto.uint(4, 0)
    view = proto.uint(6, int(view))
    continuation_info = proto.string(3, proto.percent_b64encode(tab + view + sort + shelf_view + page + proto.uint(23, 0)) )

    channel_id = proto.string(2, channel_id )
    pointless_nest = proto.string(80226972, channel_id + continuation_info)

    return base64.urlsafe_b64encode(pointless_nest).decode('ascii')
Exemplo n.º 8
0
def playlist_ctoken(playlist_id, offset):

    offset = proto.uint(1, offset)
    # this is just obfuscation as far as I can tell. It doesn't even follow protobuf
    offset = b'PT:' + proto.unpadded_b64encode(offset)
    offset = proto.string(15, offset)

    continuation_info = proto.string(3, proto.percent_b64encode(offset))

    playlist_id = proto.string(2, 'VL' + playlist_id)
    pointless_nest = proto.string(80226972, playlist_id + continuation_info)

    return base64.urlsafe_b64encode(pointless_nest).decode('ascii')
Exemplo n.º 9
0
def channel_ctoken_v2(channel_id, page, sort, tab, view=1):
    # see https://github.com/iv-org/invidious/issues/1319#issuecomment-671732646
    # page > 1 doesn't work when sorting by oldest
    offset = 30 * (int(page) - 1)
    schema_number = {
        3: 6307666885028338688,
        2: 17254859483345278706,
        1: 16570086088270825023,
    }[int(sort)]
    page_token = proto.string(
        61,
        proto.unpadded_b64encode(
            proto.string(
                1,
                proto.uint(1, schema_number) + proto.string(
                    2,
                    proto.string(
                        1, proto.unpadded_b64encode(proto.uint(1, offset)))))))

    tab = proto.string(2, tab)
    sort = proto.uint(3, int(sort))
    #page = proto.string(15, str(page) )

    shelf_view = proto.uint(4, 0)
    view = proto.uint(6, int(view))
    continuation_info = proto.string(
        3,
        proto.percent_b64encode(tab + sort + shelf_view + view + page_token))

    channel_id = proto.string(2, channel_id)
    pointless_nest = proto.string(80226972, channel_id + continuation_info)

    return base64.urlsafe_b64encode(pointless_nest).decode('ascii')
Exemplo n.º 10
0
def _post_comment_reply(text, video_id, parent_comment_id, session_token,
                        cookiejar):
    headers = {
        'User-Agent':
        'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
        'Accept': '*/*',
        'Accept-Language': 'en-US,en;q=0.5',
        'X-YouTube-Client-Name': '2',
        'X-YouTube-Client-Version': '2.20180823',
        'Content-Type': 'application/x-www-form-urlencoded',
    }

    comment_params = proto.string(2, video_id) + proto.string(
        4, parent_comment_id) + proto.nested(5, proto.uint(1, 0)) + proto.uint(
            6, 0) + proto.uint(10, 1)
    comment_params = proto.percent_b64encode(comment_params).decode('ascii')

    sej = json.dumps({
        "clickTrackingParams": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
        "commandMetadata": {
            "webCommandMetadata": {
                "url": "/service_ajax",
                "sendPost": True
            }
        },
        "createCommentReplyEndpoint": {
            "createReplyParams": comment_params
        }
    })

    data_dict = {
        'comment_text': text,
        'sej': sej,
        'session_token': session_token,
    }
    data = urllib.parse.urlencode(data_dict).encode()

    content = util.fetch_url(
        "https://m.youtube.com/service_ajax?name=createCommentReplyEndpoint",
        headers=headers,
        data=data,
        cookiejar_send=cookiejar)

    code = json.loads(content)['code']
    print("Comment posting code: " + code)
    return code
    '''with open('debug/post_comment_response', 'wb') as f:
Exemplo n.º 11
0
def page_number_to_sp_parameter(page, autocorrect, sort, filters):
    offset = (int(page) - 1) * 20  # 20 results per page
    autocorrect = proto.nested(8, proto.uint(1, 1 - int(autocorrect)))
    filters_enc = proto.nested(
        2,
        proto.uint(1, filters['time']) + proto.uint(2, filters['type']) +
        proto.uint(3, filters['duration']))
    result = proto.uint(1, sort) + filters_enc + autocorrect + proto.uint(
        9, offset) + proto.string(61, b'')
    return base64.urlsafe_b64encode(result).decode('ascii')
Exemplo n.º 12
0
def _delete_comment(video_id, comment_id, author_id, session_token, cookiejar):
    headers = {
        'User-Agent':
        'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
        'Accept': '*/*',
        'Accept-Language': 'en-US,en;q=0.5',
        'X-YouTube-Client-Name': '2',
        'X-YouTube-Client-Version': '2.20180823',
        'Content-Type': 'application/x-www-form-urlencoded',
    }
    action = proto.uint(1, 6) + proto.string(3, comment_id) + proto.string(
        5, video_id) + proto.string(9, author_id)
    action = proto.percent_b64encode(action).decode('ascii')

    sej = json.dumps({
        "clickTrackingParams": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
        "commandMetadata": {
            "webCommandMetadata": {
                "url": "/service_ajax",
                "sendPost": True
            }
        },
        "performCommentActionEndpoint": {
            "action": action
        }
    })

    data_dict = {
        'sej': sej,
        'session_token': session_token,
    }
    data = urllib.parse.urlencode(data_dict).encode()

    content = util.fetch_url(
        "https://m.youtube.com/service_ajax?name=performCommentActionEndpoint",
        headers=headers,
        data=data,
        cookiejar_send=cookiejar)
    code = json.loads(content)['code']
    print("Comment deletion code: " + code)
    return code
Exemplo n.º 13
0
def channel_ctoken_v3(channel_id, page, sort, tab, view=1):
    # page > 1 doesn't work when sorting by oldest
    offset = 30*(int(page) - 1)
    page_token = proto.string(61, proto.unpadded_b64encode(
        proto.string(1, proto.unpadded_b64encode(proto.uint(1,offset)))
    ))

    tab = proto.string(2, tab )
    sort = proto.uint(3, int(sort))

    shelf_view = proto.uint(4, 0)
    view = proto.uint(6, int(view))
    continuation_info = proto.string(3,
        proto.percent_b64encode(tab + sort + shelf_view + view + page_token)
    )

    channel_id = proto.string(2, channel_id )
    pointless_nest = proto.string(80226972, channel_id + continuation_info)

    return base64.urlsafe_b64encode(pointless_nest).decode('ascii')
Exemplo n.º 14
0
def single_comment_ctoken(video_id, comment_id):
    page_params = proto.string(2, video_id) + proto.string(6, proto.percent_b64encode(proto.string(15, comment_id)))

    result = proto.nested(2, page_params) + proto.uint(3,6)
    return base64.urlsafe_b64encode(result).decode('ascii')
Exemplo n.º 15
0
def page_number_to_sp_parameter(page, autocorrect=1, sort=0):
    offset = (int(page) - 1) * 20  # 20 results per page
    autocorrect = proto.nested(8, proto.uint(1, 1 - int(autocorrect)))
    result = proto.uint(1, sort) + proto.uint(9, offset) + proto.string(
        61, b'') + autocorrect
    return base64.urlsafe_b64encode(result).decode('ascii')