115Rename2024

115改名称(根据现有的文件名<番号>查询并修改文件名)

  1. // ==UserScript==
  2. // @name 115Rename2024
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.12
  5. // @description 115改名称(根据现有的文件名<番号>查询并修改文件名)
  6. // @author db117 wusuowei
  7. // @include https://115.com/*
  8. // @domain javbus.com
  9. // @domain avmoo.host
  10. // @domain avsox.host
  11. // @grant GM_notification
  12. // @grant GM_xmlhttpRequest
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. // 按钮
  18. let rename_list = `
  19. <li id="rename_list">
  20. <a id="rename_all_javbus" class="mark" href="javascript:;">改名javbus</a>
  21. <a id="rename_all_javbus_date" class="mark" href="javascript:;">改名javbus_时间</a>
  22. <a id="rename_all_avmoo" class="mark" href="javascript:;">改名avmoo</a>
  23. <a id="rename_all_avmoo_date" class="mark" href="javascript:;">改名avmoo_时间</a>
  24. </li>
  25. `;
  26. /**
  27. * 添加按钮的定时任务
  28. */
  29. let interval = setInterval(buttonInterval, 1000);
  30.  
  31. // javbus
  32. let javbusBase = "https://www.javbus.com/";
  33. // 有码
  34. let javbusSearch = javbusBase + "search/";
  35. // 无码
  36. let javbusUncensoredSearch = javbusBase + "uncensored/search/";
  37.  
  38. // avmoo
  39. // 有码
  40. let avmooSearch = "https://avmoo.host/cn/search/";
  41. // 无码
  42. let avmooUncensoredSearch = "https://avsox.host/cn/search/";
  43. 'use strict';
  44.  
  45. /**
  46. * 添加按钮定时任务(检测到可以添加时添加按钮)
  47. */
  48. function buttonInterval() {
  49. let open_dir = $("div#js_float_content li[val='open_dir']");
  50. if (open_dir.length !== 0 && $("li#rename_list").length === 0) {
  51. open_dir.before(rename_list);
  52. $("a#rename_all_javbus").click(
  53. function () {
  54. rename(rename_javbus, false);
  55. });
  56. $("a#rename_all_javbus_date").click(
  57. function () {
  58. rename(rename_javbus, true);
  59. });
  60. $("a#rename_all_avmoo").click(
  61. function () {
  62. rename(rename_avmoo, false);
  63. });
  64. $("a#rename_all_avmoo_date").click(
  65. function () {
  66. rename(rename_avmoo, true);
  67. });
  68. console.log("添加按钮");
  69. // 结束定时任务
  70. clearInterval(interval);
  71. }
  72. }
  73.  
  74. /**
  75. * 执行改名方法
  76. * @param call 回调函数
  77. * @param addDate 是否添加时间
  78. */
  79. function rename(call, addDate) {
  80. // 获取所有已选择的文件
  81. let list = $("iframe[rel='wangpan']")
  82. .contents()
  83. .find("li.selected")
  84. .each(function (index, v) {
  85. let $item = $(v);
  86. // 原文件名称
  87. let file_name = $item.attr("title");
  88. // 文件类型
  89. let file_type = $item.attr("file_type");
  90.  
  91. // 文件id
  92. let fid;
  93. // 后缀名
  94. let suffix;
  95. if (file_type === "0") {
  96. // 文件夹
  97. fid = $item.attr("cate_id");
  98. } else {
  99. // 文件
  100. fid = $item.attr("file_id");
  101. // 处理后缀
  102. let lastIndexOf = file_name.lastIndexOf('.');
  103. if (lastIndexOf !== -1) {
  104. suffix = file_name.substr(lastIndexOf, file_name.length);
  105. }
  106. }
  107.  
  108. if (fid && file_name) {
  109. let fh = getVideoCode(file_name);
  110. if (fh) {
  111. // 校验是否是中文字幕
  112. let chineseCaptions = checkChineseCaptions(fh, file_name);
  113. let Uncensored = checkUncensored (fh, file_name);
  114. // 执行查询
  115. call(fid, fh, suffix, chineseCaptions,Uncensored,addDate);
  116. }
  117. }
  118. });
  119.  
  120. }
  121.  
  122. /**
  123. * 通过javbus进行查询
  124. */
  125. function rename_javbus(fid, fh, suffix, chineseCaptions, Uncensored,addDate) {
  126. requestJavbus(fid, fh, suffix, chineseCaptions,Uncensored, addDate, javbusSearch);
  127. }
  128.  
  129. /**
  130. * 请求javbus,并请求115进行改名
  131. * @param fid 文件id
  132. * @param fh 番号
  133. * @param suffix 后缀
  134. * @param chineseCaptions 是否有中文字幕
  135. * @param url 请求地址
  136. * @param addDate 是否添加时间
  137. */
  138. function requestJavbus(fid, fh, suffix, chineseCaptions,Uncensored, addDate, url) {
  139. GM_xmlhttpRequest({
  140. method: "GET",
  141. url: url + fh,
  142. onload: xhr => {
  143. // 匹配标题
  144. let response = $(xhr.responseText);
  145.  
  146. // 标题
  147. let title = response
  148. .find("div.photo-frame img")
  149. .attr("title");
  150.  
  151. // 时间
  152. let date = response
  153. .find("div.photo-info date:last")
  154. .html();
  155.  
  156. if (title) {
  157. // 构建新名称
  158. let newName = buildNewName(fh, suffix, chineseCaptions,Uncensored,title);
  159.  
  160. // 添加时间
  161. if (addDate && date) {
  162. newName = date + "_" + newName;
  163. }
  164.  
  165. if (newName) {
  166. // 修改名称
  167. send_115(fid, newName, fh);
  168. }
  169. } else if (url !== javbusUncensoredSearch) {
  170. // 进行无码重查询
  171. requestJavbus(fid, fh, suffix, chineseCaptions, addDate, javbusUncensoredSearch);
  172. }
  173. }
  174. })
  175. }
  176.  
  177. /**
  178. * 通过avmoo进行查询
  179. */
  180. function rename_avmoo(fid, fh, suffix, chineseCaptions,Uncensored, addDate) {
  181. requestAvmoo(fid, fh, suffix, chineseCaptions,Uncensored, addDate, avmooSearch);
  182. }
  183.  
  184. /**
  185. * 请求avmoo,并请求115进行改名
  186. * @param fid 文件id
  187. * @param fh 番号
  188. * @param suffix 后缀
  189. * @param chineseCaptions 是否有中文字幕
  190. * @param addDate 是否带时间
  191. * @param url 请求地址
  192. */
  193. function requestAvmoo(fid, fh, suffix, chineseCaptions,Uncensored, addDate, url) {
  194. GM_xmlhttpRequest({
  195. method: "GET",
  196. url: url + fh,
  197. onload: xhr => {
  198. // 匹配标题
  199. let response = $(xhr.responseText);
  200. if (!(response.find("div.alert").length)) {
  201. let title = response
  202. .find("div.photo-frame img")
  203. .attr("title");
  204.  
  205. // 时间
  206. let date = response
  207. .find("div.photo-info date:last")
  208. .html();
  209.  
  210. if (title) {
  211. // 构建新名称
  212. let newName = buildNewName(fh, suffix, chineseCaptions,Uncensored, title);
  213.  
  214. // 添加时间
  215. if (addDate && date) {
  216. newName = date + "_" + newName;
  217. }
  218.  
  219. if (newName) {
  220. // 修改名称
  221. send_115(fid, newName, fh);
  222. }
  223. }
  224. } else if (url !== avmooUncensoredSearch) {
  225. // 进行无码查询
  226. requestAvmoo(fid, fh, suffix, chineseCaptions, addDate, avmooUncensoredSearch);
  227. }
  228. }
  229. })
  230. }
  231.  
  232. /**
  233. * 构建新名称
  234. * @param fh 番号
  235. * @param suffix 后缀
  236. * @param chineseCaptions 是否有中文字幕
  237. * @param title 番号标题
  238. * @returns {string} 新名称
  239. */
  240. function buildNewName(fh, suffix, chineseCaptions,Uncensored, title) {
  241. if (title) {
  242. let newName = String(fh);
  243. // 有中文字幕
  244. if (chineseCaptions) {
  245. newName = newName + "【中文字幕】";
  246. }
  247. // 有无码
  248. if (Uncensored) {
  249. newName = newName + "【无码】";
  250. }
  251. // 拼接标题
  252. newName = newName + " " + title;
  253. if (suffix) {
  254. // 文件保存后缀名
  255. newName = newName + suffix;
  256. }
  257. return newName;
  258. }
  259. }
  260.  
  261. /**
  262. * 请求115接口
  263. * @param id 文件id
  264. * @param name 要修改的名称
  265. * @param fh 番号
  266. */
  267. function send_115(id, name, fh) {
  268.  
  269. let file_name = stringStandard(name);
  270. $.post("https://webapi.115.com/files/edit", {
  271. fid: id,
  272. file_name: file_name
  273. },
  274. function (data, status) {
  275. let result = JSON.parse(data);
  276. if (!result.state) {
  277. GM_notification(getDetails(fh, "修改失败"));
  278. console.log("请求115接口异常: " + unescape(result.error
  279. .replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1')));
  280. } else {
  281. GM_notification(getDetails(fh, "修改成功"));
  282. console.log("修改文件名称,fh:" + fh, "name:" + file_name);
  283. }
  284. }
  285. );
  286. }
  287.  
  288. /**
  289. * 通知参数
  290. * @param text 内容
  291. * @param title 标题
  292. * @returns {{text: *, title: *, timeout: number}}
  293. */
  294. function getDetails(text, title) {
  295. return {
  296. text: text,
  297. title: title,
  298. timeout: 1000
  299. };
  300. }
  301.  
  302. /**
  303. * 115名称不接受(\/:*?\"<>|)
  304. * @param name
  305. */
  306. function stringStandard(name) {
  307. return name.replace(/\\/g, "")
  308. .replace(/\//g, " ")
  309. .replace(/:/g, " ")
  310. .replace(/\?/g, " ")
  311. .replace(/"/g, " ")
  312. .replace(/</g, " ")
  313. .replace(/>/g, " ")
  314. .replace(/\|/g, "")
  315. .replace(/\*/g, " ");
  316. }
  317.  
  318. /**
  319. * 校验是否为中文字幕
  320. * @param fh 番号
  321. * @param title 标题
  322. */
  323. function checkChineseCaptions(fh, title) {
  324. if (title.indexOf("中文") !== -1) {
  325. return true;
  326. }
  327. let regExp = new RegExp(fh + "[_-](UC|C)");
  328. let match = title.toUpperCase().match(regExp);
  329. if (match) {
  330. return true;
  331. }
  332. }
  333. /**
  334. * 校验是否为无码
  335. * @param fh 番号
  336. * @param title 标题
  337. */
  338. function checkUncensored(fh, title) {
  339. if (title.indexOf("无码") !== -1) {
  340. return true;
  341. }
  342. let regExp = new RegExp(fh + "[_-](UC|U)");
  343. let match = title.toUpperCase().match(regExp);
  344. if (match) {
  345. return true; // 如果标题中包含 "-U" 或 "_U",则返回 true,表示为无码
  346. }
  347. return false; // 默认情况下,返回 false,表示不是无码
  348. }
  349. /**
  350. * 获取番号
  351. * @param title 源标题
  352. * @returns {string} 提取的番号
  353. */
  354. function getVideoCode(title) {
  355. title = title.toUpperCase().replace("SIS001", "")
  356. .replace("1080P", "")
  357. .replace("720P", "");
  358.  
  359. let t = title.match(/T28[\-_]\d{3,4}/);
  360. // 一本道
  361. if (!t) {
  362. t = title.match(/1PONDO[\-_]\d{6}[\-_]\d{2,4}/);
  363. if (t) {
  364. t = t.toString().replace("1PONDO_", "")
  365. .replace("1PONDO-", "");
  366. }
  367. }
  368. if (!t) {
  369. t = title.match(/HEYZO[\-_]?\d{4}/);
  370. }
  371. if (!t) {
  372. // 加勒比
  373. t = title.match(/CARIB[\-_]\d{6}[\-_]\d{3}/);
  374. if (t) {
  375. t = t.toString().replace("CARIB-", "")
  376. .replace("CARIB_", "");
  377. }
  378. }
  379. if (!t) {
  380. // 东京热
  381. t = title.match(/N[-_]\d{4}/);
  382. }
  383. if (!t) {
  384. // Jukujo-Club | 熟女俱乐部
  385. t = title.match(/JUKUJO[-_]\d{4}/);
  386. }
  387. // 通用
  388. if (!t) {
  389. t = title.match(/[A-Z]{2,5}[-_]\d{3,5}/);
  390. }
  391. if (!t) {
  392. t = title.match(/\d{6}[\-_]\d{2,4}/);
  393. }
  394. if (!t) {
  395. t = title.match(/[A-Z]+\d{3,5}/);
  396. }
  397. if (!t) {
  398. t = title.match(/[A-Za-z]+[-_]?\d+/);
  399. }
  400. if (!t) {
  401. t = title.match(/\d+[-_]?\d+/);
  402. }
  403. if (!t) {
  404. t = title;
  405. }
  406. if (t) {
  407. t = t.toString().replace("_", "-");
  408. console.log("找到番号:" + t);
  409. return t;
  410. }
  411. }
  412. })();