touchstorm/youtube-subscriber-parser

将YouTube订阅者数量解析为可用的整数

1.0.5 2019-08-02 15:12 UTC

This package is auto-updated.

Last update: 2024-09-29 05:48:38 UTC


README

解析YouTube订阅者数量为可用的整数。

2019年5月,YouTube 宣布了一项更新,该更新将影响其YouTube Data API中的订阅者数量。此更新将调整API响应中找到的订阅者数量完整整数格式(673335),以匹配在YouTube视频和频道页面上找到的缩写显示格式(673K)。

此库将把YouTube的格式化字符串转换为整数,以便于数据库存储、前端显示等。

YouTube数据API请求

GET /v3/channels?part=statistics&forUsername=howdiniguru&key=...&fields=items(statistics(subscriberCount))

2019年8月之前响应

{
 "items": [
  {
   "statistics": {
    "subscriberCount": "673335"
   }
  }
 ]
}

2019年8月之后响应

{
 "items": [
  {
   "statistics": {
    "subscriberCount": "673K"
   }
  }
 ]
}

安装 & 使用

composer require touchstorm/youtube-subscriber-parser
require_once __DIR__ . '/../vendor/autoload.php';

use Subscriber\Count;

$tens_abbr_count = '41';
$hundreds_abbr_count = '311';
$thousands_decimal_abbr_count = '1.5K';
$thousands_abbr_count = '883K';
$millions_abbr_count = '99M';
$hundred_millions_abbr_count = '943M';

echo Count::parse($tens_abbr_count); // 41
echo Count::parse($hundreds_abbr_count); // 311
echo Count::parse($thousands_decimal_abbr_count); // 1500
echo Count::parse($thousands_abbr_count); // 883000
echo Count::parse($millions_abbr_count); // 99000000
echo Count::parse($hundred_millions_abbr_count); // 943000000