Cleanup and small improvements
This commit is contained in:
13
interface.py
13
interface.py
@@ -107,7 +107,8 @@ class ModuleInterface:
|
||||
else:
|
||||
if not username or not password:
|
||||
self.print(f'{module_information.service_name}: Creating a Mobile session')
|
||||
self.print(f'{module_information.service_name}: Enter your Tidal username and password:')
|
||||
self.print(f'{module_information.service_name}: Enter your TIDAL username and password:')
|
||||
self.print(f'{module_information.service_name}: (password will not be echoed)')
|
||||
username = input(' Username: ')
|
||||
password = getpass(' Password: ')
|
||||
sessions[session_type].auth(username, password)
|
||||
@@ -142,7 +143,8 @@ class ModuleInterface:
|
||||
sessions[session_type].auth()
|
||||
else:
|
||||
self.print(f'{module_information.service_name}: Recreating a Mobile session')
|
||||
self.print(f'{module_information.service_name}: Enter your Tidal username and password:')
|
||||
self.print(f'{module_information.service_name}: Enter your TIDAL username and password:')
|
||||
self.print(f'{module_information.service_name}: (password will not be echoed)')
|
||||
username = input('Username: ')
|
||||
password = getpass('Password: ')
|
||||
sessions[session_type].auth(username, password)
|
||||
@@ -187,7 +189,7 @@ class ModuleInterface:
|
||||
|
||||
items = []
|
||||
for i in results[query_type.name + 's'].get('items'):
|
||||
duration = None
|
||||
duration, name = None, None
|
||||
if query_type is DownloadTypeEnum.artist:
|
||||
name = i.get('name')
|
||||
artists = None
|
||||
@@ -427,7 +429,8 @@ class ModuleInterface:
|
||||
# lmao what did I smoke when I wrote this, track_data and not album_data!
|
||||
if (self.settings['force_non_spatial'] or (
|
||||
(quality_tier is QualityEnum.LOSSLESS or track_data.get('audioQuality') == 'LOSSLESS')
|
||||
and track_data.get('audioModes') == ['STEREO'])) and SessionType.MOBILE_DEFAULT.name in self.available_sessions:
|
||||
and track_data.get('audioModes') == ['STEREO'])) and (
|
||||
SessionType.MOBILE_DEFAULT.name in self.available_sessions):
|
||||
self.session.default = SessionType.MOBILE_DEFAULT
|
||||
elif (track_data.get('audioModes') == ['SONY_360RA']
|
||||
or ('DOLBY_ATMOS' in track_data.get('audioModes') and self.settings['prefer_ac4'])) \
|
||||
@@ -683,7 +686,7 @@ class ModuleInterface:
|
||||
silentremove(merged_temp_location)
|
||||
for temp_location in temp_locations:
|
||||
silentremove(temp_location)
|
||||
except Exception:
|
||||
except:
|
||||
self.print('FFmpeg is not installed or working! Using fallback, may have errors')
|
||||
|
||||
# return the MP4 temp file, but tell orpheus to change the container to .m4a (AAC)
|
||||
|
||||
70
tidal_api.py
70
tidal_api.py
@@ -212,25 +212,25 @@ class TidalApi(object):
|
||||
def get_artist_albums_ep_singles(self, artist_id):
|
||||
return self._get('artists/' + str(artist_id) + '/albums', params={'filter': 'EPSANDSINGLES'})
|
||||
|
||||
def get_type_from_id(self, id):
|
||||
def get_type_from_id(self, id_):
|
||||
result = None
|
||||
try:
|
||||
result = self.get_album(id)
|
||||
result = self.get_album(id_)
|
||||
return 'a'
|
||||
except TidalError:
|
||||
pass
|
||||
try:
|
||||
result = self.get_artist(id)
|
||||
result = self.get_artist(id_)
|
||||
return 'r'
|
||||
except TidalError:
|
||||
pass
|
||||
try:
|
||||
result = self.get_track(id)
|
||||
result = self.get_track(id_)
|
||||
return 't'
|
||||
except TidalError:
|
||||
pass
|
||||
try:
|
||||
result = self.get_video(id)
|
||||
result = self.get_video(id_)
|
||||
return 'v'
|
||||
except TidalError:
|
||||
pass
|
||||
@@ -238,62 +238,6 @@ class TidalApi(object):
|
||||
return result
|
||||
|
||||
|
||||
class SessionFormats:
|
||||
def __init__(self, session):
|
||||
self.mqa_trackid = '91950969'
|
||||
self.dolby_trackid = '131069353'
|
||||
self.sony_trackid = '142292058'
|
||||
|
||||
self.quality = ['HI_RES', 'LOSSLESS', 'HIGH', 'LOW']
|
||||
|
||||
self.formats = {
|
||||
'eac3': False,
|
||||
'mha1': False,
|
||||
'ac4': False,
|
||||
'mqa': False,
|
||||
'flac': False,
|
||||
'alac': False,
|
||||
'mp4a.40.2': False,
|
||||
'mp4a.40.5': False
|
||||
}
|
||||
|
||||
try:
|
||||
self.check_formats(session)
|
||||
except TidalRequestError:
|
||||
print('\tERROR: No (HiFi) subscription found!')
|
||||
|
||||
def check_formats(self, session):
|
||||
api = TidalApi(session)
|
||||
|
||||
for id in [self.dolby_trackid, self.sony_trackid]:
|
||||
playback_info = api.get_stream_url(id, ['LOW'])
|
||||
if playback_info['manifestMimeType'] == 'application/dash+xml':
|
||||
continue
|
||||
manifest_unparsed = base64.b64decode(playback_info['manifest']).decode('UTF-8')
|
||||
if 'ContentProtection' not in manifest_unparsed:
|
||||
self.formats[json.loads(manifest_unparsed)['codecs']] = True
|
||||
|
||||
for i in range(len(self.quality)):
|
||||
playback_info = api.get_stream_url(self.mqa_trackid, [self.quality[i]])
|
||||
if playback_info['manifestMimeType'] == 'application/dash+xml':
|
||||
continue
|
||||
|
||||
manifest_unparsed = base64.b64decode(playback_info['manifest']).decode('UTF-8')
|
||||
if 'ContentProtection' not in manifest_unparsed:
|
||||
self.formats[json.loads(manifest_unparsed)['codecs']] = True
|
||||
|
||||
def print_fomats(self):
|
||||
table = prettytable.PrettyTable()
|
||||
table.field_names = ['Codec', 'Technical name', 'Supported']
|
||||
table.align = 'l'
|
||||
for format in self.formats:
|
||||
table.add_row([format, technical_names[format], self.formats[format]])
|
||||
|
||||
string_table = '\t' + table.__str__().replace('\n', '\n\t')
|
||||
print(string_table)
|
||||
print('')
|
||||
|
||||
|
||||
@dataclass
|
||||
class SessionStorage:
|
||||
access_token: str
|
||||
@@ -513,7 +457,7 @@ class TidalMobileSession(TidalSession):
|
||||
})
|
||||
|
||||
if r.status_code == 200:
|
||||
print('\tRefreshing token successful')
|
||||
# print('TIDAL: Refreshing token successful')
|
||||
self.access_token = r.json()['access_token']
|
||||
self.expires = datetime.now() + timedelta(seconds=r.json()['expires_in'])
|
||||
|
||||
@@ -628,7 +572,7 @@ class TidalTvSession(TidalSession):
|
||||
})
|
||||
|
||||
if r.status_code == 200:
|
||||
print('Tidal: Refreshing token successful')
|
||||
# print('TIDAL: Refreshing token successful')
|
||||
self.access_token = r.json()['access_token']
|
||||
self.expires = datetime.now() + timedelta(seconds=r.json()['expires_in'])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user