admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
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
package com.yeshi.buwan.util.video;
 
import java.util.List;
 
import org.hibernate.Session;
import org.springframework.stereotype.Component;
 
import com.yeshi.buwan.dao.base.BaseDao;
import com.yeshi.buwan.domain.BiliBiliUrlId;
import com.yeshi.buwan.util.HibernateSessionFactory;
 
import net.sf.json.JSONObject;
 
@Component
public class BiliBiliParser {
 
    static HibernateSessionFactory hibernateSessionFactory;
 
    public static String getRequestUrl(String aid) {
        return "http://www.bilibili.com/m/html5?aid=" + aid + "&page=1";
    }
 
    public static JSONObject getRequestHeader(String aid) {
        JSONObject header = new JSONObject();
        header.put("Referer", "http://www.bilibili.com/mobile/juhe/av" + aid + ".html");
        return header;
    }
 
    public static String getRealUrl(String result) {
        JSONObject object = JSONObject.fromObject(result);
        return object.optString("src");
    }
 
    public static BiliBiliUrlId getUrlIdsByAid(String aid) {
        BaseDao<BiliBiliUrlId> dao = new BaseDao<BiliBiliUrlId>();
        List<BiliBiliUrlId> list = dao.list("from BiliBiliUrlId b where b.aid=?", new String[] { aid });
        if (list != null && list.size() > 0)
            return list.get(0);
        return null;
    }
 
    @SuppressWarnings("rawtypes")
    public static void saveUrlIds(BiliBiliUrlId bu) {
        Session session = hibernateSessionFactory.getSession();
        try {
            session.getTransaction().begin();
            List list = session.createQuery("from BiliBiliUrlId b where b.id=?").setParameter(0, bu.getAid()).list();
            if (list == null || list.size() == 0) {
                session.persist(bu);
            }
            session.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
    }
 
    public static void updateUrlIds(BiliBiliUrlId bu) {
        BaseDao<BiliBiliUrlId> dao = new BaseDao<BiliBiliUrlId>();
        dao.update(bu);
    }
 
}