@dan-uni/dan-any 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/browser/157.min.js +14 -0
  2. package/dist/browser/42.min.js +45 -0
  3. package/dist/{index.min.js → browser/index.min.js} +371 -1003
  4. package/dist/browser/plugins/bili-dedupe.min.js +1 -0
  5. package/dist/browser/plugins/index.min.js +1 -0
  6. package/dist/browser/rslib-runtime.min.js +49 -0
  7. package/dist/{src → browser/src}/index.d.ts +6 -6
  8. package/dist/browser/src/plugins/bili-dedupe/index.d.ts +5 -0
  9. package/dist/browser/src/plugins/index.d.ts +2 -0
  10. package/dist/{src → browser/src}/utils/dm-gen.d.ts +3 -3
  11. package/dist/browser/src/utils/dm-gen.test.d.ts +1 -0
  12. package/dist/node/157.js +14 -0
  13. package/dist/node/42.js +45 -0
  14. package/dist/{index.js → node/index.js} +275 -894
  15. package/dist/node/plugins/bili-dedupe.js +1 -0
  16. package/dist/node/plugins/index.js +1 -0
  17. package/dist/node/rslib-runtime.js +37 -0
  18. package/dist/node/src/ass-gen/__tests__/canvas.test.d.ts +1 -0
  19. package/dist/node/src/ass-gen/__tests__/generate.test.d.ts +1 -0
  20. package/dist/node/src/ass-gen/ass/create.d.ts +4 -0
  21. package/dist/node/src/ass-gen/ass/dialogue.d.ts +16 -0
  22. package/dist/node/src/ass-gen/ass/event.d.ts +2 -0
  23. package/dist/node/src/ass-gen/ass/info.d.ts +8 -0
  24. package/dist/node/src/ass-gen/ass/raw.d.ts +14 -0
  25. package/dist/node/src/ass-gen/ass/style.d.ts +2 -0
  26. package/dist/node/src/ass-gen/config.d.ts +2 -0
  27. package/dist/node/src/ass-gen/index.d.ts +30 -0
  28. package/dist/node/src/ass-gen/types.d.ts +71 -0
  29. package/dist/node/src/ass-gen/util/color.d.ts +18 -0
  30. package/dist/node/src/ass-gen/util/danconvert.d.ts +5 -0
  31. package/dist/node/src/ass-gen/util/index.d.ts +4 -0
  32. package/dist/node/src/ass-gen/util/lang.d.ts +3 -0
  33. package/dist/node/src/ass-gen/util/layout.d.ts +4 -0
  34. package/dist/node/src/index.d.ts +255 -0
  35. package/dist/node/src/index.test.d.ts +1 -0
  36. package/dist/node/src/plugins/bili-dedupe/index.d.ts +5 -0
  37. package/dist/node/src/plugins/bili-dedupe/index.test.d.ts +1 -0
  38. package/dist/node/src/plugins/index.d.ts +2 -0
  39. package/dist/node/src/proto/gen/bili/dm_pb.d.ts +3426 -0
  40. package/dist/node/src/proto/gen/danuni_pb.d.ts +172 -0
  41. package/dist/node/src/utils/dm-gen.d.ts +309 -0
  42. package/dist/node/src/utils/dm-gen.test.d.ts +1 -0
  43. package/dist/node/src/utils/id-gen.d.ts +50 -0
  44. package/dist/node/src/utils/platform.d.ts +24 -0
  45. package/dist/{index.umd.min.js → umd/index.umd.min.js} +452 -990
  46. package/dist/umd/plugins/bili-dedupe.umd.min.js +79 -0
  47. package/dist/umd/plugins/index.umd.min.js +98 -0
  48. package/dist/umd/src/ass-gen/__tests__/canvas.test.d.ts +1 -0
  49. package/dist/umd/src/ass-gen/__tests__/generate.test.d.ts +1 -0
  50. package/dist/umd/src/ass-gen/ass/create.d.ts +4 -0
  51. package/dist/umd/src/ass-gen/ass/dialogue.d.ts +16 -0
  52. package/dist/umd/src/ass-gen/ass/event.d.ts +2 -0
  53. package/dist/umd/src/ass-gen/ass/info.d.ts +8 -0
  54. package/dist/umd/src/ass-gen/ass/raw.d.ts +14 -0
  55. package/dist/umd/src/ass-gen/ass/style.d.ts +2 -0
  56. package/dist/umd/src/ass-gen/config.d.ts +2 -0
  57. package/dist/umd/src/ass-gen/index.d.ts +30 -0
  58. package/dist/umd/src/ass-gen/types.d.ts +71 -0
  59. package/dist/umd/src/ass-gen/util/color.d.ts +18 -0
  60. package/dist/umd/src/ass-gen/util/danconvert.d.ts +5 -0
  61. package/dist/umd/src/ass-gen/util/index.d.ts +4 -0
  62. package/dist/umd/src/ass-gen/util/lang.d.ts +3 -0
  63. package/dist/umd/src/ass-gen/util/layout.d.ts +4 -0
  64. package/dist/umd/src/index.d.ts +255 -0
  65. package/dist/umd/src/index.test.d.ts +1 -0
  66. package/dist/umd/src/plugins/bili-dedupe/index.d.ts +5 -0
  67. package/dist/umd/src/plugins/bili-dedupe/index.test.d.ts +1 -0
  68. package/dist/umd/src/plugins/index.d.ts +2 -0
  69. package/dist/umd/src/proto/gen/bili/dm_pb.d.ts +3426 -0
  70. package/dist/umd/src/proto/gen/danuni_pb.d.ts +172 -0
  71. package/dist/umd/src/utils/dm-gen.d.ts +309 -0
  72. package/dist/umd/src/utils/dm-gen.test.d.ts +1 -0
  73. package/dist/umd/src/utils/id-gen.d.ts +50 -0
  74. package/dist/umd/src/utils/platform.d.ts +24 -0
  75. package/package.json +22 -22
  76. package/plugins/package.json +6 -0
  77. package/rslib.config.ts +13 -3
  78. package/src/ass-gen/util/index.ts +2 -2
  79. package/src/index.ts +6 -6
  80. package/src/plugins/bili-dedupe/index.test.ts +40 -0
  81. package/src/plugins/bili-dedupe/index.ts +19 -0
  82. package/src/plugins/index.ts +3 -0
  83. package/src/proto/gen/bili/dm_pb.ts +1 -1
  84. package/src/proto/gen/danuni_pb.ts +1 -1
  85. package/src/utils/dm-gen.test.ts +2 -2
  86. package/src/utils/dm-gen.ts +30 -5
  87. package/dist/{index.min.js.LICENSE.txt → browser/index.min.js.LICENSE.txt} +0 -0
  88. package/dist/{src → browser/src}/ass-gen/__tests__/canvas.test.d.ts +0 -0
  89. package/dist/{src → browser/src}/ass-gen/__tests__/generate.test.d.ts +0 -0
  90. package/dist/{src → browser/src}/ass-gen/ass/create.d.ts +0 -0
  91. package/dist/{src → browser/src}/ass-gen/ass/dialogue.d.ts +0 -0
  92. package/dist/{src → browser/src}/ass-gen/ass/event.d.ts +0 -0
  93. package/dist/{src → browser/src}/ass-gen/ass/info.d.ts +0 -0
  94. package/dist/{src → browser/src}/ass-gen/ass/raw.d.ts +0 -0
  95. package/dist/{src → browser/src}/ass-gen/ass/style.d.ts +0 -0
  96. package/dist/{src → browser/src}/ass-gen/config.d.ts +0 -0
  97. package/dist/{src → browser/src}/ass-gen/index.d.ts +0 -0
  98. package/dist/{src → browser/src}/ass-gen/types.d.ts +0 -0
  99. package/dist/{src → browser/src}/ass-gen/util/color.d.ts +0 -0
  100. package/dist/{src → browser/src}/ass-gen/util/danconvert.d.ts +0 -0
  101. package/dist/{src → browser/src}/ass-gen/util/index.d.ts +2 -2
  102. /package/dist/{src → browser/src}/ass-gen/util/lang.d.ts +0 -0
  103. /package/dist/{src → browser/src}/ass-gen/util/layout.d.ts +0 -0
  104. /package/dist/{src → browser/src}/index.test.d.ts +0 -0
  105. /package/dist/{src/utils/dm-gen.test.d.ts → browser/src/plugins/bili-dedupe/index.test.d.ts} +0 -0
  106. /package/dist/{src → browser/src}/proto/gen/bili/dm_pb.d.ts +0 -0
  107. /package/dist/{src → browser/src}/proto/gen/danuni_pb.d.ts +0 -0
  108. /package/dist/{src → browser/src}/utils/id-gen.d.ts +0 -0
  109. /package/dist/{src → browser/src}/utils/platform.d.ts +0 -0
  110. /package/dist/{index.umd.min.js.LICENSE.txt → umd/index.umd.min.js.LICENSE.txt} +0 -0
package/src/index.ts CHANGED
@@ -47,7 +47,7 @@ interface DanUniConvertTip {
47
47
  export interface DM_XML_Bili {
48
48
  i: {
49
49
  chatserver: string
50
- chatid: number
50
+ chatid: bigint
51
51
  mission: number
52
52
  maxlimit: number
53
53
  state: number
@@ -78,15 +78,15 @@ export interface DM_JSON_BiliUp {
78
78
  }
79
79
  result: {
80
80
  /** 弹幕 ID,int64 */
81
- id: number
81
+ id: bigint
82
82
  /** 弹幕 ID 字符串形式 */
83
83
  id_str: string
84
84
  /** 弹幕类型:1 表示视频弹幕(当前接口恒为 1) */
85
85
  type: number
86
- aid: number
86
+ aid: bigint
87
87
  bvid: string
88
- oid: number
89
- mid: number
88
+ oid: bigint
89
+ mid: bigint
90
90
  /** 发送者 mid 的 CRC 哈希(正常接口里用的是这个,保护隐私) */
91
91
  mid_hash: string
92
92
  /** 弹幕池 */
@@ -145,7 +145,7 @@ export interface DM_JSON_Artplayer {
145
145
  export interface DM_JSON_DDPlay {
146
146
  count: number | string
147
147
  comments: {
148
- cid: number
148
+ cid: bigint
149
149
  p: string
150
150
  m: string
151
151
  }[]
@@ -0,0 +1,40 @@
1
+ //基于以下注释,根据vitest生成测试用例
2
+ import { describe, expect, it } from 'vitest'
3
+
4
+ import bili_dedupe from '.'
5
+ import { UniPool } from '../..'
6
+
7
+ const xml = `<i>
8
+ <chatserver>chat.bilibili.com</chatserver>
9
+ <chatid>1156756312</chatid>
10
+ <mission>0</mission>
11
+ <maxlimit>2947</maxlimit>
12
+ <state>0</state>
13
+ <real_name>0</real_name>
14
+ <source>k-v</source>
15
+ <d p="13.213,1,25,16777215,1686314041,3,ff41173d,1335658005672492032">喜欢</d>
16
+ <d p="13.213,1,25,16777215,1686590010,0,296b35b5,1337972999512832512">来了 哈哈~~</d>
17
+ <d p="13.246,1,25,16777215,1686276875,0,5664cfc4,1335346233459549696">就是</d>
18
+ <d p="13.266,1,25,16777215,1686283375,0,c7e6646f,1335400761013670912">什么鬼?</d>
19
+ <d p="13.284,1,25,16777215,1686291338,0,38662881,1335517923728804864">哇哦</d>
20
+ <d p="13.306,1,25,16777215,1686268410,0,4c01de10,1335275224983600896">试试</d>
21
+ <d p="13.331,1,25,16777215,1686948453,3,56a3c5d5,1340979831550069760">不喜欢</d>
22
+ <d p="13.374,1,25,16777215,1686300770,3,647fe355,1335546672880933888">不喜欢</d>
23
+ <d p="13.376,1,25,16777215,1686297921,0,469d94b8,1335522778300134400">哦豁</d>
24
+ <d p="13.419,1,25,8700107,1686268005,0,be402447,1335271828100244224">太酷啦</d>
25
+ <d p="13.419,1,25,16777215,1686316828,3,7ffb6619,1335681385016736768">喜欢</d>
26
+ <d p="13.459,1,25,16777215,1686299729,0,45834405,1335537942797634048">一般,不好看</d>
27
+ <d p="13.462,1,25,16777215,1686302133,0,3cab672c,1335558106620590080">哈哈哈</d>
28
+ <d p="13.481,1,25,16777215,1686297342,0,ce67fafd,1335517923728804864">?</d>
29
+ <d p="13.499,1,25,16777215,1686301548,3,2848bf1c,1335517923728804864">不喜欢</d>
30
+ </i>`
31
+
32
+ describe('其它', () => {
33
+ const pool = UniPool.fromBiliXML(xml)
34
+ it('B站dmid去重(仅限主站直接获取的弹幕)', () => {
35
+ const ori = pool.dans.length
36
+ expect(ori).toBe(15)
37
+ const n = pool.pipeSync(bili_dedupe)
38
+ expect(n.dans.length).toBe(13)
39
+ })
40
+ })
@@ -0,0 +1,19 @@
1
+ import type { UniDM, UniPool } from '../..'
2
+
3
+ import { PlatformVideoSource } from '../../utils/platform'
4
+
5
+ /**
6
+ * 用于过滤直接从B站api获取到的弹幕中去除dmid重复的弹幕
7
+ */
8
+ export default function bili_dedupe(that: UniPool): UniPool {
9
+ that.dans.forEach((d) => {
10
+ if (d.platform !== PlatformVideoSource.Bilibili)
11
+ throw new Error('bili-dedupe: 仅支持B站(主站)的弹幕')
12
+ if (!d.extra.bili?.dmid)
13
+ throw new Error('bili-dedupe: 弹幕缺少bili extra dmid字段')
14
+ })
15
+ const map = new Map<bigint, UniDM>()
16
+ that.dans.forEach((d) => map.set(d.extra.bili!.dmid!, d)) // 已由上方的检查保证存在
17
+ that.dans = [...map.values()]
18
+ return that
19
+ }
@@ -0,0 +1,3 @@
1
+ import bili_dedupe from './bili-dedupe'
2
+
3
+ export { bili_dedupe }
@@ -1,4 +1,4 @@
1
- // @generated by protoc-gen-es v2.10.1 with parameter "target=ts"
1
+ // @generated by protoc-gen-es v2.11.0 with parameter "target=ts"
2
2
  // @generated from file bili/dm.proto (package bilibili.community.service.dm.v1, syntax proto3)
3
3
  /* eslint-disable */
4
4
 
@@ -1,4 +1,4 @@
1
- // @generated by protoc-gen-es v2.10.1 with parameter "target=ts"
1
+ // @generated by protoc-gen-es v2.11.0 with parameter "target=ts"
2
2
  // @generated from file danuni.proto (package danuni.danmaku.v1, syntax proto3)
3
3
  /* eslint-disable */
4
4
 
@@ -88,8 +88,8 @@ describe('其它', () => {
88
88
  const c = pool.dans[1].isSameAs(pool.dans[3])
89
89
  console.info(a, b, c)
90
90
  expect(a).toBe(false)
91
- expect(b).toBe(true)
92
- expect(c).toBe(true)
91
+ expect(b).toBe(false)
92
+ expect(c).toBe(false)
93
93
  })
94
94
  it('比较(extra)', () => {
95
95
  const commonSample = {
@@ -160,7 +160,7 @@ interface DMBili {
160
160
  mode: number // xml 1
161
161
  fontsize: number // xml 2
162
162
  color: number // xml 3
163
- mid?: number // 仅创作中心源
163
+ mid?: bigint // 仅创作中心源
164
164
  midHash: string // xml 6
165
165
  /**
166
166
  * 特殊类型解析:
@@ -204,7 +204,7 @@ interface DMArtplayer {
204
204
  style?: object
205
205
  }
206
206
  interface DMDDplay {
207
- cid: number
207
+ cid: bigint
208
208
  /**
209
209
  * content
210
210
  */
@@ -241,7 +241,7 @@ interface ExtraBili {
241
241
  pool?: number //原弹幕池
242
242
  dmid?: bigint //原弹幕ID
243
243
  attr?: number //原弹幕属性
244
- mid?: number //发送者mid(仅创作中心源)
244
+ mid?: bigint //发送者mid(仅创作中心源)
245
245
  adv?: string
246
246
  code?: string
247
247
  bas?: string
@@ -572,6 +572,31 @@ export class UniDM {
572
572
  (this.extra.danuni?.merge || dan.extra.danuni?.merge)
573
573
  )
574
574
  return false
575
+ // 如果是bili弹幕,则以dmid判断是否相同
576
+ if (this.extra.bili?.dmid && dan.extra.bili?.dmid) {
577
+ // 当来源不同(标准源/创作中心源)时,视为不同弹幕
578
+ if (
579
+ (this.extra.bili.dmid && !dan.extra.bili.dmid) ||
580
+ (!this.extra.bili.dmid && dan.extra.bili.dmid)
581
+ )
582
+ return false
583
+ if (this.extra.bili.dmid === dan.extra.bili.dmid) return true
584
+ else return false
585
+ }
586
+ // 如果是artplayer弹幕,需额外比较extra项目
587
+ if (
588
+ (this.extra.artplayer && !dan.extra.artplayer) ||
589
+ (!this.extra.artplayer && dan.extra.artplayer)
590
+ )
591
+ return false
592
+ else if (
593
+ this.extra.artplayer &&
594
+ dan.extra.artplayer &&
595
+ (this.extra.artplayer.border !== dan.extra.artplayer.border ||
596
+ JSON.stringify(this.extra.artplayer.style) !==
597
+ JSON.stringify(dan.extra.artplayer.style))
598
+ )
599
+ return false
575
600
  const isSame = (k: keyof UniDMObj) => this[k] === dan[k]
576
601
  const checks = (
577
602
  [
@@ -1042,8 +1067,8 @@ export class UniDM {
1042
1067
  uid: this.senderID,
1043
1068
  m: this.content,
1044
1069
  cid: this.DMID
1045
- ? Number.parseInt(Buffer.from(this.DMID).toString('hex'), 16)
1046
- : 0,
1070
+ ? BigInt(`0x${Buffer.from(this.DMID).toString('hex')}`)
1071
+ : 0n,
1047
1072
  }
1048
1073
  }
1049
1074
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,4 +1,4 @@
1
1
  export { decimalColorToRGB, formatColor, getDecoratingColor, hexColorToRGB, isWhite, } from './color';
2
- export { layoutDanmaku } from './layout';
3
- export { arrayOfLength, assign, uniqueArray } from './lang';
4
2
  export { DanmakuList2UniPool, UniPool2DanmakuLists } from './danconvert';
3
+ export { arrayOfLength, assign, uniqueArray } from './lang';
4
+ export { layoutDanmaku } from './layout';
File without changes
File without changes
File without changes