import axios from "axios"; import { v4 as uuidv4 } from "uuid"; import {makeUID}…
- User
User: import axios from "axios"; import { v4 as uuidv4 } from "uuid"; import {makeUID} from "./utils.js"; const args = process.argv.slice(2);
const count = args[0]; const id = args[1];
export const eventTypeEnum = Object.freeze({ watchStarted: 'WATCH_STARTED', watchEnded: 'WATCH_ENDED', watchResumed: 'WATCH_RESUMED', watchContinued: 'WATCH_CONTINUED', watchPaused: 'WATCH_PAUSED', })
function instance ({ deviceId, nnbId, channelId, liveId, eventType, sessionId, positionAt }) { const data = { "channelId": channelId, "liveId": liveId, "payload": { "watchEventType": eventType, "sessionId": sessionId, "duration": 30, "positionAt": positionAt }, "liveTokens": [], "autoPlay": false }
const send = async () => { return axios.post(`https://api.chzzk.naver.com/polling/v1/watch-event/live`, data, { headers: { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', 'deviceid': deviceId, 'Cookie': `ba.uuid=${deviceId};` + (nnbId ? ` NNB=${nnbId}` : ''), 'origin': `https://chzzk.naver.com`, 'priority': `u=1, i`, 'content-type': 'application/json', 'accept': 'application/json, text/plain, */*', 'front-client-platform-type': 'PC' } }) } return { send }}
async function init() { const seulTimeGMT = 'GMT+09:00'
const channelId = id const onlineInfo = true if(onlineInfo) { setInterval(async () => { const liveDetail = await axios.get(`https://api.chzzk.naver.com/service/v3/channels/${channelId}/live-detail`, { headers: { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' } }) console.log('online', liveDetail.data.content.concurrentUserCount) }, 2000) } const liveDetail = await axios.get(`https://api.chzzk.naver.com/service/v3/channels/${channelId}/live-detail`, { headers: { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' } }) const liveDetailContent = liveDetail.data.content const getLiveDuration = () => Math.floor((new Date().getTime() - new Date(`${liveDetailContent.openDate} ${seulTimeGMT}`).getTime()) / 1000) const onlineCount = count const handlerArray = [] for(let i=0; i < onlineCount; i++) { const { send } = instance({ liveId: liveDetailContent.liveId, deviceId: uuidv4(), sessionId: uuidv4(), nnbId: makeUID(13).toUpperCase(), positionAt: getLiveDuration(), eventType: eventTypeEnum.watchContinued, channelId }) handlerArray.push(send) } let iteration = 0 const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); while (true) { iteration++; console.log(iteration); let runInstance = 0; // Перебор всех задач в handlerArray for (let x = 0; x < handlerArray.length; x++) { // Ожидаем, если runInstance больше 5 while (runInstance >= 5) { await new Promise(resolve => { setTimeout(resolve, 1000); // Задержка 1 секунда перед повторной проверкой }); } runInstance++; // Увеличиваем счетчик запущенных задач // Обрабатываем текущую задачу handlerArray[x]() .catch((error) => { console.log('handle error', x, error); }) .finally(() => { --runInstance; // Уменьшаем счетчик по завершению задачи }); } // Пауза в 20 секунд после завершения всех задач в handlerArray await delay(20000); }}
init() .catch(error => console.log('init error', error))
найди различия с этим
import axios from "axios"; import { v4 as uuidv4 } from "uuid"; import {makeUID} from "./utils.js"; const args = process.argv.slice(2);
const count = args[0]; const id = args[1];
export const eventTypeEnum = Object.freeze({ watchStarted: 'WATCH_STARTED', watchEnded: 'WATCH_ENDED', watchResumed: 'WATCH_RESUMED', watchContinued: 'WATCH_CONTINUED', watchPaused: 'WATCH_PAUSED', })
function instance ({ deviceId, nnbId, channelId, liveId, eventType, sessionId, positionAt }) { const data = { "channelId": channelId, "liveId": liveId, "payload": { "watchEventType": eventType, "sessionId": sessionId, "duration": 30, "positionAt": positionAt }, "liveTokens": [], "autoPlay": false }
const send = async () => { return axios.post(`https://api.chzzk.naver.com/polling/v1/watch-event/live`, data, { headers: { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', 'deviceid': deviceId, 'Cookie': `ba.uuid=${deviceId};` + (nnbId ? ` NNB=${nnbId}` : ''), 'origin': `https://chzzk.naver.com`, 'priority': `u=1, i`, 'content-type': 'application/json', 'accept': 'application/json, text/plain, */*', 'front-client-platform-type': 'PC' } }) } return { send }}
async function init() { const seulTimeGMT = 'GMT+09:00'
const channelId = id const onlineInfo = true if(onlineInfo) { setInterval(async () => { const liveDetail = await axios.get(`https://api.chzzk.naver.com/service/v3/channels/${channelId}/live-detail`, { headers: { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' } }) console.log('online', liveDetail.data.content.concurrentUserCount) }, 2000) } const liveDetail = await axios.get(`https://api.chzzk.naver.com/service/v3/channels/${channelId}/live-detail`, { headers: { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' } }) const liveDetailContent = liveDetail.data.content const getLiveDuration = () => Math.floor((new Date().getTime() - new Date(`${liveDetailContent.openDate} ${seulTimeGMT}`).getTime()) / 1000) const onlineCount = count const handlerArray = [] for(let i=0; i < onlineCount; i++) { const { send } = instance({ liveId: liveDetailContent.liveId, deviceId: uuidv4(), sessionId: uuidv4(), nnbId: makeUID(13).toUpperCase(), positionAt: getLiveDuration(), eventType: eventTypeEnum.watchContinued, channelId }) handlerArray.push(send) } let iteration = 0 const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); while (true) { iteration++; console.log(iteration); let runInstance = 0; // Перебор всех задач в handlerArray for (let x = 0; x < handlerArray.length; x++) { // Ожидаем, если runInstance больше 5 while (runInstance >= 5) { await new Promise(resolve => { setTimeout(resolve, 1000); // Задержка 1 секунда перед повторной проверкой }); } runInstance++; // Увеличиваем счетчик запущенных задач // Обрабатываем текущую задачу handlerArray[x]() .catch((error) => { console.log('handle error', x, error); }) .finally(() => { --runInstance; // Уменьшаем счетчик по завершению задачи }); } // Пауза в 20 секунд после завершения всех задач в handlerArray await delay(20000); }}
init() .catch(error => console.log('init error', error)) Assistant: two code snippets you provided appear to be identical in terms of functionality and structure. However, without access to the specific differences in the text, I can summarize what makes them the same and confirm that there are no visible differences in code flow, syntax, or logic.
User: переведи ответ на русский Assistant:
- Assistant