[英]Sending message with Telethon(Telegram API Client for Python)
[英]How to get Telegram audio (music) album cover using Telethon API client
這不是通過 MTproto。 每個 Telegram 客戶端都從不同的提供商手動獲取它,我將使用Android實現。
small 是聊天 UI thumb,other 是玩家大小。 這只是對屏幕截圖中曲目的測試。
自己處理評論部分並傳遞有效消息 object,並改用 aiohttp 並使此異步功能。
import requests
def get_cover(msg, limit=1, small=False):
# if not (f := msg.file) and not all((f.title, f.performer)): return
# performer, title = f.performer, f.title
performer, title = 'Sixthells', 'Mayhem'
url = f"https://itunes.apple.com/search?term={performer} - {title}&entity=song&limit={limit}"
headers = {"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A5297c Safari/602.1"}
req = requests.post(url, headers=headers)
if 200 >= req.status_code < 300:
if (x := req.json())['resultCount']:
small_url = x['results'][0]['artworkUrl100']
file_url = small_url if small\
else small_url.replace('100x100', '600x600')
# Telegram default. can increase 600x600.
return small_url, file_url
print(*get_cover(msg=None), sep='\n')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.