{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2a7325f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "from requests import get,post"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c3269f62",
   "metadata": {},
   "outputs": [],
   "source": [
    "from api import randomPic,getShi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "514bb722",
   "metadata": {},
   "outputs": [],
   "source": [
    "token=\"Bearer f8bdd800-c1d5-4865-901c-0b52925462d6\"\n",
    "headers={\n",
    "    \"Authorization\":token,\n",
    "}\n",
    "ip = \"http://192.168.0.209:9999\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e6754edf",
   "metadata": {},
   "outputs": [],
   "source": [
    "from faker import Faker\n",
    "import random\n",
    "from datetime import datetime, timedelta\n",
    "import json\n",
    "\n",
    "# 初始化Faker，设置为中文环境\n",
    "fake = Faker('zh_CN')\n",
    "def getFengjing():\n",
    "    data = get(\"https://api.btstu.cn/sjbz/api.php?lx=fengjing&format=json\").json()[\"imgurl\"]\n",
    "    return data\n",
    "\n",
    "# ===================== 核心编码映射（对应Java枚举类） =====================\n",
    "# 学段编码：1=小学，2=初中，3=高中\n",
    "EDUCATION_STAGE_MAP = {\n",
    "    1: \"小学\",\n",
    "    2: \"初中\",\n",
    "    3: \"高中\"\n",
    "}\n",
    "# 年级编码：按学段分组，保证逻辑关联\n",
    "GRADE_MAP = {\n",
    "    1: [101, 102, 103, 104, 105, 106],  # 小学：一年级到六年级\n",
    "    2: [201, 202, 203],                  # 初中：初一到初三\n",
    "    3: [301, 302, 303]                   # 高中：高一到高三\n",
    "}\n",
    "# 年级编码对应中文（可选，用于注释/调试）\n",
    "GRADE_NAME_MAP = {\n",
    "    101: \"一年级\", 102: \"二年级\", 103: \"三年级\", 104: \"四年级\", 105: \"五年级\", 106: \"六年级\",\n",
    "    201: \"初一\", 202: \"初二\", 203: \"初三\",\n",
    "    301: \"高一\", 302: \"高二\", 303: \"高三\"\n",
    "}\n",
    "# 学科编码：1=语文，2=数学，3=英语，4=物理，5=化学，6=生物，7=历史，8=地理，9=政治\n",
    "SUBJECT_MAP = {\n",
    "    1: \"语文\",\n",
    "    2: \"数学\",\n",
    "    3: \"英语\",\n",
    "    4: \"物理\",\n",
    "    5: \"化学\",\n",
    "    6: \"生物\",\n",
    "    7: \"历史\",\n",
    "    8: \"地理\",\n",
    "    9: \"政治\"\n",
    "}\n",
    "# 状态编码：0=草稿，1=发布，2=下架（保持不变）\n",
    "STATUS_LIST = [0, 1, 2]\n",
    "\n",
    "def generate_video_info(id_num: int) -> dict:\n",
    "    \"\"\"\n",
    "    生成单条视频信息模拟数据（数字编码版）\n",
    "    :param id_num: 用于生成唯一ID的序号\n",
    "    :return: 视频信息字典\n",
    "    \"\"\"\n",
    "    # 随机生成时间（近1年内）\n",
    "    start_date = datetime.now() - timedelta(days=365)\n",
    "    create_time = fake.date_time_between(start_date=start_date, end_date=\"now\")\n",
    "    update_time = create_time if random.random() < 0.3 else fake.date_time_between(start_date=create_time, end_date=\"now\")\n",
    "    \n",
    "    # 1. 随机选学段编码（1/2/3）\n",
    "    education_stage_code = random.choice(list(EDUCATION_STAGE_MAP.keys()))\n",
    "    # 2. 根据学段编码选对应年级编码（保证逻辑一致）\n",
    "    grade_code = random.choice(GRADE_MAP[education_stage_code])\n",
    "    # 3. 随机选学科编码（1-9）\n",
    "    subject_code = random.choice(list(SUBJECT_MAP.keys()))\n",
    "    \n",
    "    # 生成贴合场景的视频标题（用编码对应中文，让标题更易读）\n",
    "    grade_name = GRADE_NAME_MAP[grade_code]\n",
    "    subject_name = SUBJECT_MAP[subject_code]\n",
    "    title_prefix = [f\"{grade_name}{subject_name}\", f\"{subject_name}同步讲解\", f\"{subject_name}考点解析\", f\"{grade_name}{subject_name}易错点总结\"]\n",
    "    title = f\"{random.choice(title_prefix)}\"\n",
    "    randomPicUrl = getFengjing()\n",
    "    return {\n",
    "        \"title\": title,\n",
    "        \"coverUrl\": randomPicUrl,\n",
    "        \"videoUrl\": randomPicUrl,\n",
    "        \"categoryId\": random.randint(1, 50),  # 分类ID 1-50\n",
    "        \"teacherId\": random.randint(1000, 9999),  # 教师ID 1000-9999\n",
    "        \"subject\": subject_code,  # 学科编码（1-9）\n",
    "        \"grade\": grade_code,      # 年级编码（101/102...303）\n",
    "        \"educationStage\": education_stage_code,  # 学段编码（1/2/3）\n",
    "        \"description\": getShi()['content'],  # 5句左右的简介\n",
    "        \"duration\": random.randint(300, 3600),  # 时长5分钟到1小时（秒）\n",
    "        \"viewCount\": random.randint(0, 1000000),  # 播放量0-100万\n",
    "        \"likeCount\": random.randint(0, 100000),  # 点赞数0-10万\n",
    "        \"commentCount\": random.randint(0, 10000),  # 评论数0-1万\n",
    "        \"status\": random.choice(STATUS_LIST),\n",
    "        \"createTime\": create_time.strftime(\"%Y-%m-%d %H:%M:%S\"),  # 适配LocalDateTime格式\n",
    "        \"updateTime\": update_time.strftime(\"%Y-%m-%d %H:%M:%S\"),\n",
    "        \"videoUploadUrl\": f\"https://storage.example.com/videos/{fake.uuid4()}.mp4\",\n",
    "    }\n",
    "\n",
    "def generate_video_data(count: int) -> list:\n",
    "    \"\"\"\n",
    "    生成指定数量的视频模拟数据（数字编码版）\n",
    "    :param count: 生成数据的条数\n",
    "    :return: 视频数据列表\n",
    "    \"\"\"\n",
    "    video_list = []\n",
    "    for i in range(1, count + 1):\n",
    "        video_list.append(generate_video_info(i))\n",
    "    return video_list\n",
    "\n",
    "# if __name__ == \"__main__\":\n",
    "#     # 生成10条测试数据（可自行修改数量）\n",
    "#     video_data = generate_video_data(1)\n",
    "    \n",
    "#     # 打印编码映射说明（方便对照）\n",
    "#     print(\"===== 编码映射说明 =====\")\n",
    "#     print(f\"学段编码：{EDUCATION_STAGE_MAP}\")\n",
    "#     print(f\"年级编码：{GRADE_NAME_MAP}\")\n",
    "#     print(f\"学科编码：{SUBJECT_MAP}\")\n",
    "#     print(\"===== 生成的测试数据 =====\")\n",
    "    \n",
    "#     # 方式1：打印格式化后的JSON数据\n",
    "#     print(json.dumps(video_data, ensure_ascii=False, indent=4))\n",
    "    \n",
    "\n",
    "#     print(\"\\n数据已保存到 video_info_test_data_code.json 文件\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "442d43e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(10):\n",
    "    video_data = generate_video_data(1)\n",
    "    post(f\"{ip}/video/videoInfo\",headers=headers,json=video_data[0]).json()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca452761",
   "metadata": {},
   "outputs": [],
   "source": [
    "# post(f\"{ip}/api/video\",json=video_data[0])\n",
    "# video_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a001ddf8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': 0,\n",
       " 'msg': None,\n",
       " 'data': [{'id': '1',\n",
       "   'parentId': '0',\n",
       "   'weight': 1,\n",
       "   'name': '教研组',\n",
       "   'isLock': True,\n",
       "   'createTime': None,\n",
       "   'children': [{'id': '2',\n",
       "     'parentId': '1',\n",
       "     'weight': 1,\n",
       "     'name': '语文组',\n",
       "     'isLock': True,\n",
       "     'createTime': None}]},\n",
       "  {'id': '3',\n",
       "   'parentId': '0',\n",
       "   'weight': 1,\n",
       "   'name': '行政组',\n",
       "   'isLock': True,\n",
       "   'createTime': None}],\n",
       " 'ok': True}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get(f\"{ip}/admin/team-org/tree\",headers=headers).json()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38646bf1",
   "metadata": {},
   "outputs": [],
   "source": [
    "get(f\"{ip}/video/videoChapter/tree\",params={\n",
    "    \"subjectId\":\"15\",\n",
    "    \"deptId\":0,\n",
    "},headers=headers).json()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e2f1f1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "get(f\"{ip}/video/videoCourse/page\",headers=headers,params={\n",
    "    \"current\":1,\n",
    "    \"size\":10,\n",
    "}).json()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2a5c2fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "post(f\"{ip}/video/videoInfo\",headers=headers,json={\n",
    "    \"coverUrl\": \"/api/admin/sys-file/oss/file?fileName=d52e43ce433e44da91d248a5aecaf16e.png\",\n",
    "    \"description\": \"测试课程\",\n",
    "    \"gradeId\": \"102\",\n",
    "    \"stageId\": \"1\",\n",
    "    \"subjectId\": \"19\",\n",
    "    \"title\": \"ces\",\n",
    "\t\"videoUploadUrl\": \"http://192.168.0.244:9000/s3demo/video/live/522e4c55fc804decafdd0a62e5a1bf74.mp4\"\n",
    "}).text\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5d49311",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e00de37c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': 0,\n",
       " 'msg': None,\n",
       " 'data': 'http://192.168.0.244:9000/s3demo/video/couer/5ac9f3a8061a4eea938272ce0a34bb3b.png',\n",
       " 'ok': True}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "post(f\"{ip}/video/videoInfo/uploadImg\",headers=headers,files={\"file\":open(\"1.png\",\"rb\")}).json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "02944113",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"code\":0,\"msg\":\"成功\",\"data\":{\"app\":\"rtp\",\"stream\":\"34020000001320000002_34020000001320000002\",\"ip\":null,\"flv\":\"http://192.168.0.244:85/rtp/34020000001320000002_34020000001320000002.live.flv?originTypeStr=rtp_push\",\"https_flv\":\"https://192.168.0.244:443/rtp/34020000001320000002_34020000001320000002.live.flv?originTypeStr=rtp_push\",\"ws_flv\":\"ws://192.168.0.244:85/rtp/34020000001320000002_34020000001320000002.live.flv?originTypeStr=rtp_push\",\"wss_flv\":\"wss://192.168.0.244:443/rtp/34020000001320000002_34020000001320000002.live.flv?originTypeStr=rtp_push\",\"fmp4\":\"http://192.168.0.244:85/rtp/34020000001320000002_34020000001320000002.live.mp4?originTypeStr=rtp_push\",\"https_fmp4\":\"https://192.168.0.244:443/rtp/34020000001320000002_34020000001320000002.live.mp4?originTypeStr=rtp_push\",\"ws_fmp4\":\"ws://192.168.0.244:85/rtp/34020000001320000002_34020000001320000002.live.mp4?originTypeStr=rtp_push\",\"wss_fmp4\":\"wss://192.168.0.244:443/rtp/34020000001320000002_34020000001320000002.live.mp4?originTypeStr=rtp_push\",\"hls\":\"http://192.168.0.244:85/rtp/34020000001320000002_34020000001320000002/hls.m3u8?originTypeStr=rtp_push\",\"https_hls\":\"https://192.168.0.244:443/rtp/34020000001320000002_34020000001320000002/hls.m3u8?originTypeStr=rtp_push\",\"ws_hls\":\"ws://192.168.0.244:85/rtp/34020000001320000002_34020000001320000002/hls.m3u8?originTypeStr=rtp_push\",\"wss_hls\":\"wss://192.168.0.244:443/rtp/34020000001320000002_34020000001320000002/hls.m3u8?originTypeStr=rtp_push\",\"ts\":\"http://192.168.0.244:85/rtp/34020000001320000002_34020000001320000002.live.ts?originTypeStr=rtp_push\",\"https_ts\":\"https://192.168.0.244:443/rtp/34020000001320000002_34020000001320000002.live.ts?originTypeStr=rtp_push\",\"ws_ts\":\"ws://192.168.0.244:85/rtp/34020000001320000002_34020000001320000002.live.ts?originTypeStr=rtp_push\",\"wss_ts\":null,\"rtmp\":\"rtmp://192.168.0.244:1935/rtp/34020000001320000002_34020000001320000002?originTypeStr=rtp_push\",\"rtmps\":null,\"rtsp\":\"rtsp://192.168.0.244:554/rtp/34020000001320000002_34020000001320000002?originTypeStr=rtp_push\",\"rtsps\":null,\"rtc\":\"http://192.168.0.244:85/index/api/webrtc?app=rtp&stream=34020000001320000002_34020000001320000002&type=play&originTypeStr=rtp_push\",\"rtcs\":\"https://192.168.0.244:443/index/api/webrtc?app=rtp&stream=34020000001320000002_34020000001320000002&type=play&originTypeStr=rtp_push\",\"mediaServerId\":\"zlmediakit-local\",\"mediaInfo\":{\"app\":\"rtp\",\"stream\":\"34020000001320000002_34020000001320000002\",\"mediaServer\":{\"id\":\"zlmediakit-local\",\"ip\":\"192.168.0.244\",\"hookIp\":\"127.0.0.1\",\"sdpIp\":\"192.168.0.244\",\"streamIp\":\"192.168.0.244\",\"httpPort\":85,\"httpSSlPort\":443,\"rtmpPort\":1935,\"flvPort\":0,\"flvSSLPort\":443,\"mp4Port\":0,\"wsFlvPort\":0,\"wsFlvSSLPort\":443,\"rtmpSSlPort\":0,\"rtpProxyPort\":10000,\"jttProxyPort\":0,\"rtspPort\":554,\"rtspSSLPort\":0,\"autoConfig\":false,\"secret\":\"TWSYFgYJOQWB4ftgeYut8DW4wbs7pQnj\",\"hookAliveInterval\":10.0,\"rtpEnable\":true,\"status\":true,\"rtpPortRange\":\"40000,45000\",\"sendRtpPortRange\":\"50000,55000\",\"recordAssistPort\":0,\"createTime\":\"2026-01-04 17:59:07\",\"updateTime\":\"2026-03-04 14:45:29\",\"lastKeepaliveTime\":null,\"defaultServer\":true,\"recordDay\":7,\"recordPath\":\"\",\"type\":\"zlm\",\"transcodeSuffix\":null,\"serverId\":\"000000\"},\"schema\":\"rtsp\",\"readerCount\":0,\"videoCodec\":\"H264\",\"width\":1920,\"height\":1080,\"fps\":null,\"loss\":null,\"audioCodec\":null,\"audioChannels\":null,\"audioSampleRate\":null,\"duration\":null,\"online\":true,\"originType\":3,\"originTypeStr\":\"rtp_push\",\"originUrl\":\"rtp://__defaultVhost__/rtp/34020000001320000002_34020000001320000002\",\"aliveSecond\":0,\"bytesSpeed\":0,\"callId\":\"e6e72138756dfd276b888202879d70b1@192.168.0.244\",\"paramMap\":{},\"serverId\":\"000000\"},\"startTime\":null,\"endTime\":null,\"duration\":null,\"downLoadFilePath\":null,\"transcodeStream\":null,\"progress\":0.0,\"key\":null}}'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get(\"http://192.168.0.244:18081/api/common/channel/play?channelId=1\",headers={\"api-key\":\"eyJhbGciOiJSUzI1NiIsImtpZCI6IjNlNzk2NDZjNGRiYzQwODM4M2E5ZWVkMDlmMmI4NWFlIn0.eyJqdGkiOiIzRjFJQ2xhRzNscm9zVEdZTUlNanZRIiwiaWF0IjoxNzcyNjA1NzA5LCJuYmYiOjE3NzI2MDU3MDksInN1YiI6ImxvZ2luIiwiYXVkIjoiQXVkaWVuY2UiLCJ1c2VyTmFtZSI6ImFkbWluIiwiYXBpS2V5SWQiOjF9.YxFVDE6czLSqUZtLXnW7mWzkk0EG6lfHgJpykP_eZ_-COve8_tfLLRs_Gqip64EiGrAWTuw98TRToIzF2TKAqOHYD3XtaTlzcrCUWXHT-d70DYz9qniStrXimwIqeyuYKzgyweiGkkbmkn6y6SRrvGkQmGZWltHNLtp_Iy9DToBQr6adA8Jt23mGazZDueewJEofp54FeirB7Uorwb8XXFX-u9X33HbB3RIX5GS3AmOCchWOwhaBH4ZyeZDCJO7W1ziD_UPzzo4GG1GIc7sAnjGO0poGXs3-oCyBJ0gwsapJcSB6n-S8qW_JvIp7qk0GGo8KyBLE2ILRHX6BYULiww\"}).text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d040893",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
