{
  "apiVersion": 1,
  "identityFields": [],
  "id": "sohu",
  "name": "Sohu",
  "locales": {
    "zh-CN": {
      "name": "搜狐视频"
    }
  },
  "version": "0.5.0",
  "hosts": ["m.so.tv.sohu.com", "api.tv.sohu.com", "api.danmu.tv.sohu.com"],
  "search": {
    "inputs": ["q"],
    "steps": [
      {
        "type": "http",
        "id": "search",
        "request": {
          "method": "GET",
          "url": "'https://m.so.tv.sohu.com/search/pc/keyword'",
          "query": "{ 'key': q, 'type': '1', 'page': '1', 'page_size': '20', 'tabsChosen': '0', 'poster': '4', 'tuple': '6', 'extSource': '1', 'show_star_detail': '3', 'pay': '1', 'hl': '3', 'uid': $string($millis() * 1000), 'plat': '-1', 'ssl': '0' }",
          "rewriteHeaders": {
            "Referer": "'https://so.tv.sohu.com/'",
            "Origin": "'https://so.tv.sohu.com'"
          }
        }
      }
    ],
    "output": "[search.data.items[aid and album_name and site = 1 and (is_trailer ? is_trailer != 1 : true) and (corner_mark.text ? corner_mark.text != '预告' : true)].($metaTxt := [meta.txt][$contains($, '|')][0]; $type := $metaTxt ? $trim($split($metaTxt, '|')[0]) : 'Sohu'; { 'providerIds': { 'aid': $string(aid) }, 'indexedId': $string(aid), 'title': $replace(album_name, /<<<|>>>/, ''), 'type': $type, 'year': year ? $number(year) : undefined, 'imageUrl': ver_big_pic, 'episodeCount': total_video_count > 0 ? total_video_count : undefined })]"
  },
  "episodes": {
    "inputs": ["aid"],
    "steps": [
      {
        "type": "http",
        "id": "album",
        "request": {
          "method": "GET",
          "url": "'https://api.tv.sohu.com/v4/album/videos/' & aid & '.json'",
          "query": "{ 'page': '1', 'page_size': '500' }",
          "rewriteHeaders": { "Referer": "'https://tv.sohu.com/'" }
        }
      }
    ],
    "output": "[album.data.videos[$exists(vid)].{ 'providerIds': { 'vid': $string(vid), 'aid': $string(aid), 'durationSec': total_duration > 0 ? $number(total_duration) : 0 }, 'indexedId': $string(vid), 'title': video_name ? video_name : ('第' & $string(albumAbsoluteOrder ? albumAbsoluteOrder : 1) & '集'), 'episodeNumber': albumAbsoluteOrder ? $number(albumAbsoluteOrder) : undefined }]"
  },
  "danmaku": {
    "inputs": ["vid", "aid", "durationSec"],
    "steps": [
      {
        "type": "assign",
        "id": "info",
        "values": {
          "maxTime": "durationSec > 0 ? $ceil(durationSec) : 10800"
        }
      },
      {
        "type": "forEach",
        "id": "segments",
        "in": "$range(0, $ceil(info.maxTime / 300))",
        "as": "i",
        "concurrency": 5,
        "throttleMs": 50,
        "request": {
          "method": "GET",
          "url": "'https://api.danmu.tv.sohu.com/dmh5/dmListAll'",
          "query": "{ 'act': 'dmlist_v2', 'vid': vid, 'aid': aid, 'pct': '2', 'time_begin': $string(i * 300), 'time_end': $string((i + 1) * 300), 'dct': '1', 'request_from': 'h5_js' }",
          "rewriteHeaders": { "Referer": "'https://tv.sohu.com/'" }
        },
        "collect": "info.comments"
      }
    ],
    "output": "[segments.($cr := $string(t.c ? t.c : '16777215'); $color := $contains($cr, '#') ? $hexToInt($replace($cr, '#', '')) : $number($cr); $vt := v ? $string(v) : '0'; { 'p': $vt & ',1,' & $string($color) & ',' & (uid ? $string(uid) : ''), 'm': c })]"
  }
}
