# -*- coding:utf-8 -*-
# @Time : 2019/8/27 16:24 
# @Author : litao
import re

def calculate_haokan_id(data_dic):
    url = data_dic.get("url")
    # if data_dic.get("video_id"):
    #     return data_dic["video_id"]
    if "id=" in url:
        find_vid = re.findall('id=(\d+)', url)
        return find_vid[0]
    elif "context=%7B%22nid%22%3A%22sv_" in url:
        find_vid = re.findall('context=%7B%22nid%22%3A%22sv_(.+)%22%7D', url)
        return find_vid[0]
    else:
        return url


if __name__ == '__main__':
    print(calculate_haokan_id({"url":"https://sv.baidu.com/videoui/page/videoland?context=%7B%22nid%22%3A%22sv_5091548046938576131%22%7D"}))
    print(calculate_haokan_id({"url":"https://haokan.baidu.com/v?vid=4596161678511752193"}))