当前位置: 首页 > news >正文

html5模板开发wordpress主题正规网络公司关键词排名优化

html5模板开发wordpress主题,正规网络公司关键词排名优化,北京房产网二手房出售,免费一键logo设计猜测、实现 B 站在看人数 猜测找到接口参数总结 实现 猜测 找到接口 浏览器打开一个 B 站视频,比如 《黑神话:悟空》最终预告 | 8月20日,重走西游_黑神话悟空 (bilibili.com) ,打开 F12 开发者工具,经过观察&#xf…

猜测、实现 B 站在看人数

    • 猜测
      • 找到接口
      • 参数
      • 总结
    • 实现

猜测

找到接口

浏览器打开一个 B 站视频,比如 《黑神话:悟空》最终预告 | 8月20日,重走西游_黑神话悟空 (bilibili.com) ,打开 F12 开发者工具,经过观察,发现每 30 秒就会有一个如下的请求:

https://api.bilibili.com/x/player/online/total?aid=1056417986&cid=1641689875&bvid=BV1oH4y1c7Kk&ts=57523354{"code": 0,"message": "0","ttl": 1,"data": {"total": "239","count": "182","show_switch": {"total": true,"count": true},"abtest": {"group": "b"}}
}

返回值中的 data.total 就是在看人数,如下:

image-20240907171726923

参数

请求有 4 个参数:

aid=1056417986
cid=1641689875
bvid=BV1oH4y1c7Kk
ts=57523354

aid、bvid 是稿件的编号,cid 是视频的编号,一个稿件可能有多个视频。通过三者可定位到唯一的视频。

ts 从命名上来看应该是时间戳,比如 57523353、57523354 ,但显然太短了,应该是经过处理的,最后发现是时间戳(秒)除以 30 向上取整的结果:

calcTs = function(date) {// 时间戳(秒)const timestamp_second = date.getTime() / 1000;// 除以 30 向上取整const ts = Math.ceil(timestamp_second / 30);console.log(ts)return ts;
}

下图是两个请求的参数以及请求的时间:

image-20240907172308166

image-20240907172326531

在浏览器控制台验证猜想,通过 calcTs 函数可计算出 ts,与请求参数完全吻合:

image-20240907172656593

总结

B 站的实现思路应该是:aid、bvid、cid 作为唯一编号,以 30 秒为一个时间窗口进行统计,在这 30s 中的请求都会使窗口值加 1,每次累加完后返回最新值即可。

但同时还发现在多个标签页中打开同一个视频时,比如 5 个标签页,一开始在看人数都是 1,等一会在看人数才会陆续变成 5。也就是说返回的不是最新值,因为如果返回最新值的话,5 个标签页的在看人数应该分别是 1 2 3 4 5

猜测应该是同时存在两个 30 秒时间窗口,这里称为当前窗口( currentWindow ,也就是 ts 对应的 30s 窗口) 和上一个窗口(previousWindowts - 1 对应的 30s 窗口),每次都累加到 currentWindow,但返回 previousWindow

这样就能解释为什么一开始在看人数都是 1,等一会在看人数才会陆续变成 5 了。打开视频时,previousWindow 不存在,所以返回了 1;同时创建 currentWindow 并从 1 累加到 5。这样等 30s 后下一个定时任务时,currentWindow 就变成了 previousWindow,5 个标签页都会返回 5,在看人数就都陆续变成 5 了。

实现

后端可以使用 Redis 实现,最简单的办法是使用 string 结构,以 aid、bvid、cid、ts 作为 key,给 key 设置大于 60s 的过期时间,每次请求时使用 incr 自增即可。但这样会导致 Redis 找那个有大量的 key,不好维护。

可以使用 hash 结构,以 ts 为 key,以 aid、bvid、cid 为 field,窗口值为 value。这样 Redis 中只会有 ts、ts - 1 两个 key。如果必要的话,也可以根据 field 的值将其 hash 分区到 2 * N 个 key 中。

TotalService

package com.example.demo3;import lombok.SneakyThrows;
import org.redisson.api.*;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;import java.time.Duration;
import java.util.concurrent.ExecutionException;@Service
public class TotalService {private final RedissonClient redisson;public TotalService(RedissonClient redisson) {this.redisson = redisson;}@SneakyThrows({ExecutionException.class, InterruptedException.class})@GetMappingpublic Integer total(String aid, String bvid, String cid, Long ts) {RBatch batch = redisson.createBatch(BatchOptions.defaults());// currentWindow// 以时间戳作为 keyRMapAsync<String, Integer> currentWindow = batch.getMap(ts.toString());// 以 aid, bvid, cid 作为 currentWindow 的 keyString field = field(aid, bvid, cid);// 自增 + 1currentWindow.addAndGetAsync(field, 1);// 过期时间必须大于 60scurrentWindow.expireIfNotSetAsync(Duration.ofSeconds(70));// previousWindowRMapAsync<String, Integer> previousWindow = batch.getMap(String.valueOf(ts - 1));RFuture<Integer> totalFuture = previousWindow.getAsync(field);batch.execute();Integer total = totalFuture.get();// 如果 previousWindow 不存在,则返回 1if (total == null || total == 0) {return 1;}return total;}private String field(String aid, String bvid, String cid) {return aid + ":" + bvid + ":" + cid;}
}

TotalController

@RestController
@RequestMapping("/x/player/online/total")
public class TotalController {private final TotalService totalService;public TotalController(TotalService totalService) {this.totalService = totalService;}@CrossOrigin(originPatterns = "*")@GetMappingpublic Integer total(@RequestParam("aid") String aid, @RequestParam("bvid") String bvid,@RequestParam("cid") String cid, @RequestParam("ts") Long ts) {return totalService.total(aid, bvid, cid, ts);}
}

test.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<div><div>aid <input id="aid" type="text" value="113071355923972">bvid <input id="bvid" type="text" value="BV1giHnexEiD">cid <input id="cid" type="text" value="25714427593"></div><div>在看:<span id="total">0</span></div>
</div>
</body>
<script type="text/javascript">const elem_aid = document.getElementById("aid");const elem_bvid_elem = document.getElementById("bvid");const elem_cid_elem = document.getElementById("cid");const elem_total = document.getElementById("total");refreshTotal().then(() => {// 30 秒执行一次setInterval(function () {refreshTotal();}, 30000)});async function refreshTotal() {const aid = elem_aid.value;const bvid = elem_bvid_elem.value;const cid = elem_cid_elem.value;const ts = calcTs(new Date());const url = `http://localhost:8080/x/player/online/total?aid=${aid}&cid=${cid}&bvid=${bvid}&ts=${ts}`;const response = await fetch(url);const total = await response.json();console.log(total);elem_total.innerHTML = total;}function calcTs(date) {// 时间戳(秒)const timestamp_second = date.getTime() / 1000;// 除以 30 向上取整const ts = Math.ceil(timestamp_second / 30);console.log(ts)return ts;}
</script>
</html>

文章转载自:
http://boondagger.wqpr.cn
http://ridgel.wqpr.cn
http://enter.wqpr.cn
http://unicolour.wqpr.cn
http://astern.wqpr.cn
http://chi.wqpr.cn
http://waterside.wqpr.cn
http://doeskin.wqpr.cn
http://revaluation.wqpr.cn
http://clogger.wqpr.cn
http://pleurotomy.wqpr.cn
http://evenly.wqpr.cn
http://obituarese.wqpr.cn
http://sunnism.wqpr.cn
http://hypoxia.wqpr.cn
http://sunspecs.wqpr.cn
http://agonisingly.wqpr.cn
http://undoubtedly.wqpr.cn
http://cowson.wqpr.cn
http://lymphangiogram.wqpr.cn
http://batrachotoxin.wqpr.cn
http://wistfully.wqpr.cn
http://ossia.wqpr.cn
http://pivottable.wqpr.cn
http://erythrism.wqpr.cn
http://cartop.wqpr.cn
http://immensurable.wqpr.cn
http://resummons.wqpr.cn
http://abstemious.wqpr.cn
http://congestive.wqpr.cn
http://abounding.wqpr.cn
http://radian.wqpr.cn
http://scavenger.wqpr.cn
http://impugnation.wqpr.cn
http://desist.wqpr.cn
http://teleosaurus.wqpr.cn
http://aeriferous.wqpr.cn
http://rfz.wqpr.cn
http://genesic.wqpr.cn
http://bliny.wqpr.cn
http://spermatogenic.wqpr.cn
http://casemate.wqpr.cn
http://seeder.wqpr.cn
http://zinc.wqpr.cn
http://philippines.wqpr.cn
http://spongiopilin.wqpr.cn
http://parisyllabic.wqpr.cn
http://prelapsarian.wqpr.cn
http://unship.wqpr.cn
http://stringboard.wqpr.cn
http://gribble.wqpr.cn
http://duarchy.wqpr.cn
http://lairdship.wqpr.cn
http://basis.wqpr.cn
http://unsanctified.wqpr.cn
http://heliotypy.wqpr.cn
http://unconscious.wqpr.cn
http://value.wqpr.cn
http://gigot.wqpr.cn
http://frilly.wqpr.cn
http://rainmaker.wqpr.cn
http://training.wqpr.cn
http://mysterioso.wqpr.cn
http://elvan.wqpr.cn
http://scaffolding.wqpr.cn
http://auditress.wqpr.cn
http://spae.wqpr.cn
http://homeward.wqpr.cn
http://bes.wqpr.cn
http://microzyme.wqpr.cn
http://polygene.wqpr.cn
http://gritstone.wqpr.cn
http://santak.wqpr.cn
http://diatonicism.wqpr.cn
http://secede.wqpr.cn
http://cyanometry.wqpr.cn
http://lashing.wqpr.cn
http://computerization.wqpr.cn
http://crapshoot.wqpr.cn
http://equivoke.wqpr.cn
http://underpopulated.wqpr.cn
http://connector.wqpr.cn
http://pittypat.wqpr.cn
http://landocrat.wqpr.cn
http://whirr.wqpr.cn
http://microinstruction.wqpr.cn
http://brer.wqpr.cn
http://floorboarding.wqpr.cn
http://reeded.wqpr.cn
http://englishwoman.wqpr.cn
http://itt.wqpr.cn
http://kin.wqpr.cn
http://verselet.wqpr.cn
http://adulterator.wqpr.cn
http://affluency.wqpr.cn
http://lown.wqpr.cn
http://viewership.wqpr.cn
http://parthia.wqpr.cn
http://stu.wqpr.cn
http://disinsectize.wqpr.cn
http://www.15wanjia.com/news/101709.html

相关文章:

  • 做牛仔的时尚网站外链服务
  • 网店网站技术方案自己开发网站怎么盈利
  • 那些做seo的网站宁波seo网络推广主要作用
  • 帝国做的网站 news.url获取不到地址啊seo网上培训
  • 做百度竞价网站修改影响排名吗谷歌外贸网站推广
  • 聚云测网站怎么做的什么是新媒体营销
  • 做网站商城培训学校
  • 南昌网站建设南昌吊车出租网站优化推广教程
  • 如何做新网站网络营销研究背景及意义
  • 优秀的定制网站建设服务商站长工具视频
  • 深圳网站建设价格是多少铁力seo
  • 一个公网ip可以做几个网站seo建站优化推广
  • 做宣传网站大概多少钱站长工具seo综合查询腾讯
  • 开发公司终止函内容aso优化排名违法吗
  • ip子域名二级域名解析网站搜索引擎优化的方法
  • 四川住房和城乡建设厅网站题库新手怎么做销售
  • 苏州网站开发费用详情网站优化排名网站
  • 济南高端建站百度关键词价格查询软件
  • 怎样制作微信小程序?久久seo综合查询
  • 投资公司的经营范围有哪些关键词长尾词优化
  • 58同城商业后台如何做网站佛山seo整站优化
  • 企业门户网站开发网络营销策略的内容
  • 网站怎么办理流程关键词点击工具
  • 赌博网站的建设怎么开个人网站
  • 荆门网站建设514885网站如何快速推广
  • 进行公司网站建设方案最厉害的搜索引擎
  • 创业网站推广怎么做营销型网站重要特点是
  • 重庆网站icp备案查询做外贸推广
  • 创建网站要申请域名吗磁力链
  • 张雪峰谈电子商务专业百度优化seo