diff --git a/app/util/emoji.py b/app/util/emoji.py index 3ab73b7..31b6c03 100644 --- a/app/util/emoji.py +++ b/app/util/emoji.py @@ -89,20 +89,31 @@ class Emotion: if lock.locked(): lock.release() - def get_emoji_url(self, md5: str): - sql = ''' - select CDNUrl - from CustomEmotion - where md5 = ? - ''' + def get_emoji_url(self, md5: str, thumb: bool): + if thumb: + sql = ''' + select + case + when thumburl is NULL or thumburl = '' then cdnurl + else thumburl + end as selected_url + from CustomEmotion + where md5 = ? + ''' + else: + sql = ''' + select CDNUrl + from CustomEmotion + where md5 = ? + ''' try: lock.acquire(True) self.cursor.execute(sql, [md5]) return self.cursor.fetchone()[0] except: md5 = md5.upper() - sql = """ - select Data + sql = f""" + select {"Thumb" if thumb else "Data"} from EmotionItem where md5 = ? """ @@ -158,7 +169,7 @@ def get_emoji(xml_string, thumb=True, output_path=root_path) -> str: return file_path url = emoji_info['thumburl'] if thumb else emoji_info['cdnurl'] if not url or url == "": - url = Emotion().get_emoji_url(md5) + url = Emotion().get_emoji_url(md5, thumb) if type(url) == str and url != "": print("下载表情包ing:", url) emoji_path = download(url, output_path, md5, thumb) @@ -185,11 +196,13 @@ def get_emoji(xml_string, thumb=True, output_path=root_path) -> str: if __name__ == '__main__': - xml_string = ' ' - res1 = parser_xml(xml_string) - print(res1, res1['md5']) + # xml_string = ' ' + # res1 = parser_xml(xml_string) + # print(res1, res1['md5']) # download(res1['cdnurl'], "./data/emoji/", res1['md5']) # download(res1['thumburl'], "./data/emoji/", res1['md5'], True) - print(get_emoji(xml_string, True)) - print(get_emoji(xml_string, False)) + print(Emotion().get_emoji_url("144714f65c98844128ac3a1042445d9a", True)) + print(Emotion().get_emoji_url("144714f65c98844128ac3a1042445d9a", False)) + # print(get_emoji(xml_string, True)) + # print(get_emoji(xml_string, False)) # http://vweixinf.tc.qq.com/110/20403/stodownload?m=3a4d439aba02dce4834b2c54e9f15597&filekey=3043020101042f302d02016e0402534804203361346434333961626130326463653438333462326335346539663135353937020213f0040d00000004627466730000000131&hy=SH&storeid=323032313037323030373236313130303039653236646365316535316534383236386234306230303030303036653033303034666233&ef=3&bizid=1022