Exemple #1
0
def run():
    xdg_config_home = os.getenv("XDG_CONFIG_HOME")
    if xdg_config_home:
        config_dir = Path(xdg_config_home)
    else:
        config_dir = Path.home() / '.config'

    config_file = config_dir / 'undercurrent.conf'

    config = configparser.ConfigParser()
    config.read(config_file)

    if not config.has_section('tidal_auth'):
        print('Missing tidal auth')
        exit()

    tidal_config = tidalapi.Config(quality=tidalapi.Quality.lossless)
    tidal = tidalapi.Session(config=tidal_config)
    tidal.login(config.get('tidal_auth', 'user'),
                config.get('tidal_auth', 'pass'))

    gui = PlayerGUI(tidal)
    player = Player(tidal, gui)
    gui.set_player(player)

    playlists = tidal.user.playlists()
    for pl in playlists:
        gui.add_playlist(pl)

    gui.run()
def open_tidal_session(config):
    quality_mapping = {
        'low': tidalapi.Quality.low,
        'high': tidalapi.Quality.high,
        'lossless': tidalapi.Quality.lossless
    }
    quality = quality_mapping[config.get('quality', 'high').lower()]
    session = tidalapi.Session(tidalapi.Config(quality=quality))
    session.login(config['username'], config['password'])
    return session
Exemple #3
0
def maybelogin(a={}):
    global session
    global quality
    global httphp
    global pathprefix
    global is_logged_in

    # Do this always
    setidprefix(tidalidprefix)

    if is_logged_in:
        return True

    if "UPMPD_HTTPHOSTPORT" not in os.environ:
        raise Exception("No UPMPD_HTTPHOSTPORT in environment")
    httphp = os.environ["UPMPD_HTTPHOSTPORT"]
    if "UPMPD_PATHPREFIX" not in os.environ:
        raise Exception("No UPMPD_PATHPREFIX in environment")
    pathprefix = os.environ["UPMPD_PATHPREFIX"]
    if "UPMPD_CONFIG" not in os.environ:
        raise Exception("No UPMPD_CONFIG in environment")

    upconfig = conftree.ConfSimple(os.environ["UPMPD_CONFIG"])
    if 'user' in a:
        username = a['user']
        password = a['password']
    else:
        username, password = getserviceuserpass(upconfig, 'tidal')
    if not username or not password:
        raise Exception("tidaluser and/or tidalpass not set in configuration")

    qalstr = upconfig.get('tidalquality')
    if qalstr == 'lossless':
        quality = Quality.lossless
    elif qalstr == 'high':
        quality = Quality.high
    elif qalstr == 'low':
        quality = Quality.low
    elif not qalstr:
        quality = Quality.high
    else:
        raise Exception("Bad tidal quality string in config. " +
                        "Must be lossless/high/low")
    tidalconf = tidalapi.Config(quality)
    session = tidalapi.Session(config=tidalconf)
    session.login(username, password)
    is_logged_in = True
    if quality == Quality.lossless:
        setMimeAndSamplerate('audio/flac', "44100")
    else:
        setMimeAndSamplerate('audio/mpeg', "44100")
Exemple #4
0
 def create_session(self):
     self.settings.validate()
     session_config = tdl.Config(self.settings.get("quality"))
     session = tdl.Session(session_config)
     try:
         session.login(
             self.settings.get_username(self.ui.uname_input,
                                        self.ui.yesno_prompt),
             self.settings.get_password(self.ui.pass_input,
                                        self.ui.yesno_prompt))
         if session.check_login() == False:
             self.ui.error("Invalid Login Credentials", exit=True)
     except:
         self.ui.error("Error Creating Login Session", exit=True)
     return session
Exemple #5
0
 def setup(self):
     # Assign quality or switch to high if not specified/not found.
     if hasattr(tidalapi.Quality,
                config.app["services"]["tidal"]["quality"]):
         quality = getattr(tidalapi.Quality,
                           config.app["services"]["tidal"]["quality"])
     else:
         quality = tidalapi.Quality.high
     # We need to instantiate a config object to pass quality settings.
     _config = tidalapi.Config(quality=quality)
     session_id = config.app["services"]["tidal"]["session_id"]
     token_type = config.app["services"]["tidal"]["token_type"]
     access_token = config.app["services"]["tidal"]["access_token"]
     refresh_token = config.app["services"]["tidal"]["refresh_token"]
     log.debug("Using quality: %s" % (quality, ))
     self.session = tidalapi.Session(config=_config)
     self.session.load_oauth_session(session_id, token_type, access_token,
                                     refresh_token)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tidalapi
import argparse
import urllib2
import os
from mutagen.flac import FLAC

config = tidalapi.Config(quality=tidalapi.Quality.lossless)
session = tidalapi.Session(config=config)
session.login("*****@*****.**", "ozturk.99")

def downloadFile(url, path, fileName):
	u = urllib2.urlopen(url)
	meta = u.info()
	contentLength = meta.getheaders("Content-Length")
	if len(contentLength):
		fileSize = int(contentLength[0])
	else:	
		fileSize = 1
	print "Downloading: %s Bytes: %s" % (fileName.encode("utf8"), fileSize)
	if not os.path.exists(path.encode("utf8")):
    		os.makedirs(path.encode("utf8"))
	fileName = os.path.join( path, fileName)
	if os.path.isfile(fileName.encode("utf8")):
		return 
	f = open(fileName.encode("utf8"), 'wb')
	fileDownloaded = 0
	blockSize = 8192
	while True:
Exemple #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fileencoding=utf-8

import tidalapi
from transliterate import translit
import os
from mutagen.flac import Picture, FLAC
from requests import get

session = tidalapi.Session(tidalapi.Config('LOSSLESS'))
session._config.api_token='MbjR4DLXz1ghC4rV'
session.login('YOUR TIDAL LOGIN', 'YOUR TIDAL PASSWORD')

def start():

	if not os.path.exists("music/"):
		os.mkdir("music/")

	mode = raw_input("Mode: \n 1) Playlist grabber\n 2) Track grabber\n 3) Album grabber\n 4) Search \n")

	if int(mode) == 1:
		playlist_id = raw_input("Enter playlist id: ")
		try:
			playlist = session.get_playlist_tracks(playlist_id=playlist_id)
			can_download = 1
		except Exception:
			print("Playlist not found.")
			can_download = 0
		if can_download == 1:
			for track in playlist:
Exemple #8
0
if quality == None:
    quality = "High"

if username == None or password == None or token == None:
    print "Please configure /etc/mpd.conf with your tidal settings"
    raise SystemExit

# check we can write to the folder
if folder == None:
    folder = "."

if not os.access(folder, os.W_OK):
    print "Can't write to " + folder + " aborting\n"
    raise SystemExit

config = tidalapi.Config()
config.quality = quality
config.api_token = token

# log in to tidal
session = tidalapi.Session(config)
session.login(username, password)

# grab a list of the users playlists:
playlists = session.get_user_playlists(session.user.id)

# for each playlist make a extended .m3u file, extended are used here to work round some issues in my front end.
# we don't remove deleted playlists but that could be done.

for playlist in playlists:
    print playlist.name