1. add 网易云音乐解析

This commit is contained in:
QAIU
2024-10-20 18:16:51 +08:00
parent 0a3db51c7d
commit 10eec323dd
13 changed files with 83 additions and 38 deletions

View File

@@ -52,15 +52,16 @@ public class CacheManager {
}
// 写入网盘厂商API解析次数
public Future<Integer> updateTotalByCached(String shareKey) {
public Future<Integer> updateTotalByField(String shareKey, CacheTotalField field) {
Promise<Integer> promise = Promise.promise();
String fieldLower = field.name().toLowerCase();
String sql = """
MERGE INTO `api_statistics_info` (`pan_type`, `share_key`, `cache_hit_total`, `update_ts`)
MERGE INTO `api_statistics_info` (`pan_type`, `share_key`, `{field}`, `update_ts`)
KEY (`share_key`)
VALUES (#{panType}, #{shareKey}, #{total}, #{ts})
""";
""".replace("field", fieldLower);
getShareKeyTotal(shareKey, "cache_hit_total").onSuccess(total -> {
getShareKeyTotal(shareKey, fieldLower).onSuccess(total -> {
Integer newTotal = (total == null ? 0 : total) + 1;
SqlTemplate.forUpdate(jdbcPool, sql)
.execute(new HashMap<>() {{
@@ -81,30 +82,6 @@ public class CacheManager {
return fullShareKey.split(":")[0];
}
// 写入网盘厂商API解析次数
public Future<Integer> updateTotalByParser(String shareKey) {
Promise<Integer> promise = Promise.promise();
String sql = """
MERGE INTO `api_statistics_info` (`pan_type`, `share_key`, `api_parser_total`, `update_ts`)
KEY (`share_key`)
VALUES (#{panType}, #{shareKey}, #{total}, #{ts})
""";
getShareKeyTotal(shareKey, "api_parser_total").onSuccess(total -> {
Integer newTotal = (total == null ? 0 : total) + 1;
SqlTemplate.forUpdate(jdbcPool, sql)
.execute(new HashMap<>() {{
put("panType", getShareType(shareKey));
put("shareKey", shareKey);
put("total", newTotal);
put("ts", System.currentTimeMillis());
}})
.onSuccess(res -> promise.complete(res.rowCount()))
.onFailure(Throwable::printStackTrace);
});
return promise.future();
}
public Future<Integer> getShareKeyTotal(String shareKey, String name) {
String sql = """
select `share_key`, sum({total_name}) sum_num

View File

@@ -0,0 +1,10 @@
package cn.qaiu.lz.common.cache;
/**
* 缓存字段
*/
public enum CacheTotalField {
API_PARSER_TOTAL, // 解析次数
CACHE_HIT_TOTAL, // 缓存次数
FAILED_TOTAL // 解析失败次数
}

View File

@@ -3,6 +3,7 @@ package cn.qaiu.lz.web.service.impl;
import cn.qaiu.entity.ShareLinkInfo;
import cn.qaiu.lz.common.cache.CacheConfigLoader;
import cn.qaiu.lz.common.cache.CacheManager;
import cn.qaiu.lz.common.cache.CacheTotalField;
import cn.qaiu.lz.web.model.CacheLinkInfo;
import cn.qaiu.lz.web.service.CacheService;
import cn.qaiu.parser.ParserCreate;
@@ -46,12 +47,12 @@ public class CacheServiceImpl implements CacheService {
"shareKey", cacheKey
));
cacheManager.cacheShareLink(cacheLinkInfo).onFailure(Throwable::printStackTrace);
cacheManager.updateTotalByParser(cacheKey).onFailure(Throwable::printStackTrace);
cacheManager.updateTotalByField(cacheKey, CacheTotalField.API_PARSER_TOTAL).onFailure(Throwable::printStackTrace);
}).onFailure(promise::fail);
} else {
result.setExpires(generateDate(result.getExpiration()));
promise.complete(result);
cacheManager.updateTotalByCached(cacheKey).onFailure(Throwable::printStackTrace);
cacheManager.updateTotalByField(cacheKey, CacheTotalField.CACHE_HIT_TOTAL).onFailure(Throwable::printStackTrace);
}
}).onFailure(t -> promise.fail(t.fillInStackTrace()));
return promise.future();

View File

@@ -54,8 +54,9 @@ cache:
iz: 20
le: 2879
lz: 20
qq: 999999
qq: 9999999
ws:
ye:
mne: 30

View File

@@ -0,0 +1,11 @@
#@no-redirect
# https://y.music.163.com/m/song?id=472194327&uct2=qzCghKR6RWwXkHGVOZeRrg%3D%3D&fx-wechatnew=t1&fx-wxqd=c&fx-wordtest=&fx-listentest=t3&H5_DownloadVIPGift=&playerUIModeId=76001&PlayerStyles_SynchronousSharing=t3&dlt=0846&app_version=9.1.78&sc=wm&tn=
http://163cn.tv/ykLZJJT
###
#@no-redirect
https://music.163.com/song?id=233334
###
#@no-redirect
https://music.163.com/song/media/outer/url?id=233334

View File

@@ -195,6 +195,11 @@ GET http://127.0.0.1:6401/json/parser?url=https://iwx.mail.qq.com/ftn/download?f
GET http://127.0.0.1:6401/parser?url=https://474b.com/file/4015376-131945810
### PASS MNE
# @no-redirect
GET http://127.0.0.1:6401/parser?url=http://163cn.tv/ykLZJJT
### n1
http://127.0.0.1:6401/n1/statisticsInfo

View File

@@ -15,7 +15,7 @@ proxy:
# 1.origin代理地址端口后有目录(包括 / ),转发后地址:代理地址+访问URL目录部分去除location匹配目录
# 2.origin代理地址端口后无任何转发后地址代理地址+访问URL目录部
location:
- path: ~^/(json/|v2/|parser|ye/|lz/|cow/|ec/|fj/|fc/|le/|qq/|ws/|iz/|ce/).*
- path: ~^/(json/|v2/|parser|ye/|lz/|cow/|ec/|fj/|fc/|le/|qq/|ws/|iz/|ce|mne/).*
origin: 127.0.0.1:6400
# json/parser -> xxx/parser