MCPcopy Create free account
hub / github.com/AncientLysine/BiliLocal / parseComment

Function parseComment

src/Load.cpp:42–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40namespace
41{
42QList<Comment> parseComment(QByteArray data,Utils::Site site)
43{
44 QList<Comment> list;
45 switch(site){
46 case Utils::Bilibili:
47 case Utils::TuCao:
48 {
49 QString xml(data);
50 QVector<QStringRef> l=xml.splitRef("<d p=");
51 l.removeFirst();
52 for(const QStringRef &item:l){
53 const QVector<QStringRef> &args=item.mid(1,item.indexOf(item.at(0),1)-1).split(',');
54 if (args.size()<=4){
55 continue;
56 }
57 Comment comment;
58 comment.time =args[0].toDouble()*1000+0.5;
59 comment.date =args[4].toInt();
60 comment.mode =args[1].toInt();
61 comment.font =args[2].toInt();
62 comment.color =args[3].toInt();
63 comment.sender=args.size()<=6?QString():args[6].toString();
64 int sta=item.indexOf(">")+1;
65 int len=item.indexOf("<",sta)-sta;
66 comment.string=Utils::decodeXml(item.mid(sta,len).toString(),true);
67 list.append(comment);
68 }
69 break;
70 }
71 case Utils::AcFun:
72 {
73 QQueue<QJsonArray> queue;
74 queue.append(QJsonDocument::fromJson(data).array());
75 while(!queue.isEmpty()){
76 for(const QJsonValue &i:queue.head()){
77 if(i.isArray()){
78 queue.append(i.toArray());
79 }
80 else{
81 QJsonObject item=i.toObject();
82 QString c(item["c"].toString()),m(item["m"].toString());
83 const QVector<QStringRef> &args=c.splitRef(',');
84 if (args.size()<6){
85 continue;
86 }
87 Comment comment;
88 comment.time =args[0].toDouble()*1000+0.5;
89 comment.date =args[5].toInt();
90 comment.mode =args[2].toInt();
91 comment.font =args[3].toInt();
92 comment.color =args[1].toInt();
93 comment.sender=args[4].toString();
94 comment.string=m;
95 list.append(comment);
96 }
97 }
98 queue.dequeue();
99 }

Callers 2

LoadMethod · 0.85
dumpDanmakuMethod · 0.85

Calls 5

splitMethod · 0.80
sizeMethod · 0.80
isEmptyMethod · 0.80
dequeueMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected