{
  "apiVersion": 1,
  "identityFields": [],
  "id": "migu",
  "name": "Migu Video",
  "locales": {
    "zh-CN": {
      "name": "咪咕视频"
    }
  },
  "version": "0.5.1",
  "hosts": ["jadeite.migu.cn", "v3-sc.miguvideo.com", "webapi.miguvideo.com"],
  "search": {
    "inputs": ["q"],
    "steps": [
      {
        "type": "http",
        "id": "search",
        "request": {
          "method": "POST",
          "url": "'https://jadeite.migu.cn/search/v3/open-search'",
          "headers": {
            "Content-Type": "'application/json'",
            "appId": "'miguvideo'",
            "terminalId": "'www'"
          },
          "body": "{ 'k': q, 'pageIdx': 1, 'pageSize': 20, 'ct': 101, 'mediaSource': 9000000, 'appVersion': '6.1.1.00', 'isCorrectWord': 1, 'copyrightTerminal': 3, 'searchScene': 2, 'uiVersion': 'A3.26.0', 'packId': '1002581,1002601,1003861,1003862,1003863,1003864,1003865,1003866,1004041,1004121,1004261,1004262,1004281,1004321,1004262,1004281,1004322,1004261,1004421,1004422,1002781,1004301,1004641,1004761,1005061,1005261,1005301,1005321,1005361,1005362,1005341,1005342,1005521,1005722,1005721,1015749,1015761,1015760,1015762,1015763,1015768,1015786,1015790,1015812,1015813,1015814,1015815,1015816,1015817,1015820,1015819,1015821', 'sid': '1X4A395AL3XS3UV5MT8PQ1L5JUYK6KFM8VKDSDD48S5Y7YX5WY1MOUHRT6512988' }",
          "rewriteHeaders": {
            "Origin": "'https://www.miguvideo.com'",
            "Referer": "'https://www.miguvideo.com/'",
            "User-Agent": "'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36'"
          }
        }
      }
    ],
    "output": "($fromList := [search.body.contentInfoList.shortMediaAsset[isLong = 1 or isLong = true]]; $fromCluster := [search.body.mediaClusterInfo.mediaAssetList[isLong = 1 or isLong = true]]; [$append($fromList, $fromCluster).($sma := $; $eps := $exists($sma.extraData.episodes[0]) ? $sma.extraData.episodes[0] : $sma.pID; { 'providerIds': { 'epsId': $string($eps) }, 'indexedId': $string($eps), 'title': $sma.name, 'type': $sma.contDisplayName, 'typeDescription': $sma.contDisplayName, 'imageUrl': $sma.h5pics.highResolutionV, 'year': $exists($sma.year) and $trim($sma.year) != '' ? $number($trim($sma.year)) : null })])"
  },
  "episodes": {
    "inputs": ["epsId"],
    "steps": [
      {
        "type": "http",
        "id": "info",
        "request": {
          "method": "GET",
          "url": "'https://v3-sc.miguvideo.com/program/v4/cont/content-info/' & $string(epsId) & '/1'",
          "rewriteHeaders": {
            "User-Agent": "'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36'"
          }
        }
      },
      {
        "type": "assign",
        "id": "picked",
        "values": {
          "items": "$exists(info.body.data.datas) ? info.body.data.datas : ($exists(info.body.data.playing.pID) ? [{ 'pID': info.body.data.playing.pID, 'name': info.body.data.name, 'episodeNumber': '1' }] : [])"
        }
      }
    ],
    "output": "($epsIdStr := $string(epsId); [picked.items.{ 'providerIds': { 'epsId': $epsIdStr, 'pId': $string(pID) }, 'indexedId': $string(pID), 'title': name, 'episodeNumber': $exists(episodeNumber) ? episodeNumber : undefined }])"
  },
  "danmaku": {
    "inputs": ["epsId", "pId"],
    "steps": [
      {
        "type": "http",
        "id": "info",
        "request": {
          "method": "GET",
          "url": "'https://v3-sc.miguvideo.com/program/v4/cont/content-info/' & $string(pId) & '/1'",
          "rewriteHeaders": {
            "User-Agent": "'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36'"
          }
        }
      },
      {
        "type": "assign",
        "id": "plan",
        "values": {
          "duration": "$timeToSeconds($string(info.body.data.playing.duration))",
          "segCount": "$ceil($timeToSeconds($string(info.body.data.playing.duration)) / 30)"
        }
      },
      {
        "type": "forEach",
        "id": "segments",
        "in": "$range(0, plan.segCount)",
        "as": "i",
        "concurrency": 4,
        "throttleMs": 50,
        "request": {
          "method": "GET",
          "url": "'https://webapi.miguvideo.com/gateway/live_barrage/videox/barrage/v2/list/' & $string(epsId) & '/' & $string(pId) & '/' & $string(i * 30) & '/' & $string((i + 1) * 30 < plan.duration ? (i + 1) * 30 : plan.duration) & '/020'",
          "format": "text",
          "headers": {
            "appCode": "'miguvideo_default_h5'"
          },
          "rewriteHeaders": {
            "User-Agent": "'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36'"
          }
        },
        "extract": {
          "comments": "($decoded := $jsonParse($gatewayDecrypt($, 'vwwLu7e6ug4HAQMAug8CsA8HD7oHDwuxAg4HAQG6DLA=')); $exists($decoded.body.result) ? $decoded.body.result : [])"
        },
        "collect": "comments"
      }
    ],
    "output": "[segments.{ 'cid': $number(cid), 'p': $string(playtime) & ',1,' & $string($exists(textcolor) and textcolor != '' ? ($h := $hexToInt($replace($string(textcolor), '#', '')); $h >= 0 ? $h : 16777215) : 16777215), 'm': msg }]"
  }
}
