admin
2021-08-13 cdc3690a0354e01b44852f4c9da3b7204128d2eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.yeshi.buwan.util.video;
 
import java.util.List;
 
import org.apache.log4j.Logger;
 
import com.yeshi.buwan.dao.base.BaseDao;
import com.yeshi.buwan.domain.YouKuVideoUrl;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
public class UCVideoParser {
 
    static Logger logger = Logger.getLogger(UCVideoParser.class);
 
    public static String parseData(String result) {
        JSONObject object =JSONObject.fromObject(result);
        JSONObject data = object.optJSONObject("data");
        JSONArray array = data.optJSONArray("videoList");
        if (array != null && array.size() > 0) {
            JSONObject obj = array.optJSONObject(0);
            JSONArray fa = obj.optJSONArray("fragment");
            if (fa.size() > 1)
                logger.info(result);
            return fa.optJSONObject(0).optString("url");
        }
        logger.error(result);
        return "";
    }
 
    public static String getRequestUrl(String url) {
        return "http://m.uczzd.cn/iflow/api/v1/article/video/parse?pageUrl="
                + (url.contains("?") ? url.split("\\?")[0] : url);
    }
 
    public static YouKuVideoUrl getYouKuVideo(String url) {
        BaseDao<YouKuVideoUrl> dao = new BaseDao<YouKuVideoUrl>();
        List<YouKuVideoUrl> list = dao.list(
                "from YouKuVideoUrl yk where yk.url=?",
                new String[] { url.contains("?") ? url.split("\\?")[0] : url });
        if (list != null && list.size() > 0)
            return list.get(0);
        else
            return null;
    }
 
    public static void updateYouKuVideo(String url, String realUrl) {
        BaseDao<YouKuVideoUrl> dao = new BaseDao<YouKuVideoUrl>();
        List<YouKuVideoUrl> list = dao.list(
                "from YouKuVideoUrl yk where yk.url=?",
                new String[] { url.contains("?") ? url.split("\\?")[0] : url });
        if (list != null && list.size() > 0) {
            list.get(0).setRealurl(realUrl);
            list.get(0).setUpdatetime(System.currentTimeMillis() + "");
            dao.update(list.get(0));
        } else {
            YouKuVideoUrl yv = new YouKuVideoUrl();
            yv.setRealurl(realUrl);
            yv.setUpdatetime(System.currentTimeMillis() + "");
            yv.setUrl(url.contains("?") ? url.split("\\?")[0] : url);
            dao.create(yv);
        }
    }
}