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 66 67 68
| import re import requests
from urllib import parse
requests.packages.urllib3.disable_warnings()
def handle_share_content(share_content: str) -> str: """ 从App端分享信息中提取分享作品短链接 :param share_content: :return: """ url_regular = re.compile(r"(https|http)?:\/\/(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)*([0-9a-zA-Z]" r"[0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\.[0-9a-zA-Z]{2,6})(:[0-9a-zA-Z]{1,4})?" r"((\/[0-9a-zA-Z_!~*().;?:@&=+$,%#-]*)+)?") result = url_regular.search(share_content) if result: if result.group(0) in share_content: return result.group(0).strip() else: raise ValueError('请输入标准的抖音分享信息') else: raise ValueError('请输入标准的抖音分享信息')
def resolve_share_url(share_url: str) -> str: """ 解析分享链接,提取作品ID :param share_url: :return: """ resp = requests.get(share_url, verify=False) url_data = parse.unquote(resp.url) result = parse.urlparse(url_data) video_id = str(result.path).split('/')[-2] if video_id.isdigit(): return video_id else: raise ValueError('获取作品ID异常,请检查连接:%s是否为抖音分享链接。' % share_url)
def get_tiktok_item_info(share_content: str) -> dict: share_url = handle_share_content(share_content) item_id = resolve_share_url(share_url)
response = requests.get("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/", params={'item_ids': item_id}, verify=False, timeout=5).json()
if response['status_code'] == 0 and len(response['item_list']) > 0: return response['item_list'][0] else: raise RuntimeError('获取抖音Api数据失败,%s' % response)
data = '尝试臭豆腐肥肠火锅?这味道简直太太太上头了!!%vlog日常 %美食探店 %火锅 %深夜放毒 %美食趣胃计划' \ 'https://v.douyin.com/eNBofpr/ 椱制此链接,打开Dou吟搜索,直接觀看视频!'
info = get_tiktok_item_info(share_content=data) print(info)
{'is_live_replay': False, 'video_labels': None, 'geofencing': None, 'group_id': 6942073391922843000, 'forward_id': '0', 'author': {'policy_version': None, 'uid': '76615500441', 'short_id': '2262937117', 'avatar_thumb': {'uri': '100x100/20b7b00015cd04a8ec0cb', 'url_list': ['https://p5-ipv6.douyinpic.com/aweme/100x100/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p6.douyinpic.com/aweme/100x100/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p11.douyinpic.com/aweme/100x100/20b7b00015cd04a8ec0cb.jpeg?from=2563711402']}, 'avatar_medium': {'uri': '720x720/20b7b00015cd04a8ec0cb', 'url_list': ['https://p3.douyinpic.com/aweme/720x720/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p29.douyinpic.com/aweme/720x720/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p26.douyinpic.com/aweme/720x720/20b7b00015cd04a8ec0cb.jpeg?from=2563711402']}, 'unique_id': 'xiaozhuzhu2334', 'platform_sync_info': None, 'nickname': '帅气的悉尼小猪猪', 'signature': '🧣同名\n合作:taozi484520(只接星图)', 'avatar_larger': {'uri': '1080x1080/20b7b00015cd04a8ec0cb', 'url_list': ['https://p3.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p5-ipv6.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p26.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402']}, 'followers_detail': None, 'geofencing': None, 'type_label': None}, 'video': {'origin_cover': {'uri': 'tos-cn-p-0015/8111a1cf615e48d8a06d8363c91e8250_1616327449', 'url_list': ['https://p29.douyinpic.com/tos-cn-p-0015/8111a1cf615e48d8a06d8363c91e8250_1616327449~tplv-dy-360p.jpeg?from=2563711402', 'https://p6.douyinpic.com/tos-cn-p-0015/8111a1cf615e48d8a06d8363c91e8250_1616327449~tplv-dy-360p.jpeg?from=2563711402', 'https://p5-ipv6.douyinpic.com/tos-cn-p-0015/8111a1cf615e48d8a06d8363c91e8250_1616327449~tplv-dy-360p.jpeg?from=2563711402']}, 'ratio': '720p', 'duration': 90139, 'is_long_video': 1, 'play_addr': {'uri': 'v0200fcf0000c1bj4fmluf3igni150tg', 'url_list': ['https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0200fcf0000c1bj4fmluf3igni150tg&ratio=720p&line=0']}, 'cover': {'url_list': ['https://p29.douyinpic.com/img/tos-cn-p-0015/fdabcc862cbc4698a4ee4feb42a9ee27~c5_300x400.jpeg?from=2563711402_large', 'https://p26.douyinpic.com/img/tos-cn-p-0015/fdabcc862cbc4698a4ee4feb42a9ee27~c5_300x400.jpeg?from=2563711402_large', 'https://p5-ipv6.douyinpic.com/img/tos-cn-p-0015/fdabcc862cbc4698a4ee4feb42a9ee27~c5_300x400.jpeg?from=2563711402_large'], 'uri': 'tos-cn-p-0015/fdabcc862cbc4698a4ee4feb42a9ee27'}, 'dynamic_cover': {'uri': 'tos-cn-p-0015/fdabcc862cbc4698a4ee4feb42a9ee27', 'url_list': ['https://p5-ipv6.douyinpic.com/obj/tos-cn-p-0015/fdabcc862cbc4698a4ee4feb42a9ee27?from=2563711402_large', 'https://p26.douyinpic.com/obj/tos-cn-p-0015/fdabcc862cbc4698a4ee4feb42a9ee27?from=2563711402_large', 'https://p3.douyinpic.com/obj/tos-cn-p-0015/fdabcc862cbc4698a4ee4feb42a9ee27?from=2563711402_large']}, 'bit_rate': None, 'vid': 'v0200fcf0000c1bj4fmluf3igni150tg', 'height': 1920, 'width': 1080, 'has_watermark': True}, 'share_info': {'share_weibo_desc': '#在抖音,记录美好生活#尝试臭豆腐肥肠火锅?这味道简直太太太上头了!!#vlog日常 #美食探店 #火锅 #深夜放毒 #美食趣胃计划', 'share_desc': '在抖音,记录美好生活', 'share_title': '尝试臭豆腐肥肠火锅?这味道简直太太太上头了!!#vlog日常 #美食探店 #火锅 #深夜放毒 #美食趣胃计划'}, 'video_text': None, 'create_time': 1616328562, 'cha_list': [{'user_count': 0, 'is_commerce': False, 'cid': '1558567968378882', 'cha_name': '深夜放毒', 'desc': '', 'hash_tag_profile': '', 'connect_music': None, 'type': 0, 'view_count': 0}], 'image_infos': None, 'author_user_id': 76615500441, 'desc': '尝试臭豆腐肥肠火锅?这味道简直太太太上头了!!#vlog日常 #美食探店 #火锅 #深夜放毒 #美食趣胃计划', 'images': None, 'promotions': None, 'share_url': 'https://www.iesdouyin.com/share/video/6942073391922842894/?region=&mid=6942073520700607269&u_code=48&titleType=title&did=MS4wLjABAAAANwkJuWIRFOzg5uCpDRpMj4OX-QryoDgn-yYlXQnRwQQ&iid=MS4wLjABAAAANwkJuWIRFOzg5uCpDRpMj4OX-QryoDgn-yYlXQnRwQQ&with_sec_did=1', 'label_top_text': None, 'mix_info': {'mix_id': '6812903915307141134', 'mix_name': '猪猪的美食vlog!', 'statis': {'updated_to_episode': 55, 'play_vv': 0, 'collect_vv': 0, 'current_episode': 55}, 'extra': '{"douyin_search_ocr_content":"猪猪带你吃吃吃,吃饱了才能减肥嘛!","douyin_search_user_generated_title":" 美食 计划 ","first_reviewed":1,"is_quality_mix":0,"next_info":{"cover":"tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d","desc":"猪猪带你吃吃吃,吃饱了才能减肥嘛!","name":"猪猪的美食vlog!"},"origin_challenge_content":""}', 'create_time': 1586252804, 'cover_url': {'url_list': ['https://p5-ipv6.douyinpic.com/obj/tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d?from=2563711402', 'https://p26.douyinpic.com/obj/tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d?from=2563711402', 'https://p11.douyinpic.com/obj/tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d?from=2563711402'], 'uri': 'tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d'}, 'status': {'status': 2, 'is_collected': 0}, 'desc': '猪猪带你吃吃吃,吃饱了才能减肥嘛!', 'next_info': {'mix_name': '猪猪的美食vlog!', 'desc': '猪猪带你吃吃吃,吃饱了才能减肥嘛!', 'cover_url': {'url_list': ['https://p1-dy.bytecdn.cn/obj/tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d', 'https://p3-dy.bytecdn.cn/obj/tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d', 'https://p9-dy.bytecdn.cn/obj/tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d'], 'uri': 'tos-cn-i-0813/2cebe1ba64a9413d8e85383a0651a64d'}}}, 'category': 0, 'is_preview': 1, 'aweme_id': '6942073391922842894', 'text_extra': [{'start': 23, 'end': 30, 'type': 1, 'hashtag_name': 'vlog日常', 'hashtag_id': 1607783788304387}, {'hashtag_name': '美食探店', 'hashtag_id': 1591486437085198, 'start': 31, 'end': 36, 'type': 1}, {'hashtag_name': '火锅', 'hashtag_id': 1553400994340865, 'start': 37, 'end': 40, 'type': 1}, {'start': 41, 'end': 46, 'type': 1, 'hashtag_name': '深夜放毒', 'hashtag_id': 1558567968378882}, {'hashtag_name': '美食趣胃计划', 'hashtag_id': 1657693004378126, 'start': 47, 'end': 54, 'type': 1}], 'aweme_type': 4, 'long_video': None, 'music': {'cover_medium': {'uri': '720x720/20b7b00015cd04a8ec0cb', 'url_list': ['https://p9.douyinpic.com/aweme/720x720/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p26.douyinpic.com/aweme/720x720/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p11.douyinpic.com/aweme/720x720/20b7b00015cd04a8ec0cb.jpeg?from=2563711402']}, 'cover_thumb': {'uri': '168x168/20b7b00015cd04a8ec0cb', 'url_list': ['https://p5-ipv6.douyinpic.com/img/20b7b00015cd04a8ec0cb~c5_168x168.jpeg?from=2563711402', 'https://p11.douyinpic.com/img/20b7b00015cd04a8ec0cb~c5_168x168.jpeg?from=2563711402', 'https://p9.douyinpic.com/img/20b7b00015cd04a8ec0cb~c5_168x168.jpeg?from=2563711402']}, 'play_url': {'uri': 'https://sf6-cdn-tos.douyinstatic.com/obj/ies-music/6942073506247379719.mp3', 'url_list': ['https://sf6-cdn-tos.douyinstatic.com/obj/ies-music/6942073506247379719.mp3', 'https://sf3-cdn-tos.douyinstatic.com/obj/ies-music/6942073506247379719.mp3']}, 'duration': 90, 'position': None, 'mid': '6942073520700607269', 'title': '@帅气的悉尼小猪猪创作的原声', 'cover_hd': {'uri': '1080x1080/20b7b00015cd04a8ec0cb', 'url_list': ['https://p26.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p29.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p11.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402']}, 'cover_large': {'uri': '1080x1080/20b7b00015cd04a8ec0cb', 'url_list': ['https://p26.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p29.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402', 'https://p11.douyinpic.com/aweme/1080x1080/20b7b00015cd04a8ec0cb.jpeg?from=2563711402']}, 'status': 1, 'id': 6942073520700607000, 'author': '帅气的悉尼小猪猪'}, 'duration': 90139, 'risk_infos': {'warn': False, 'type': 0, 'content': ''}, 'comment_list': None, 'anchor_info': {'id': '6867104903072860167', 'type': 2}, 'statistics': {'aweme_id': '6942073391922842894', 'comment_count': 15234, 'digg_count': 149138, 'play_count': 0, 'share_count': 4860}}
|