add:新增临时rss订阅地址

This commit is contained in:
Yutousama 2022-07-16 18:25:30 +08:00
parent e17095cc7e
commit 88960372f5
4 changed files with 134 additions and 47 deletions

View File

@ -3,14 +3,11 @@ package com.yutou.tools.bangumi;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.tools.mybatis.dao.BangumiItemDao;
import com.yutou.tools.mybatis.dao.BangumiListDao;
import com.yutou.tools.mybatis.model.BangumiItem; import com.yutou.tools.mybatis.model.BangumiItem;
import com.yutou.tools.mybatis.model.BangumiItemExample;
import com.yutou.tools.mybatis.model.BangumiList; import com.yutou.tools.mybatis.model.BangumiList;
import com.yutou.tools.mybatis.model.BangumiListExample;
import com.yutou.tools.services.interfaces.BangumiService; import com.yutou.tools.services.interfaces.BangumiService;
import com.yutou.tools.utils.BangumiTools; import com.yutou.tools.utils.BangumiTools;
import com.yutou.tools.utils.RedisTools;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -84,7 +81,20 @@ public class AnimationController {
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/rss/add.do", method = RequestMethod.POST) @RequestMapping(value = "/anim/rss/add.do", method = RequestMethod.POST)
public String addAnimationRss(String bgmId, String title, String author, String categories, String titleKey, String bid) { public JSONObject addAnimationRss(String bgmId, String title, String author, String categories, String titleKey, String bid) {
int i = 0;
JSONObject json = new JSONObject();
json.put("code", 0);
if ("-1".equals(bid)) {
BangumiItem item = new BangumiItem();
item.setId(-1);
item.setTitle(title);
item.setTitlekey(title.split("\\?")[1]);
i = bangumiService.addBangumiItem(item);
json.put("msg", i == 0 ? "添加失败" : "添加成功");
return json;
}
int id = 0; int id = 0;
if (!StringUtils.isEmpty(bgmId)) { if (!StringUtils.isEmpty(bgmId)) {
try { try {
@ -100,11 +110,9 @@ public class AnimationController {
item.setTitlekey(titleKey); item.setTitlekey(titleKey);
item.setBid(bid); item.setBid(bid);
item.setEnable(1); item.setEnable(1);
int i = bangumiService.addBangumiItem(item); i = bangumiService.addBangumiItem(item);
JSONObject json = new JSONObject();
json.put("code", 0);
json.put("msg", i == 0 ? "添加失败" : "添加成功"); json.put("msg", i == 0 ? "添加失败" : "添加成功");
return json.toJSONString(); return json;
} }
@ResponseBody @ResponseBody
@ -119,12 +127,18 @@ public class AnimationController {
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/rss/del.do", method = RequestMethod.POST) @RequestMapping(value = "/anim/rss/del.do", method = RequestMethod.POST)
public String delAnimation(int id) { public JSONObject delAnimation(String id) {
int i = bangumiService.removeBangumiItem(id);
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("code", 0); json.put("code", 0);
if (id.startsWith("http")) {
boolean tmpRss = RedisTools.list_remove("anim_tmp_rss", id);
json.put("msg", tmpRss ? "删除成功" : "删除失败");
return json;
}
int i = bangumiService.removeBangumiItem(Integer.parseInt(id));
json.put("msg", i == 0 ? "删除失败" : "删除成功"); json.put("msg", i == 0 ? "删除失败" : "删除成功");
return json.toJSONString(); return json;
} }
@ResponseBody @ResponseBody

View File

@ -14,7 +14,9 @@ import com.yutou.tools.utils.Tools;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
@Service("BangumiService") @Service("BangumiService")
public class BangumiServiceImpl implements BangumiService { public class BangumiServiceImpl implements BangumiService {
@ -36,7 +38,9 @@ public class BangumiServiceImpl implements BangumiService {
@Override @Override
public int addBangumiItem(BangumiItem... list) { public int addBangumiItem(BangumiItem... list) {
for (BangumiItem item : list) { for (BangumiItem item : list) {
if (itemDao.insert(item) <= 0) { if (item.getId().equals(-1)) {
RedisTools.list_add("anim_tmp_rss",item.getTitle());
} else if (itemDao.insert(item) <= 0) {
return 0; return 0;
} }
} }
@ -68,40 +72,59 @@ public class BangumiServiceImpl implements BangumiService {
@Override @Override
public List<BangumiItem> getBangumiItemList(String type) { public List<BangumiItem> getBangumiItemList(String type) {
List<BangumiItem> items;
if ("-1".equals(type)) {
Set<String> strings = RedisTools.list_get("anim_tmp_rss");
items=new ArrayList<>();
for (String string : strings) {
BangumiItem item=new BangumiItem();;
item.setTitle(string);
items.add(item);
}
return items;
}
BangumiItemExample example = new BangumiItemExample(); BangumiItemExample example = new BangumiItemExample();
example.createCriteria().andBidEqualTo(type); example.createCriteria().andBidEqualTo(type);
List<BangumiItem> items = itemDao.selectByExample(example); items = itemDao.selectByExample(example);
for (BangumiItem item : items) { for (BangumiItem item : items) {
if(item.getEnable()==0||item.getBgmid()==0){ if (item.getEnable() == 0 || item.getBgmid() == 0) {
continue; continue;
} }
String tmp=RedisTools.get(item.getBgmid()+"",1); String tmp = RedisTools.get(item.getBgmid() + "", 1);
JSONObject bangumi= tmp==null?BangumiTools.getBangumiInfoSmall(item.getBgmid()):JSONObject.parseObject(tmp); JSONObject bangumi = tmp == null ? BangumiTools.getBangumiInfoSmall(item.getBgmid()) : JSONObject.parseObject(tmp);
RedisTools.set(1,2592000,item.getBgmid()+"",bangumi.toJSONString()); RedisTools.set(1, 2592000, item.getBgmid() + "", bangumi.toJSONString());
if(bangumi.containsKey("code")&&bangumi.getInteger("code")==404){ if (bangumi.containsKey("code") && bangumi.getInteger("code") == 404) {
continue; continue;
} }
int day=Tools.getWeekDay(); int day = Tools.getWeekDay();
if (day == 0) { if (day == 0) {
day = 7; day = 7;
} }
if(bangumi.getInteger("air_weekday")==day) { if (bangumi.getInteger("air_weekday") == day) {
item.setUpdateDay("今天更新"); item.setUpdateDay("今天更新");
}else{ } else {
item.setUpdateDay(""+getDay(bangumi.getInteger("air_weekday"))+"更新"); item.setUpdateDay("" + getDay(bangumi.getInteger("air_weekday")) + "更新");
} }
} }
return items; return items;
} }
private String getDay(int day){
switch (day){ private String getDay(int day) {
case 1:return ""; switch (day) {
case 2:return ""; case 1:
case 3:return ""; return "";
case 4:return ""; case 2:
case 5:return ""; return "";
case 6:return ""; case 3:
default:return ""; return "";
case 4:
return "";
case 5:
return "";
case 6:
return "";
default:
return "";
} }
} }
@ -112,6 +135,11 @@ public class BangumiServiceImpl implements BangumiService {
@Override @Override
public List<BangumiList> getAllBangumiList() { public List<BangumiList> getAllBangumiList() {
return listDao.selectByExample(new BangumiListExample()); List<BangumiList> list = listDao.selectByExample(new BangumiListExample());
BangumiList bangumi = new BangumiList();
bangumi.setTitle("临时RSS");
bangumi.setId(-1);
list.add(bangumi);
return list;
} }
} }

View File

@ -173,6 +173,11 @@
<a class="layui-btn layui-btn-xs" lay-event="show">查看</a> <a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script> </script>
<script type="text/html" id="RsslistTools">
<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="mikan">MiKan</a>
<a class="layui-btn layui-btn-xs" lay-event="tmp_rss_show">查看</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="tmp_rss_del">删除</a>
</script>
<script type="text/html" id="animState"> <script type="text/html" id="animState">
{{# if(d.enable==1){}} {{# if(d.enable==1){}}
<div><input type="checkbox" name="state" lay-text="启用|关闭" lay-filter="stateCheckbox" lay-skin="switch" <div><input type="checkbox" name="state" lay-text="启用|关闭" lay-filter="stateCheckbox" lay-skin="switch"
@ -202,7 +207,22 @@
window.location.href = "/" window.location.href = "/"
} }
}) })
function addTmpRss(def) {
layer.prompt({
formType: 0,
value: '',
title: '请输入RSS地址'
}, function(value, index, elem){
$.post('/anim/rss/add.do',{
title: value,
bid:-1
},function (json) {
console.log(json)
layer.msg(json.msg)
layer.close(index);
})
});
}
layui.use(['layer', 'form', 'element', 'table', 'util'], function () { layui.use(['layer', 'form', 'element', 'table', 'util'], function () {
let layer = layui.layer let layer = layui.layer
, util = layui.util , util = layui.util
@ -220,24 +240,34 @@
} }
} }
}); });
$.get("/anim/type/list.do", function (data) { $.get("/anim/type/list.do", function (data) {
let json = JSON.parse(data); let json = JSON.parse(data);
if (json.code === 0) { if (json.code === 0) {
for (let index = 0; index < json.data.length; index++) { for (let index = 0; index < json.data.length; index++) {
const ret = json.data[index]; let ret = json.data[index];
let content;
if(ret.id===-1){
content='<button type="button" class="layui-btn layui-btn-xs" onclick="addTmpRss(this)">添加临时订阅地址</button>'
}else{
content=''
}
element.tabAdd('animType', { element.tabAdd('animType', {
title: ret.title title: ret.title
, content: '<table id="passwordlist' + ret.id + '" lay-filter="adminTable"></table>' , content: content+'<table id="passwordlist' + ret.id + '" lay-filter="adminTable"></table>'
, id: ret.id , id: ret.id
}) })
} }
element.on('tab(animType)', function (data) { element.on('tab(animType)', function (data) {
tabid = $(this).attr('lay-id') tabid = $(this).attr('lay-id')
table.render({ let cols;
elem: "#passwordlist" + tabid if(tabid==='-1'){
, url: '/anim/rss/list.do?type=' + tabid cols=[[
, page: true {field: 'title', title: '地址'}
, cols: [[ ,{field: "right", toolbar: '#RsslistTools'}
]]
}else{
cols=[[
{field: "id", title: "id", width: 60, sort: true, fixed: 'left'} {field: "id", title: "id", width: 60, sort: true, fixed: 'left'}
, {field: 'bgmid', title: 'bgmId', width: 80, edit: 'text'} , {field: 'bgmid', title: 'bgmId', width: 80, edit: 'text'}
, {field: 'title', title: '标题', edit: 'text'} , {field: 'title', title: '标题', edit: 'text'}
@ -248,6 +278,12 @@
, {field: 'update', title: '更新', width: 110, templet: '#animUpdateState'} , {field: 'update', title: '更新', width: 110, templet: '#animUpdateState'}
, {field: "right", toolbar: '#listTools'} , {field: "right", toolbar: '#listTools'}
]] ]]
}
table.render({
elem: "#passwordlist" + tabid
, url: '/anim/rss/list.do?type=' + tabid
, page: true
, cols: cols
}); });
}) })
table.on('edit(adminTable)', function (obj) { table.on('edit(adminTable)', function (obj) {
@ -306,8 +342,7 @@
, content: "删除操作无法回滚,是否确认删除:" + obj.data.title , content: "删除操作无法回滚,是否确认删除:" + obj.data.title
, btn: ['确认', '取消'] , btn: ['确认', '取消']
, yes: function (index) { , yes: function (index) {
$.post('/anim/rss/del.do', {id: obj.data.id}, function (data) { $.post('/anim/rss/del.do', {id: obj.data.id}, function (json) {
let json = JSON.parse(data);
layer.msg(json.msg) layer.msg(json.msg)
layer.close(index) layer.close(index)
}) })
@ -321,6 +356,15 @@
window.open("https://share.dmhy.org/topics/list?keyword=" + encodeURI(obj.data.titlekey)) window.open("https://share.dmhy.org/topics/list?keyword=" + encodeURI(obj.data.titlekey))
} else if (obj.event === 'bgm_src') { } else if (obj.event === 'bgm_src') {
window.open("https://bgm.tv/subject/" + obj.data.bgmid) window.open("https://bgm.tv/subject/" + obj.data.bgmid)
} else if (obj.event==='mikan'){
console.log(getParam('bangumiId',obj.data.title))
window.open('https://mikanani.me/Home/Bangumi/'+getParam('bangumiId',obj.data.title)+'#'+getParam('subgroupid',obj.data.title))
} else if (obj.event==='tmp_rss_show'){
window.open(obj.data.title)
} else if (obj.event==='tmp_rss_del'){
$.post('/anim/rss/del.do', {id: obj.data.title}, function (json) {
layer.msg(json.msg)
})
} }
}) })
table.on('tool(rssTools)', function (obj) { table.on('tool(rssTools)', function (obj) {
@ -354,8 +398,7 @@
, categories: data.categories[0] , categories: data.categories[0]
, titleKey: $('#title').val() , titleKey: $('#title').val()
, bid: tabid , bid: tabid
}, function (data) { }, function (json) {
let json = JSON.parse(data);
layer.msg(json.msg) layer.msg(json.msg)
layer.close(index) layer.close(index)
}) })
@ -456,7 +499,6 @@
function setTitle(_this) { function setTitle(_this) {
let url = "https://bgm.tv/subject_search/" + encodeURIComponent(_this.value) + "?cat=2" let url = "https://bgm.tv/subject_search/" + encodeURIComponent(_this.value) + "?cat=2"
console.log(url)
$('#bgmUrl')[0].href = url; $('#bgmUrl')[0].href = url;
} }

View File

@ -102,7 +102,10 @@ function Base64() {
} }
} }
function getParam(name){ function getParam(name){
let results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); return getParam(name,window.location.href)
}
function getParam(name,url){
let results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(url);
if (results == null) { if (results == null) {
return null; return null;
} else { } else {