Skip to content

Commit 2402ea8

Browse files
committed
app分类接口
1 parent 57248dc commit 2402ea8

File tree

11 files changed

+180
-72
lines changed

11 files changed

+180
-72
lines changed

py/tagpa.py

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
POOL = PooledDB(
1212
creator=pymysql, # 使用链接数据库的模块
1313
maxconnections=0, # 连接池允许的最大连接数,0和None表示不限制连接数
14-
mincached=20, # 初始化时,链接池中至少创建的空闲的链接,0表示不创建
14+
mincached=0, # 初始化时,链接池中至少创建的空闲的链接,0表示不创建
1515
maxcached=5, # 链接池中最多闲置的链接,0和None不限制
1616
maxshared=0, # 链接池中最多共享的链接数量,0和None表示全部共享。PS: 无用,因为pymysql和MySQLdb等模块的 threadsafety都为1,所有值无论设置为多少,_maxcached永远为0,所以永远是所有链接都共享。
1717
blocking=True, # 连接池中如果没有可用连接后,是否阻塞等待。True,等待;False,不等待然后报错
@@ -27,7 +27,7 @@
2727
charset='utf8'
2828
)
2929
proxys=[]
30-
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'}
30+
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36'}
3131
#获取代理
3232
def get_proxy(i):
3333
global proxys
@@ -44,64 +44,81 @@ def getHtml(url,p):
4444
global proxys
4545
try:
4646
i=random.randint(0,len(proxys)-1)
47-
html = requests.get(url,proxies={'http':proxys[i]},headers=header,timeout=5)
47+
proxies={'http': 'http://'+proxys[i]}
48+
html = requests.get(url,proxies=proxies,headers=header,timeout=3)
4849
if html!=None:
49-
return html.text
50+
return html
5051
except Exception:
5152
proxys.remove(proxys[i])
52-
if len(proxys)<5:
53+
if len(proxys)<2:
5354
get_proxy(10)
5455
return getHtml(url,True)
5556
else :
5657
html = requests.get(url,headers=header,timeout=5)
57-
return html.text
58+
return html
5859
def main():
60+
print("开始")
5961
global proxys
60-
get_proxy(10)
61-
print(proxys)
62-
conn = POOL.connection()
63-
cursor = conn.cursor()
64-
cursor.execute("SELECT id,pm,dy,lx,gkdz,xzdz FROM `ysb` ORDER BY `gxtime` DESC LIMIT 1000")
65-
data = cursor.fetchall()
62+
#get_proxy(10)
63+
print(getHtml("http://api.p00q.cn/ip",False).text)
64+
type("tv")
65+
type("cartoon")
66+
type("movie")
67+
print("结束")
68+
def type(t):
69+
pool = ThreadPool(10)
6670
rpool = redis.ConnectionPool(host='185.207.153.189', port=6379,db=0,password='danbairedis225')
67-
pool = ThreadPool(30)
68-
for ys in data:
71+
conn = POOL.connection()
72+
for j in range(10):
6973
try:
70-
r = redis.Redis(connection_pool=rpool)
71-
pool.apply_async(run, args=(ys,r))
74+
html=getHtml("http://v.qq.com/x/bu/pagesheet/list?_all=1&append=1&channel="+t+"&listpage=2&pagesize=30&sort=19&offset=1"+str(j*30),False)
75+
rstr=html.content.decode(encoding="utf-8", errors="strict")
76+
selector=etree.HTML(rstr)
77+
idlist=selector.xpath("//a[@class=\"figure_title figure_title_two_row bold\"]/@href")
78+
pmlist=selector.xpath("//a[@class=\"figure_title figure_title_two_row bold\"]/text()")
79+
for i in range(0,len(idlist)):
80+
cursor = conn.cursor()
81+
cursor.execute("SELECT id,pm,dy,lx,gkdz,xzdz FROM `ysb` WHERE `pm` LIKE '"+pmlist[i]+"'")
82+
data = cursor.fetchone()
83+
if(data!=None):
84+
r = redis.Redis(connection_pool=rpool)
85+
if data[4] != '[]':
86+
jys=json.loads(data[4])
87+
else :
88+
jys=json.loads(data[5])
89+
pmkey=data[1]+data[2]+data[3]
90+
tnum=r.get(pmkey)
91+
if tnum==None:
92+
tnum=0
93+
else:
94+
tnum=int(tnum)
95+
id=(re.compile("https://v.qq.com/x/cover/(.*).html").findall(idlist[i])[0])
96+
if tnum<len(jys):
97+
pool.apply_async(run, args=(id,r,jys,pmkey,data[0]))
7298
except Exception as e:
7399
print(e)
74100
pool.close()
75101
pool.join()
76-
print("结束")
77-
def run(ys,r):
78-
if ys[4] != '[]':
79-
jys=json.loads(ys[4])
80-
else :
81-
jys=json.loads(ys[5])
82-
pm=ys[1]+ys[2]+ys[3]
83-
tnum=r.get(pm)
84-
if tnum==None:
85-
tnum=0
86-
else:
87-
tnum=int(tnum)
88-
if tnum<len(jys):
89-
fh=getHtml("http://v.qq.com/x/search/?q="+pm,True)
90-
ysid=re.compile("{id: '(.*)'; type: '2';}",re.M).findall(fh)[0]
91-
fh=getHtml("http://s.video.qq.com/get_playsource?plat=2&type=4&range=1&otype=json&id="+ysid,True)
102+
def run(id,r,jys,pmkey,ysid):
103+
try:
104+
fh=getHtml("http://s.video.qq.com/get_playsource?plat=2&type=4&range=1&otype=json&id="+id,False).text
92105
jsonj=json.loads(fh[13:-1])
93106
jlist=jsonj["PlaylistItem"]["videoPlayList"]
94107
taglist=[]
95-
if jsonj["PlaylistItem"]['payType']==2:
96-
for i in range (0,len(jlist)):
97-
tfh=getHtml("http://bullet.video.qq.com/fcgi-bin/target/regist?otype=json&vid="+jlist[i]['id'],True)
98-
tagid=json.loads(tfh[13:-1])['targetid']
99-
taglist.append(tagid)
108+
for i in range (0,len(jlist)):
109+
tfh=getHtml("http://bullet.video.qq.com/fcgi-bin/target/regist?otype=json&vid="+jlist[i]['id'],False).text
110+
tagid=json.loads(tfh[13:-1])['targetid']
111+
taglist.append(tagid)
112+
if(len(taglist)>0):
100113
taglist.reverse()
101-
for i in range (0,len(jys)):
102-
r.set(pm+str(ys[0])+jys[i]['name'],taglist[i])
103-
if len(taglist) >0:
104-
print(pm+str(len(taglist)))
105-
r.set(pm,len(jys))
114+
else:
115+
return
116+
for k in range (0,len(jys)):
117+
r.set(pmkey+str(ysid)+jys[k]['name'],taglist[k])
118+
if len(taglist) >0:
119+
print(pmkey+str(len(taglist)))
120+
r.set(pmkey,len(taglist))
121+
except Exception as e:
122+
print(e)
106123
if __name__ == "__main__":
107124
main()

src/main/java/com/danbai/ys/controller/restful/v1/Ys.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.web.bind.annotation.*;
88

9+
import javax.validation.constraints.NotBlank;
10+
import javax.validation.constraints.NotNull;
11+
912

1013
/**
1114
* rest 风格 api
@@ -56,4 +59,9 @@ public BaseResult search(@PathVariable String gjc) {
5659
public BaseResult tv(){
5760
return ResultUtil.success(ysService.getAllTv());
5861
}
62+
@GetMapping("ys/type")
63+
public BaseResult type(String type1, String type2, String region,String year,String sort,@NotNull int page){
64+
65+
return ResultUtil.success(ysService.getByType(type1,type2,region,year,sort,page));
66+
}
5967
}

src/main/java/com/danbai/ys/mapper/YsbMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
import org.apache.ibatis.annotations.CacheNamespace;
77
import org.springframework.stereotype.Repository;
88

9+
import java.util.List;
10+
911
/**
1012
* @author danbai
1113
*/
1214

1315
@Repository
1416
@CacheNamespace(implementation = RedisCache.class)
1517
public interface YsbMapper extends MyMapper<Ysb> {
18+
List<Ysb> getByType(String type1, String type2, String region, String year, String sort);
1619
}

src/main/java/com/danbai/ys/service/YsService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,15 @@ public interface YsService {
161161
* @return list
162162
*/
163163
List<Ysb> getNewYsb(int num);
164+
165+
/**
166+
* 根据分类获取影视
167+
* @param type1 影视类型1 电视剧、电影、动漫、综艺
168+
* @param type2 影视类型2 爱情 恐怖 科幻
169+
* @param region 地区 国产 韩国 欧美
170+
* @param year 年份 2019
171+
* @param sort 排序规则 热度 或 评分
172+
* @return list
173+
*/
174+
List<Ysb> getByType(String type1,String type2,String region,String year,String sort,int page);
164175
}

src/main/java/com/danbai/ys/service/impl/UserServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public boolean yzUser(User user, HttpServletRequest request, HttpServletResponse
8484
user2.setPassword("password");
8585
sessoin.setAttribute("user", user2);
8686
Cookie cookie = new Cookie("JSESSIONID", sessoin.getId());
87-
cookie.setMaxAge(60 * 60 * 24);
87+
cookie.setMaxAge(60 * 60 * 24*7);
8888
response.addCookie(cookie);
8989
return true;
9090
}
@@ -181,7 +181,7 @@ public boolean checkToken(Token token) {
181181
return false;
182182
}
183183
Token rtoken = (Token) redisTemplate.opsForValue().get(Token.TOKEN+token.getUsername());
184-
if(rtoken.getToken().equals(token.getToken())){
184+
if(rtoken!=null&&rtoken.getToken().equals(token.getToken())){
185185
// 如果验证成功,说明此用户进行了一次有效操作,延长 token 的过期时间
186186
redisTemplate.expire(Token.TOKEN+token.getUsername (),7, TimeUnit.DAYS);
187187
return true;

src/main/java/com/danbai/ys/service/impl/YsServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,12 @@ public List<Ysb> getNewYsb(int num) {
289289
example.setOrderByClause("gxtime DESC limit 0,"+num);
290290
return ysbMapper.selectByExample(example);
291291
}
292+
293+
@Override
294+
public List<Ysb> getByType(String type1, String type2, String region, String year, String sort,int page) {
295+
PageHelper.startPage(page, 20).getPages();
296+
List<Ysb> ysbs = ysbMapper.getByType(type1,type2,region,year,sort);
297+
PageInfo pages = new PageInfo(ysbs);
298+
return pages.getList();
299+
}
292300
}

src/main/java/com/danbai/ys/utils/RedisCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class RedisCache implements Cache {
2222
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
2323
private final String id;
2424
RedisTemplate redisTemplate;
25-
private static final long EXPIRE_TIME_IN_MINUTES = 30;
25+
private static final long EXPIRE_TIME_IN_MINUTES = 5;
2626
// redis过期时间
2727

2828
public RedisCache(String id) {

src/main/java/com/danbai/ys/websocket/CinemaSocket.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void onOpen(Session session, @PathParam("username") String username) {
5555
this.username=username;
5656
if(DELETE_P00L.containsKey(username)){
5757
this.roomId=DELETE_P00L.get(username);
58+
DELETE_P00L.remove(username);
5859
}
5960
//加入POOL中
6061
POOL.put(session.getId(),this);
@@ -79,9 +80,9 @@ public void onClose(Session session) {
7980
CinemaSocket cinemaSocket = POOL.get(session.getId());
8081
if(cinemaSocket!=null){
8182
DELETE_P00L.put(cinemaSocket.getUsername(),cinemaSocket.roomId);
82-
if(cinemaSocket.roomId!=0){
83-
CinemaSocketManagement.exitRoom(session.getId());
84-
}
83+
if(cinemaSocket.roomId!=0){
84+
CinemaSocketManagement.exitRoom(session.getId());
85+
}
8586
}
8687
POOL.remove(session.getId());
8788
log.info("有一连接关闭!当前在线人数为" + POOL.size());
@@ -175,8 +176,9 @@ public Session getSession() {
175176
public void setSession(Session session) {
176177
this.session = session;
177178
}
178-
@Scheduled(cron="0/5 * * * * ? ")
179+
@Scheduled(cron="0 */1 * * * ?")
179180
public void examine(){
181+
DELETE_P00L.clear();
180182
//删除断开的链接
181183
POOL.forEach((id,e)->{
182184
if(!e.session.isOpen()){
Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,69 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
33
<mapper namespace="com.danbai.ys.mapper.YsbMapper">
4-
<resultMap id="BaseResultMap" type="com.danbai.ys.entity.Ysb">
5-
<!--
6-
WARNING - @mbg.generated
7-
-->
8-
<id column="id" jdbcType="INTEGER" property="id" />
9-
<result column="pf" jdbcType="REAL" property="pf" />
10-
<result column="pm" jdbcType="LONGVARCHAR" property="pm" />
11-
<result column="tp" jdbcType="LONGVARCHAR" property="tp" />
12-
<result column="zt" jdbcType="LONGVARCHAR" property="zt" />
13-
<result column="bm" jdbcType="LONGVARCHAR" property="bm" />
14-
<result column="dy" jdbcType="LONGVARCHAR" property="dy" />
15-
<result column="zy" jdbcType="LONGVARCHAR" property="zy" />
16-
<result column="lx" jdbcType="LONGVARCHAR" property="lx" />
17-
<result column="dq" jdbcType="LONGVARCHAR" property="dq" />
18-
<result column="yy" jdbcType="LONGVARCHAR" property="yy" />
19-
<result column="sytime" jdbcType="LONGVARCHAR" property="sytime" />
20-
<result column="pctime" jdbcType="LONGVARCHAR" property="pctime" />
21-
<result column="gxtime" jdbcType="LONGVARCHAR" property="gxtime" />
22-
<result column="js" jdbcType="LONGVARCHAR" property="js" />
23-
<result column="gkdz" jdbcType="LONGVARCHAR" property="gkdz" />
24-
<result column="xzdz" jdbcType="LONGVARCHAR" property="xzdz" />
25-
</resultMap>
4+
<resultMap id="BaseResultMap" type="com.danbai.ys.entity.Ysb">
5+
<!--
6+
WARNING - @mbg.generated
7+
-->
8+
<id column="id" jdbcType="INTEGER" property="id"/>
9+
<result column="pf" jdbcType="REAL" property="pf"/>
10+
<result column="pm" jdbcType="LONGVARCHAR" property="pm"/>
11+
<result column="tp" jdbcType="LONGVARCHAR" property="tp"/>
12+
<result column="zt" jdbcType="LONGVARCHAR" property="zt"/>
13+
<result column="bm" jdbcType="LONGVARCHAR" property="bm"/>
14+
<result column="dy" jdbcType="LONGVARCHAR" property="dy"/>
15+
<result column="zy" jdbcType="LONGVARCHAR" property="zy"/>
16+
<result column="lx" jdbcType="LONGVARCHAR" property="lx"/>
17+
<result column="dq" jdbcType="LONGVARCHAR" property="dq"/>
18+
<result column="yy" jdbcType="LONGVARCHAR" property="yy"/>
19+
<result column="sytime" jdbcType="LONGVARCHAR" property="sytime"/>
20+
<result column="pctime" jdbcType="LONGVARCHAR" property="pctime"/>
21+
<result column="gxtime" jdbcType="LONGVARCHAR" property="gxtime"/>
22+
<result column="js" jdbcType="LONGVARCHAR" property="js"/>
23+
<result column="gkdz" jdbcType="LONGVARCHAR" property="gkdz"/>
24+
<result column="xzdz" jdbcType="LONGVARCHAR" property="xzdz"/>
25+
</resultMap>
26+
<select id="getByType" resultMap="BaseResultMap">
27+
SELECT * FROM `ysb` WHERE
28+
<choose>
29+
<when test="param1 == '电影'">
30+
(`zt` LIKE '%H%' OR '%B%')
31+
</when>
32+
<when test="param1 == '电视剧'">
33+
(`zt` LIKE '%完结%' OR '%集%')
34+
</when>
35+
<when test="param1 == '综艺'">
36+
(`lx` LIKE '%综艺%')
37+
</when>
38+
<when test="param1 == '动漫'">
39+
(`lx` LIKE '%动漫%')
40+
</when>
41+
</choose>
42+
<if test="param2 !='' and param2 !='全部'">
43+
AND `lx` LIKE '%${param2}%'
44+
</if>
45+
<if test="param3 !='' and param3 !='全部'">
46+
<choose>
47+
<when test="param3=='国产'">
48+
AND (`dq` LIKE '%大陆%' OR '%中国%' OR '%香港%' OR '%台湾%')
49+
</when>
50+
<otherwise>
51+
AND `dq` LIKE '%${param3}%'
52+
</otherwise>
53+
</choose>
54+
</if>
55+
<if test="param4 !='' and param4 !='全部'">
56+
AND `sytime` LIKE '%${param4}'
57+
</if>
58+
59+
<choose>
60+
<when test="param5 =='更新'">
61+
ORDER BY `gxtime` DESC
62+
</when>
63+
<when test="param5 =='评分'">
64+
ORDER BY `pf` DESC
65+
</when>
66+
</choose>
67+
68+
</select>
2669
</mapper>

src/test/java/com/danbai/ys/YsApplicationTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import com.alibaba.fastjson.JSONObject;
44
import com.danbai.ys.entity.UpdateInfo;
5+
import com.danbai.ys.entity.User;
56
import com.danbai.ys.entity.VideoTime;
67
import com.danbai.ys.entity.Ysb;
78
import com.danbai.ys.mapper.VideoTimeMapper;
9+
import com.danbai.ys.service.impl.UserServiceImpl;
810
import com.danbai.ys.service.impl.YsServiceImpl;
911
import com.danbai.ys.utils.HtmlUtils;
12+
import com.danbai.ys.utils.Md5;
1013
import com.danbai.ys.utils.SiteMapUtils;
1114
import org.junit.Test;
1215
import org.junit.runner.RunWith;
@@ -32,6 +35,8 @@ public class YsApplicationTests {
3235
SiteMapUtils siteMapUtils;
3336
@Autowired
3437
VideoTimeMapper videoTimeMapper;
38+
@Autowired
39+
UserServiceImpl userService;
3540
@Test
3641
public void test() {
3742
System.out.println(redisTemplate.opsForValue().get("gg"));
@@ -67,4 +72,15 @@ public void appgx(){
6772
public void gkls(){
6873
ysService.getGkls("danbai");
6974
}
75+
@Test
76+
public void user(){
77+
System.out.println(Md5.getMD5LowerCase("是撒1"));
78+
}
79+
@Test
80+
public void getYsByType(){
81+
List<Ysb> byType = ysService.getByType("电影", "全部", "国产", "全部","评分",1);
82+
byType.forEach(ysb -> {
83+
System.out.println(ysb.getDy());
84+
});
85+
}
7086
}

0 commit comments

Comments
 (0)