├── 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 2 | 4 | 4.0.0 5 | 6 | com 7 | rjt 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | main 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.6.RELEASE 17 | 18 | 19 | 20 | 21 | UTF-8 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-devtools 34 | runtime 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | com.bladejava 43 | blade-kit 44 | 1.2.9-alpha 45 | 46 | 47 | com.alibaba 48 | fastjson 49 | 1.2.47 50 | 51 | 52 | org.jsoup 53 | jsoup 54 | 1.11.3 55 | 56 | 57 | com.squareup.okhttp3 58 | okhttp 59 | 3.14.2 60 | 61 | 62 | 63 | 64 | ${project.artifactId} 65 | 66 | 67 | org.springframework.boot 68 | spring-boot-maven-plugin 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/main/java/com/rjt/video/service/impl/DouyinServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.rjt.video.service.impl; 2 | 3 | import okhttp3.OkHttpClient; 4 | import okhttp3.Request; 5 | import okhttp3.Response; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.rjt.common.util.JsonUtil; 9 | import com.rjt.common.util.TextUtil; 10 | import com.rjt.video.model.VideoModel; 11 | import com.rjt.video.service.VideoService; 12 | 13 | import blade.kit.http.HttpRequest; 14 | 15 | /** 16 | * @comment 17 | * @author tanran 18 | * @date 2019年6月14日 19 | * @version 1.0 20 | */ 21 | @Service 22 | public class DouyinServiceImpl implements VideoService{ 23 | 24 | @Override 25 | public VideoModel parseUrl(String url) { 26 | // TODO Auto-generated method stub 27 | VideoModel videoModel=new VideoModel(); 28 | try { 29 | OkHttpClient okHttpClient = new OkHttpClient(); 30 | Request request = new Request.Builder().url(url).header("User-Agent","Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1").build(); 31 | Response response = okHttpClient.newCall(request).execute(); 32 | String result=response.body().string(); 33 | String vid=TextUtil.getSubString(result,"itemId:",",").trim(); 34 | String dytk=TextUtil.getSubString(result,"dytk:","}").trim(); 35 | vid=vid.substring(1,vid.length()-1); 36 | dytk=dytk.substring(1,dytk.length()-1); 37 | url="https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+vid+"&dytk="+dytk; 38 | request = new Request.Builder().url(url).header("User-Agent","Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1").build(); 39 | response = okHttpClient.newCall(request).execute(); 40 | result=response.body().string(); 41 | System.out.println(result); 42 | String title = JsonUtil.getJsonValue(result, "item_list[0].desc"); 43 | String playAddr = JsonUtil.getJsonValue(result, "item_list[0].video.play_addr_lowbr.url_list[0]"); 44 | String cover = JsonUtil.getJsonValue(result, "item_list[0].video.origin_cover.url_list[0]"); 45 | request = new Request.Builder().url(playAddr).header("User-Agent","Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1").build(); 46 | response = okHttpClient.newCall(request).execute(); 47 | result=response.body().string(); 48 | result="Found"; 49 | playAddr=TextUtil.getSubString(result,"\"","\""); 50 | videoModel.setName(title); 51 | videoModel.setPlayAddr(playAddr); 52 | videoModel.setCover(cover); 53 | 54 | }catch (Exception e){ 55 | e.printStackTrace(); 56 | } 57 | return videoModel; 58 | } 59 | public static void main(String[] args) { 60 | System.out.println(new DouyinServiceImpl().parseUrl("http://v.douyin.com/r2w3sN/")); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/rjt/common/util/TextUtil.java: -------------------------------------------------------------------------------- 1 | package com.rjt.common.util; 2 | 3 | import blade.kit.http.HttpRequest; 4 | import com.alibaba.fastjson.JSON; 5 | import com.alibaba.fastjson.JSONArray; 6 | import com.alibaba.fastjson.JSONObject; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import java.io.UnsupportedEncodingException; 12 | import java.net.URLEncoder; 13 | import java.util.Random; 14 | 15 | 16 | public class TextUtil { 17 | 18 | private static Logger logger = LoggerFactory.getLogger(TextUtil.class); 19 | /** 20 | * 取两个文本之间的文本值 21 | * 22 | * @param text 23 | * @param left 24 | * @param right 25 | * @return 26 | */ 27 | public static String getSubString(String text, String left, String right) { 28 | String result = ""; 29 | int zLen; 30 | if (left == null || left.isEmpty()) { 31 | zLen = 0; 32 | } else { 33 | zLen = text.indexOf(left); 34 | if (zLen > -1) { 35 | zLen += left.length(); 36 | } else { 37 | zLen = 0; 38 | } 39 | } 40 | int yLen = text.indexOf(right, zLen); 41 | if (yLen < 0 || right == null || right.isEmpty()) { 42 | yLen = text.length(); 43 | } 44 | result = text.substring(zLen, yLen); 45 | return result; 46 | } 47 | 48 | /** 49 | * 获取ip 50 | * 51 | * @param request 52 | * @return 53 | */ 54 | public static String getRemortIP(HttpServletRequest request) { 55 | 56 | String ip = request.getHeader("x-forwarded-for"); 57 | if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) { 58 | // 多次反向代理后会有多个ip值,第一个ip才是真实ip 59 | if( ip.indexOf(",")!=-1 ){ 60 | ip = ip.split(",")[0]; 61 | } 62 | } 63 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 64 | ip = request.getHeader("Proxy-Client-IP"); 65 | } 66 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 67 | ip = request.getHeader("WL-Proxy-Client-IP"); 68 | } 69 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 70 | ip = request.getHeader("HTTP_CLIENT_IP"); 71 | } 72 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 73 | ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 74 | } 75 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 76 | ip = request.getHeader("X-Real-IP"); 77 | } 78 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 79 | ip = request.getRemoteAddr(); 80 | } 81 | return ip; 82 | } 83 | 84 | /** 85 | * 根据ip获取地址 86 | * 87 | * @param 88 | * @return 89 | * @throws UnsupportedEncodingException 90 | */ 91 | public static String getPlace(String ip) throws UnsupportedEncodingException { 92 | if (ip.indexOf(", ") != -1) { 93 | ip = ip.split(", ")[1]; 94 | } 95 | String url = "https://ip.cn/index.php?ip=" + ip; 96 | HttpRequest request = HttpRequest.get(url, true).header("User-Agent", 97 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0"); 98 | String res = request.body(); 99 | String place = TextUtil.getSubString(res, "置:", "

"); 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 | --------------------------------------------------------------------------------