Ejemplo n.º 1
0
    async def init(self, login: str = '', pwd: str = ''):
        """
        Start point for get music.yandex.ru client

        :param login: Username or token string
        :param pwd: Password string
        :return: yandex_music.Client
        """

        try:
            if login != '' and pwd != '':
                # Old authorization method, report_new_fields no need to new auth
                # self.client = Client.from_credentials(login, pwd, report_new_fields=False)
                self.client = Client.from_credentials(login, pwd)
                return True

            else:
                if pwd == '' and login != '':
                    # Old authorization method, report_new_fields no need to new auth
                    # self.client = Client.from_token(login, report_new_fields=False)
                    self.client = Client.from_token(login)
                    return True
                else:
                    # Old authorization method, report_new_fields no need to new auth
                    # self.client = Client.from_credentials(LOGIN, PWD, report_new_fields=False)
                    self.client = Client.from_credentials(LOGIN, PWD)
                    return True

        except Unauthorized:
            print("Unauthorized")
            return False

        except YandexMusicError:
            print("YandexMusicError")
            return False
def check_login(settings):
    token = settings.getSetting('token')
    if not token:
        return False, Client()

    try:
        client = Client.from_token(token)
        return True, client
    except Unauthorized as _:
        return False, Client()
Ejemplo n.º 3
0
    def __init__(self,
                 title: str,
                 username: str | None = None,
                 password: str | None = None,
                 token: str | None = None,
                 cache="/tmp/YMStreamer",
                 debug=False):
        super().__init__(title, debug)
        if token is not None:
            self.client = Client.from_token(token)
        else:
            self.client = Client.from_credentials(username or '', password
                                                  or '')

        global CACHE_FOLDER
        CACHE_FOLDER = cache
Ejemplo n.º 4
0
 def authorization_token(self, token):
     try:
         self.client = Client.from_token(token)
     except Exception as e:
         logging.getLogger(e.args[0])
Ejemplo n.º 5
0
import discord
import datetime
import sqlalchemy
import sqlalchemy.orm as orm
from imgurpython import ImgurClient
from sqlalchemy.orm import Session
import sqlalchemy.ext.declarative as dec
from data import db_session
from data.users import User
import os
from yandex_music import Client

TOKEN = ''
YM_TOKEN = ''
prefix = '-'
ya_music = Client.from_token(YM_TOKEN)


def get_my_files(content):
    f = io.BytesIO(content)
    my_files = [
        discord.File(f, "tmpcat.jpg"),
    ]
    return my_files


class YLBotClient(discord.Client):
    def __init__(self):
        super().__init__()
        self.timers = []
        self.queue = asyncio.Queue()
Ejemplo n.º 6
0
if args.print_args:
    print(args)
    sys.exit()

if type(args.token) is str and re.match(r'^[A-z0-9]{39}$', args.token):
    if not args.no_save_token:
        parser.get_default('token').write_text(args.token)
else:
    try:
        args.token = Path(args.token).read_text()
    except FileNotFoundError:
        print('Config file not found. Use --token to create it')
        sys.exit(2)

client = Client.from_token(args.token, report_new_fields=False)

print('Hello,', client.me.account.first_name)
if client.me.account.now and client.me.account.now.split(
        'T')[0] == client.me.account.birthday:
    print('Happy birthday!')

if args.playlist == 'user':
    user_playlists = client.users_playlists_list()
    if not args.playlist_name:
        print('specify --playlist-name', list(p.title for p in user_playlists))
        sys.exit(1)
    playlist = next(
        (p for p in user_playlists if p.title == args.playlist_name), None)
    if playlist == None:
        print(f'playlist "{args.playlist_name}" not found')
Ejemplo n.º 7
0
from yandex_music import Client

token = ""
client = Client.from_token(token)
search = client.search("moby")

print(search)