Skip to content

Instantly share code, notes, and snippets.

@frydaykg
Last active February 1, 2022 22:32
Show Gist options
  • Select an option

  • Save frydaykg/f0eda052ec3c428ee2bb459538cbda48 to your computer and use it in GitHub Desktop.

Select an option

Save frydaykg/f0eda052ec3c428ee2bb459538cbda48 to your computer and use it in GitHub Desktop.
Yambu
import asyncio
from telethon import TelegramClient, events
from yandex_music import Client
import time
import datetime
yaclient = Client.from_credentials('fryday.kg@yandex.ru', 'xxxxx')
def get_current_track():
try:
queues = yaclient.queues_list()
# Последняя проигрываемая очередь всегда в начале списка
last_queue = yaclient.queue(queues[0].id)
last_track_id = last_queue.get_current_track()
last_track = last_track_id.fetch_track()
artists = ', '.join(last_track.artists_name())
title = last_track.title
return f'#yambu 🎵 {artists} - {title}'
except:
pass
from telethon.tl.functions.account import UpdateProfileRequest
# These example values won't work. You must get your own api_id and
# api_hash from https://my.telegram.org, under API Development.
api_id = 13592063
api_hash = 'xxxx'
async def main():
client = TelegramClient('session_name', api_id, api_hash)
await client.start()
s = ''
sm = datetime.datetime.now()
while True:
try:
cur = get_current_track()
if cur != s:
await client(UpdateProfileRequest(about=cur))
s = cur
sm = datetime.datetime.now()
elif (datetime.datetime.now() - sm).total_seconds() > 600:
await client(UpdateProfileRequest(about='#yambu 🎵 Ничего не слушает'))
except:
pass
time.sleep(5)
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment