长江雨课堂刷课原理分析记录-python脚本技

浮夸小生。
2023-12-03 / 0 评论 / 408 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2023年12月03日,已超过369天没有更新,若内容或图片失效,请留言反馈。

前言

  本篇文章仅限于技术交流-请勿用于商业用途。(如有侵权请联系我,24小时内删除该文章)
  起因:高中好哥们(假小子->变大美女)问我长江雨课堂能不能shua课???? emmm...这真不好拒绝,直接抓包分析!!!

视频

  通过浏览器发包分析 存在心跳包 每五秒一次,接口 以及 发包参数如下:

#接口:
  https://changjiang.yuketang.cn/video-log/heartbeat/
#发包参数:
  'heart_data': [
            {
                'i': 5, #常量
                'et': 'playing', #播放操作
                'p': 'web', #常量
                'n': 'ali-cdn.xuetangx.com',#常量
                'lob': 'ykt',# 常量
                'cp': videoTime, # 播放进度 ->>>>>>>模拟生成
                'fp': 0, # 常量
                'tp': videoTime, # 视频时长
                'sp': 1,# 常量
                'ts': int(time.time() * 1000), # 时间戳 13位 我这里用python直接模拟的
                'u': u,# user_id
                'uip': '',# 常量
                'c': c,# course_id
                'v': v,# 视频id
                'skuid': skuid, # skuid
                'classroomid': classroomid, #classroom_id
                'cc': cc, # 常量
                'd': duration, # 视频时常
                'pg': pg, #视频id + 随机字符串 可以写死
                'sq': 2,  # 常量
                't': 'video', # 常量
                'cards_id': 0, # 常量
                'slide': 0, # 常量
                'v_url': '', # 常量
            }
        ]
#以上视频参数 可以在以下接口获取参数值:
https://changjiang.yuketang.cn/c27/online_courseware/xty/kls/pub_news/'+课件id+'/

#课件id的值通过该元素获取courseware_id

python代码

  • 目前只完成了 视频代码部分(默认是全部课程都刷->按顺序刷课)
  • 我没有学过python,代码很烂 勿喷
import json
import time
import random
import re
import requests


#cookies 填写自己的即可 
cookies = {} 


# 课程列表
def course_list():
    headers = {
        'authority': 'changjiang.yuketang.cn',
        'accept': 'application/json, text/plain, */*',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'no-cache',
        'pragma': 'no-cache',
        'referer': 'https://changjiang.yuketang.cn/v2/web/index',
        'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'university-id': '0',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
        'uv-id': '0',
        'xt-agent': 'web',
        'xtbz': 'ykt',
    }

    params = {
        'identity': '2',
    }

    response = requests.get('https://changjiang.yuketang.cn/v2/api/web/courses/list', params=params, cookies=cookies,
                            headers=headers)
    return response.text


## 访问课程链接
def course_info(course_id):
    headers = {
        'authority': 'changjiang.yuketang.cn',
        'accept': 'application/json, text/plain, */*',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'no-cache',
        'classroom-id': '14037619',
        # 'cookie': 'JG_fcdf8e635093adde6bef42651_PV=1701342457885|1701342464783; django_language=zh-cn; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThjMWY3MTE4MzAxNmQ2LTBjZTM0NjRkYWQ4YmQ1OC0xNjUyNTYzNC0yMDczNjAwLTE4YzFmNzExODMxMjZhNyJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%7D; sajssdk_2015_cross_new_user=1; csrftoken=kWczx89mCJgThyBIBlOitizxRIH7Tuef; sessionid=byzyzsb66yxmrf0vy702ap05mm88i74d; user_role=-1; classroomId=14037619; classroom_id=14037619; JG_fcdf8e635093adde6bef42651_PV=1701342457656|1701342457656',
        'pragma': 'no-cache',
        'referer': 'https://changjiang.yuketang.cn/v2/web/studentLog/14037619',
        'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'university-id': '2868',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
        'uv-id': '2868',
        'xt-agent': 'web',
        'xtbz': 'ykt',
    }
    params = {
        'actype': '-1',
        'page': '0',
        'offset': '20',
        'sort': '-1',
    }
    response = requests.get(
        'https://changjiang.yuketang.cn/v2/api/web/logs/learn/'+str(course_id), params=params, cookies=cookies,headers=headers)

    return response.text


def courseware(id):
    headers = {
        'authority': 'changjiang.yuketang.cn',
        'accept': 'application/json, text/plain, */*',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'no-cache',
        'classroom-id': '14037619',
        # 'cookie': 'django_language=zh-cn; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThjMWY3MTE4MzAxNmQ2LTBjZTM0NjRkYWQ4YmQ1OC0xNjUyNTYzNC0yMDczNjAwLTE4YzFmNzExODMxMjZhNyJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%7D; sajssdk_2015_cross_new_user=1; csrftoken=kWczx89mCJgThyBIBlOitizxRIH7Tuef; sessionid=byzyzsb66yxmrf0vy702ap05mm88i74d; user_role=-1; classroomId=14037619; classroom_id=14037619; JG_fcdf8e635093adde6bef42651_PV=1701342457656|1701342457656',
        'pragma': 'no-cache',
        'referer': 'https://changjiang.yuketang.cn/v2/web/studentLog/14037619',
        'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'university-id': '2868',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
        'uv-id': '2868',
        'x-csrftoken': 'kWczx89mCJgThyBIBlOitizxRIH7Tuef',
        'xt-agent': 'web',
        'xtbz': 'ykt',
    }
    response = requests.get(
        'https://changjiang.yuketang.cn/c27/online_courseware/xty/kls/pub_news/'+id+'/',
        cookies=cookies,
        headers=headers,
    )
    return response.text


def coursePageInfo(course_id, id):

    headers = {
        'authority': 'changjiang.yuketang.cn',
        'accept': 'application/json, text/plain, */*',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'no-cache',
        'classroom-id': '14037619',
        # 'cookie': 'django_language=zh-cn; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThjMWY3MTE4MzAxNmQ2LTBjZTM0NjRkYWQ4YmQ1OC0xNjUyNTYzNC0yMDczNjAwLTE4YzFmNzExODMxMjZhNyJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%7D; sajssdk_2015_cross_new_user=1; csrftoken=kWczx89mCJgThyBIBlOitizxRIH7Tuef; sessionid=byzyzsb66yxmrf0vy702ap05mm88i74d; user_role=-1; classroomId=14037619; classroom_id=14037619; JG_fcdf8e635093adde6bef42651_PV=1701342457656|1701342457656',
        'pragma': 'no-cache',
        'referer': 'https://changjiang.yuketang.cn/v2/web/xcloud/video-student/14037619/18867446',
        'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'university-id': '2868',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
        'uv-id': '2868',
        'xt-agent': 'web',
        'xtbz': 'ykt',
    }
    response = requests.get(
        'https://changjiang.yuketang.cn/mooc-api/v1/lms/learn/leaf_info/'+str(course_id)+'/'+str(id)+'/',
        cookies=cookies,
        headers=headers,
    )

    return response.text


def is_course_success(course_id, user_id, classroom_id, video_id):


    headers = {
        'authority': 'changjiang.yuketang.cn',
        'accept': 'application/json, text/plain, */*',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'no-cache',
        'classroom-id': '14037619',
        # 'cookie': 'django_language=zh-cn; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThjMWY3MTE4MzAxNmQ2LTBjZTM0NjRkYWQ4YmQ1OC0xNjUyNTYzNC0yMDczNjAwLTE4YzFmNzExODMxMjZhNyJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%7D; csrftoken=kWczx89mCJgThyBIBlOitizxRIH7Tuef; sessionid=byzyzsb66yxmrf0vy702ap05mm88i74d; user_role=-1; classroomId=14037619; classroom_id=14037619; JG_fcdf8e635093adde6bef42651_PV=1701342457656|1701342457656',
        'pragma': 'no-cache',
        'referer': 'https://changjiang.yuketang.cn/v2/web/xcloud/video-student/14037619/18867444',
        'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'university-id': '2868',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
        'uv-id': '2868',
        'xt-agent': 'web',
        'xtbz': 'ykt',
    }

    params = {
        'cid': course_id,
        'user_id': user_id,
        'classroom_id': classroom_id,
        'video_type': 'video',
        'vtype': 'rate',
        'video_id': video_id,
        'snapshot': '1',
    }

    response = requests.get(
        'https://changjiang.yuketang.cn/video-log/get_video_watch_progress/',
        params=params,
        cookies=cookies,
        headers=headers,
    )

    return response.text


def shuake(duration, videoTime, u, c,v,skuid,classroomid,cc, pg):
    headers = {
        'authority': 'changjiang.yuketang.cn',
        'accept': '*/*',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'no-cache',
        'classroom-id': '14037619',
        'content-type': 'application/json',
        # 'cookie': 'django_language=zh-cn; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThjMWY3MTE4MzAxNmQ2LTBjZTM0NjRkYWQ4YmQ1OC0xNjUyNTYzNC0yMDczNjAwLTE4YzFmNzExODMxMjZhNyJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218c1f71183016d6-0ce3464dad8bd58-16525634-2073600-18c1f71183126a7%22%7D; sajssdk_2015_cross_new_user=1; csrftoken=kWczx89mCJgThyBIBlOitizxRIH7Tuef; sessionid=byzyzsb66yxmrf0vy702ap05mm88i74d; user_role=-1; classroomId=14037619; classroom_id=14037619; JG_fcdf8e635093adde6bef42651_PV=1701342457656|1701342457656',
        'origin': 'https://changjiang.yuketang.cn',
        'pragma': 'no-cache',
        'referer': 'https://changjiang.yuketang.cn/v2/web/xcloud/video-student/14037619/18867447',
        'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
        'x-csrftoken': 'kWczx89mCJgThyBIBlOitizxRIH7Tuef',
        'x-requested-with': 'XMLHttpRequest',
        'xtbz': 'ykt',
    }
    json_data = {
        'heart_data': [
            {
                'i': 5,
                'et': 'playing',
                'p': 'web',
                'n': 'ali-cdn.xuetangx.com',
                'lob': 'ykt',
                'cp': videoTime,
                'fp': 0,
                'tp': videoTime,
                'sp': 1,
                'ts': int(time.time() * 1000),
                'u': u,
                'uip': '',
                'c': c,
                'v': v,
                'skuid': skuid,
                'classroomid': classroomid,
                'cc': cc,
                'd': duration,
                'pg': pg,
                'sq': 2,
                't': 'video',
                'cards_id': 0,
                'slide': 0,
                'v_url': '',
            }
        ]
    }

    response = requests.post('https://changjiang.yuketang.cn/video-log/heartbeat/', cookies=cookies, headers=headers, json=json_data)



if __name__ == '__main__':
    json_str = course_list()
    data = json.loads(json_str)
    course_lst= data['data']['list']
    ## 遍历课程 刷课
    for course_lst in course_lst:
        ## 获取课程id 全部刷
        course_id = course_lst['classroom_id']
        # 假设course_info()方法返回的是一个JSON字符串
        json_str = course_info(course_id)
        # 解析JSON字符串为Python对象
        data = json.loads(json_str)
        activities = data['data']['activities']
        # 遍历JSON对象
        for activity in activities:
            if 'type' in activity:
                type = activity['type']
                # 公告
                if type == 9:
                    print('这是一个公告')
                    pass
                # 期末测试
                elif type == 20:
                    print('这是期末测试')
                    pass
                elif type == 15:
                    # 全部单元Id
                    courseware_id = activity['courseware_id']
                    json_str = courseware(courseware_id)
                    data = json.loads(json_str)
                    content_info = data['data']['content_info']
                    for content_info in content_info:
                        print(content_info['name'])
                        for section_list in content_info['section_list']:
                            time.sleep(1)
                            randomStr = ''.join(random.choices('abcdefghijklmnopqrstuvwxyz0123456789', k=6))
                            courseChapterId = section_list['leaf_list'][0]['id']
                            # 注意这个位置 可能有的页面有多个任务而被忽略
                            video_name = section_list['name']
                            print(video_name, courseChapterId)

                            # 进入课程界面
                            json_str = coursePageInfo(course_id, courseChapterId)
                            data = json.loads(json_str)
                            videoInfo = data['data']
                            c = videoInfo['course_id']
                            cc = videoInfo['content_info']['media']['ccid']
                            classroomid = videoInfo['classroom_id']
                            # cp  播放时长

                            d = videoInfo['content_info']['media']['duration']
                            sku_id = videoInfo['sku_id']
                            pg = str(videoInfo['id']) + "_" + randomStr
                            v = videoInfo['id']
                            u = videoInfo['user_id']
                            progress = is_course_success(c, u, classroomid, v)
                            if_completed = '0'
                            try:
                                if_completed = re.search(r'"completed":(.+?),', progress).group(1)
                            except:
                                pass
                            if if_completed == '1':
                                print(video_name, '\033[31m学习完成,跳过\033[0m')
                                continue
                            else:
                                print(video_name + ",尚未学习,现在开始自动学习")

                                videoTime = 0
                                while True:
                                    if videoTime >= d:
                                        videoTime == d
                                        shuake(d, videoTime, u, c, v, sku_id, classroomid, cc, pg)
                                        print(video_name, '\033[31m学习完成\033[0m')
                                        break
                                        # 模拟每5秒递增5,实际应用时需要替换为实际的递增逻辑
                                    videoTime += 5
                                    # 判断当前播放时长是否超过视频总时长
                                    # 发送心跳请求
                                    shuake(d, videoTime, u, c, v, sku_id, classroomid, cc, pg)
                                    print('学习时长:', videoTime)
                                    time.sleep(5)
                else:
                    pass





0

评论 (0)

取消