├── src
└── main
│ ├── resources
│ └── application.yml
│ └── java
│ └── com
│ └── rjt
│ ├── video
│ ├── service
│ │ ├── VideoService.java
│ │ └── impl
│ │ │ ├── VideoFactory.java
│ │ │ ├── HuoShanServiceImpl.java
│ │ │ ├── PiPiXServiceImpl.java
│ │ │ ├── KuaiShouServiceImpl.java
│ │ │ ├── WeiShiServiceImpl.java
│ │ │ ├── ZuiYouServiceImpl.java
│ │ │ └── DouyinServiceImpl.java
│ ├── model
│ │ └── VideoModel.java
│ └── controller
│ │ └── VideoController.java
│ ├── MainApplication.java
│ └── common
│ └── util
│ ├── JsonUtil.java
│ └── TextUtil.java
└── pom.xml
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 80
3 | servlet:
4 | context-path: /
--------------------------------------------------------------------------------
/src/main/java/com/rjt/video/service/VideoService.java:
--------------------------------------------------------------------------------
1 | package com.rjt.video.service;
2 |
3 | import com.rjt.video.model.VideoModel;
4 |
5 | /**
6 | * @comment
7 | * @author tanran
8 | * @date 2019年6月14日
9 | * @version 1.0
10 | */
11 | public interface VideoService {
12 | public VideoModel parseUrl(String url);
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/rjt/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.rjt;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 |
7 | @SpringBootApplication
8 | public class MainApplication {
9 | public static void main(String[] args) {
10 | SpringApplication.run(MainApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/rjt/video/model/VideoModel.java:
--------------------------------------------------------------------------------
1 | package com.rjt.video.model;
2 |
3 | public class VideoModel {
4 | //视频名
5 | private String name;
6 | //视频背景
7 | private String cover;
8 | //无水印地址
9 | private String playAddr;
10 | /**
11 | * @return the name
12 | */
13 | public String getName() {
14 | return name;
15 | }
16 | /**
17 | * @param name the name to set
18 | */
19 | public void setName(String name) {
20 | this.name = name;
21 | }
22 | /**
23 | * @return the cover
24 | */
25 | public String getCover() {
26 | return cover;
27 | }
28 | /**
29 | * @param cover the cover to set
30 | */
31 | public void setCover(String cover) {
32 | this.cover = cover;
33 | }
34 | /**
35 | * @return the playAddr
36 | */
37 | public String getPlayAddr() {
38 | return playAddr;
39 | }
40 | /**
41 | * @param playAddr the playAddr to set
42 | */
43 | public void setPlayAddr(String playAddr) {
44 | this.playAddr = playAddr;
45 | }
46 | @Override
47 | public String toString() {
48 | return "VideoModel [name=" + name + ", cover=" + cover + ", playAddr=" + playAddr + "]";
49 | }
50 |
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/rjt/video/controller/VideoController.java:
--------------------------------------------------------------------------------
1 | package com.rjt.video.controller;
2 |
3 | import java.util.Objects;
4 |
5 | import org.springframework.web.bind.annotation.CrossOrigin;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import com.rjt.video.model.VideoModel;
11 | import com.rjt.video.service.VideoService;
12 | import com.rjt.video.service.impl.VideoFactory;
13 |
14 | /**
15 | * @comment
16 | * @author tanran
17 | * @date 2019年6月14日
18 | * @version 1.0
19 | */
20 | @RestController
21 | @RequestMapping("video")
22 | @CrossOrigin
23 | public class VideoController {
24 | @GetMapping("parse")
25 | public VideoModel parse(String url) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
26 | VideoService videoService = VideoFactory.getVideo(url);
27 | if(Objects.isNull(videoService)) {
28 | return new VideoModel();
29 | }
30 | return videoService.parseUrl(url);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/rjt/video/service/impl/VideoFactory.java:
--------------------------------------------------------------------------------
1 | package com.rjt.video.service.impl;
2 |
3 | import com.rjt.video.service.VideoService;
4 |
5 | public class VideoFactory {
6 | public static VideoService getVideo(String type)
7 | throws InstantiationException, IllegalAccessException, ClassNotFoundException {
8 |
9 | if (type.indexOf("douyin.com") != -1 || type.indexOf("iesdouyin.com") != -1 ) {
10 |
11 | return DouyinServiceImpl.class.newInstance();
12 |
13 | } else if (type.indexOf("huoshan.com") != -1 ) {
14 |
15 | return HuoShanServiceImpl.class.newInstance();
16 |
17 | } else if (type.indexOf("kuaishou.com") != -1 || type.indexOf("gifshow.com") != -1 || type.indexOf("chenzhongtech.com") != -1) {
18 |
19 | return KuaiShouServiceImpl.class.newInstance();
20 |
21 | } else if (type.indexOf("pipix.com") != -1) {
22 |
23 | return PiPiXServiceImpl.class.newInstance();
24 |
25 | } else if (type.indexOf("weishi.qq.com")!= -1 ) {
26 |
27 | return WeiShiServiceImpl.class.newInstance();
28 |
29 | }else if (type.indexOf("izuiyou.com") != -1) {
30 |
31 | return ZuiYouServiceImpl.class.newInstance();
32 |
33 | } else {
34 | System.out.println("哎呀!找不到相应的实例化类啦!");
35 | return null;
36 | }
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/rjt/common/util/JsonUtil.java:
--------------------------------------------------------------------------------
1 | package com.rjt.common.util;
2 |
3 | import org.springframework.util.StringUtils;
4 |
5 | import com.alibaba.fastjson.JSON;
6 |
7 |
8 |
9 | public class JsonUtil {
10 | /**
11 | * 将json格式化为字符串,然后根据key取值
12 | * @param jsonStr
13 | * @param key
14 | * @return
15 | */
16 | public static String getJsonValue(String jsonStr,String key) {
17 | if(StringUtils.isEmpty(jsonStr) || StringUtils.isEmpty(key)) {
18 | return "";
19 | }
20 | if(key.indexOf(".")==-1) {
21 | if(key.indexOf("[")!=-1) {
22 | int num =Integer.parseInt(TextUtil.getSubString(key, "[", "]"));
23 | key=key.substring(0, key.indexOf("["));
24 | return JSON.parseObject(jsonStr).getJSONArray(key).getString(num);
25 | }else {
26 | return JSON.parseObject(jsonStr).getString(key);
27 | }
28 |
29 | }else {
30 | String[] keys = key.split("\\.");
31 | for(int i=0;i", "
"); 100 | request.disconnect(); 101 | return place; 102 | } 103 | 104 | /** 105 | * 根据地址获取纬度 106 | * 107 | * @param 108 | * @return 109 | * @throws UnsupportedEncodingException 110 | */ 111 | public static String getWd(String place) throws UnsupportedEncodingException { 112 | String url = "http://apis.map.qq.com/jsapi?qt=poi&wd=" + URLEncoder.encode(place, "utf8"); 113 | HttpRequest request = HttpRequest.get(url, true); 114 | String res = request.body(); 115 | request.disconnect(); 116 | return handResult(res); 117 | } 118 | 119 | /** 120 | * 处理数据 121 | * 122 | * @param res 123 | * @return 124 | */ 125 | private static String handResult(String res) { 126 | JSONObject json = JSON.parseObject(res); 127 | json = JSON.parseObject(json.get("detail").toString()); 128 | JSONArray jsonArray = JSON.parseArray((json.get("pois").toString())); 129 | int ranNum = getRandomNumRang(jsonArray.size()); 130 | json = JSON.parseObject(jsonArray.get(ranNum).toString()); 131 | return json.get("pointx") + "," + json.get("pointy"); 132 | } 133 | 134 | public static void main(String[] args) throws UnsupportedEncodingException { 135 | int a=0; 136 | for (int i=0;i<100;i++){ 137 | String ee= getRandomNum(1); 138 | if(ee.equals("8")){ 139 | System.out.println(a++); 140 | } 141 | } 142 | } 143 | /** 144 | * 根据ip获取维度和精度 145 | * @param 146 | * @return 147 | * @throws UnsupportedEncodingException 148 | */ 149 | public static String getWd(HttpServletRequest request) throws UnsupportedEncodingException { 150 | String remortIP = getRemortIP(request); 151 | logger.info("remortIP 为{}",remortIP); 152 | String place = getPlace(remortIP); 153 | logger.info("place 为{}",place); 154 | String wd="112.537170,37.874690"; 155 | try { 156 | wd = getWd(place); 157 | } catch (Exception e) { 158 | // TODO: handle exception 159 | logger.info("e 为{}",e); 160 | } 161 | 162 | logger.info("wd 为{}",wd); 163 | return wd; 164 | } 165 | /** 166 | * 取随机数字 167 | * 168 | * @param num 169 | * @return 170 | */ 171 | public static String getRandomNum(int num) { 172 | StringBuffer sb = new StringBuffer(); 173 | for (int i = 0; i < num; i++) { 174 | Random rnd = new Random(); 175 | sb.append(rnd.nextInt(9)); 176 | } 177 | return sb.toString(); 178 | } 179 | 180 | /** 181 | * 根据范围取随机数字 182 | * 183 | * @param 184 | * @return 185 | */ 186 | public static int getRandomNumRang(int end) { 187 | Random rnd = new Random(); 188 | return rnd.nextInt(end); 189 | } 190 | 191 | 192 | 193 | public static String makeImei () { 194 | String imeiString=TextUtil.getRandomNum(14); 195 | char[] imeiChar=imeiString.toCharArray(); 196 | int resultInt=0; 197 | for (int i = 0; i < imeiChar.length; i++) { 198 | int a=Integer.parseInt(String.valueOf(imeiChar[i])); 199 | i++; 200 | final int temp=Integer.parseInt(String.valueOf(imeiChar[i]))*2; 201 | final int b=temp<10?temp:temp-9; 202 | resultInt+=a+b; 203 | } 204 | resultInt%=10; 205 | resultInt=resultInt==0?0:10-resultInt; 206 | return imeiString+resultInt; 207 | } 208 | } 209 | --------------------------------------------------------------------------------