115Rename

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址