banner
Vinking

Vinking

你写下的每一个BUG 都是人类反抗被人工智能统治的一颗子弹

Sir, this way~ Analysis of shared external information

Because sometimes I need to share some external information on the blog, I collected some APIs to ensure that the shared cards contain some basic information and can have real-time updates. When writing articles, I insert the shortcode [share url] [/share] to achieve automatic parsing. You only need to fill in the sharing URL without any additional information, which is very convenient.

Game Information#

Steam Game Information#

For sharing Steam games, the simplest way is to use the iframe tag to call the small widget provided by the official:

However, since Steam is in a semi-blocked state, the loading speed of this is really not commendable, and in some places, the network simply fails to load (for example, at my home 😣). Similarly, the API for Steam game information https://store.steampowered.com/api/appdetails is also not recommended due to loading speed issues.

Xiaohei Box API#

Here, I recommend using the Xiaohei Box API https://api.xiaoheihe.cn/game/web/get_game_detail.

The necessary parameters are the current timestamp _time and the Steam game ID appid. Just like this: https://api.xiaoheihe.cn/game/web/get_game_detail/?_time=1663404056&appid=289070.

If you include the parameters os_type=web&version=999.0.2 when making the request, you must also include a hkey parameter; otherwise, it will prompt that hkey cannot be empty. There is no updated algorithm for calculating hkey available online, and since the hkey algorithm changes frequently, I don't plan to spend time researching this. Currently, it seems that a small number of games may not return price information without the hkey parameter, so if you use it, you need to be prepared for fallback handling.

Steam API#

The necessary parameter for the Steam API is the game ID appids, and it is recommended to include the region for querying the game cc=cn, so that the returned price will be in Chinese Yuan (CNY); at the same time, including the l=schinese parameter will replace the text such as tags and game descriptions with Chinese text (provided that the publisher has localized the game page into Chinese).

Finally, since the Steam API returns a very, very, very large amount of information, almost double that of the Xiaohei Box API, it exacerbates the already slow loading speed. In response to this situation, Steam provides a filters parameter that allows users to specify and filter the required information. However, it should be noted that this parameter can only filter out object collections (i.e., data structures surrounded by curly braces {} or square brackets []). This means that once the filters parameter is used for filtering, all non-object collection data, such as the game name name, will be excluded. Currently, no solution has been found to address this limitation. Usage is just like this: https://store.steampowered.com/api/appdetails/?appids=814380&cc=cn&l=schinese.

Note

By the way, the prices and discounts returned by the Xiaohei Box API are those of Xiaohei Box, not Steam's prices and discounts.

The parsing effect is as follows:

To obtain the store page link corresponding to the platform game, you need to directly use the platform's built-in API (usually the platform's search API).

Steam#

For the Steam platform, you can construct the game link by appending steam_appid to the base URL https://store.steampowered.com/app/.

For example, the link for "Overcooked! 2" is https://store.steampowered.com/app/728880.

Switch#

The game search for the Switch platform can be implemented through the https://search.nintendo.jp/nintendo_soft/search.json API, where the key parameter q represents the game name and supports English or Japanese. If you directly use the Chinese name, such as q=集合啦!动物森友会, you will not be able to obtain game information.

For example, the API URL for "Xenoblade 3" is: https://search.nintendo.jp/nintendo_soft/search.json?q=Xenoblade3. By using the id value returned by the API, you can construct the game link in the Switch store, such as: https://store-jp.nintendo.com/list/software/70010000053335.html.

Ubisoft#

The game search API for the Ubisoft platform is https://zh-cn.ubisoft.com/news2/search_name, which requires the game_keyword parameter and supports searching for Chinese game names.

For example, the API URL for searching "Skull and Bones" is: https://zh-cn.ubisoft.com/news2/search_name?game_keyword=碧海黑帆.

By appending the returned gameabb value to https://zh-cn.ubisoft.com, you can obtain the game link, such as: https://zh-cn.ubisoft.com/skull_and_bones.

Blizzard#

Warning

💩 Search Inaccuracy Warning

The search on the Blizzard platform may yield inaccurate results.

The game search API for the Blizzard platform is https://tw.shop.battle.net/api/search, which requires two parameters: q (game name) and l (language code, such as en-us or zh-tw).

For example, the API URL for searching "Warcraft III: Reforged" is: https://tw.shop.battle.net/api/search?q=Warcraft III: Reforged&l=en-us. After obtaining the destination from the returned data, append it to the base URL https://tw.shop.battle.net/zh-tw to construct the game link, such as: https://tw.shop.battle.net/zh-tw/product/warcraft-iii-reforged.

Other Platforms#

For platforms like Playstation, Xbox, iOS, etc., no direct APIs have been found, and web scraping is usually used to obtain game links.

As for Epic, due to encrypted parameters and anti-scraping strategies, and the Origin platform lacking a public API, these platforms will directly use the game links provided by Xiaohei Box.


Bilibili Information#

Video#

Similar to sharing Steam game cards, Bilibili can also share video information through the iframe tag:

Bilibili Share

The API call for Bilibili video information is relatively simple, requiring only a parameter bvid or aid that represents the video. For example: https://api.bilibili.com/x/web-interface/view?bvid=1NT411u7n9.

The parsing effect is as follows:

Dynamics#

The API for Bilibili dynamics is also simple, requiring a parameter id that represents the dynamic, as well as an optional timezone offset timezone_offset (in minutes, default value is -480). For example: https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?id=706453546894098487.

Note

The array of dynamic content rich_text_nodes will be separated by emojis as array delimiters. For example, the sentence "This is a text post[Give Heart]more text" will be divided into three elements in the array: This is a text post, [Give Heart], more text. Therefore, you need to traverse the array and concatenate the elements to obtain the complete dynamic content.

Danmaku#

The API for danmaku information requires a parameter oid representing the video, which is the video's cid, and can be obtained through the video information API. For example, to get the danmaku for the video with cid 834814323: https://api.bilibili.com/x/v1/dm/list.so?oid=834814323. The data format returned by the API is XML.

[!NOTE]

  1. The cid of the video is not the same concept as the video's AV/BV number. For example, the video with BV number 1NT411u7n9 corresponds to cid 834814323.
  2. The returned data is compressed using deflate and needs to be decompressed. In PHP, you can use the gzinflate() function for decompression.

Focus on the following data:

  • The <maxlimit> tag contains the maximum number of danmaku for the video.

  • The <state> tag indicates whether danmaku is open for the video, where 0 means danmaku can be sent normally, and 1 means the danmaku sending function is closed.

  • The <d p="114.63900,1,25,16777215,1673445087,0,xxxxxxxx,yyyyyyyyyyyyyyyyyyy,10"> Pressure finally reached the second creation</d> tag contains the specific information of each danmaku. For detailed information, refer to: bilibili-API-collect Attribute p. Thus, it can be concluded that the danmaku with the content Pressure finally reached the second creation appeared at 114.639 seconds into the video, is a normal danmaku scrolling from right to left, with a font size of standard, font color of white, sent at 21:51:27 on January 11, 2023 (timestamp 1673445087), danmaku pool type is normal danmaku, the sender's mid hash is an 8-digit alphanumeric combination xxxxxxxx, and the danmaku dmid is a 19-digit pure number yyyyyyyyyyyyyyyyyyy, and when the danmaku shielding level is greater than 10, that danmaku can be shielded.


Github Repository Information#

Similarly, the API for Github repository information is also very simple; you only need to append {username}/{repository name} after https://api.github.com/repos/. Like this: https://api.github.com/repos/SocialSisterYi/bilibili-API-collect.

The parsing effect is as follows:

Blog Article/Page Information#

Since Typecho has been upgraded to the latest version 1.2, the original plugin for outputting article information is no longer usable, so I had to add some functionality myself.

In Function.php, add:

// Get article information
public static function getCustom($uid){
    $type = is_numeric($uid) ? 'post' : 'page';
    $cidType = $type === "post" ? 'cid' : 'slug';
    $f = Typecho_Widget::widget('Widget_Archive@'.$uid,'pageSize=1&type='.$type, $cidType.'='.$uid);
    $archive_info = ['title'=> $f->title ,'desc' => $f->description ,'category' => $f->category ,'time' => date('Y.m.d', $f->created)];
    return $archive_info;
}

Then create an independent page template, calling getCustom() by obtaining the parameters from the URL.

/**
* Article Information
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
function filter($uid){
    preg_match_all("/[a-zA-Z0-9]/",$uid,$a);
    return join('',$a[0]);
}
if(!empty(filter($_SERVER["QUERY_STRING"]))){
    foreach (explode('&', filter($_SERVER["QUERY_STRING"])) as $value) {
    	if (strpos($value,'uid')!== false) $uid = explode('=', $value)[1];
    }
    $returnJson=['state'=>1,'data'=> Func::getCustom($uid)];
    echo json_encode($returnJson, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
}else{
    $returnJson=['state'=>-2,'message'=>"No valid UID input"];
    echo json_encode($returnJson, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
}

Finally, add an independent page in the backend and select the Article Information template. There is only one corresponding article cid or page slug parameter uid. The article call is as follows: https://vinking.top/getInfo.html?uid=67, and the independent page call is as follows: https://vinking.top/getInfo.html?uid=about.

The article parsing effect is as follows:

Currently, I have only used these few most commonly used APIs, and more external parsing will be written when needed 🙈.

Ordinary URL Parsing#

Recently, I wrote an API that can parse ordinary pages, but some URLs may fail to parse, so just make do with it for now...

2022.12.3: After optimization, the compatibility with different websites has been greatly improved.

Title and Description Parsed Successfully#

URL Title Parsing Failed#

Taking the official website of "Genshin Impact" as an example, from the image below, it can be observed that the content of the title tag on this page is dynamically generated through a js file named config.54af175465c7448a0fa377d065a2d6da.js, which means that the original static HTML does not contain the <title> tag before the page is fully loaded, so the page title cannot be directly obtained.

However, this page defines keywords metadata, so when the <title> tag cannot be obtained, we will choose the first value in keywords as the parsed title. The reason for this is that the first value in keywords usually corresponds to the page title, and when there is no other obvious information representing the webpage title, this is a feasible alternative.

Example of Title Parsing Failure

URL Description Parsing Failed#

URL Does Not Exist#

URL Access Timeout in Mainland#

When the URL access times out in the mainland, it automatically uses a proxy to try again. If the access times out again, it will be downgraded to 'URL does not exist'.

This article is synchronized and updated to xLog by Mix Space. The original link is https://www.vinking.top/posts/codes/game-and-social-media-sharing

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.