You've already forked lubo_comment_query
							
							支持主动导入弹幕
This commit is contained in:
		
							
								
								
									
										32
									
								
								app/Util/DanmakuUtil.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								app/Util/DanmakuUtil.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Util; | ||||
| 
 | ||||
| use SplFileInfo; | ||||
| 
 | ||||
| class DanmakuUtil | ||||
| { | ||||
|     public static function parse_danmaku(SplFileInfo $file): array | ||||
|     { | ||||
|         $document = new \DOMDocument(); | ||||
|         $document->load($file->getRealPath()); | ||||
|         $danmaku_items = $document->getElementsByTagName("d"); | ||||
|         $result = []; | ||||
|         /** @var \DOMNode $item */ | ||||
|         foreach ($danmaku_items as $item) { | ||||
|             $paramsNode = $item->attributes->getNamedItem("p"); | ||||
|             $param_list = mb_split(",", $paramsNode->value); | ||||
|             if (sizeof($param_list) < 7) { | ||||
|                 throw new \Exception("弹幕格式异常"); | ||||
|             } | ||||
|             $userNode = $item->attributes->getNamedItem("user"); | ||||
|             $result[] = [ | ||||
|                 "from" => $userNode->value, | ||||
|                 "from_mid" => $param_list[6], | ||||
|                 "content" => $item->textContent, | ||||
|                 "created_at" => intval($param_list[4])/1000, | ||||
|             ]; | ||||
|         } | ||||
|         return $result; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user