mirror of
https://github.com/yaronzz/Tidal-Media-Downloader.git
synced 2026-01-16 16:04:25 -05:00
Refactoring: Mainly removed unused imports.
This commit is contained in:
@@ -8,16 +8,14 @@
|
||||
@Contact : yaronhuang@foxmail.com
|
||||
@Desc :
|
||||
'''
|
||||
import aigpy
|
||||
import logging
|
||||
|
||||
from paths import *
|
||||
from printf import *
|
||||
from decryption import *
|
||||
from tidal import *
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from decryption import *
|
||||
from printf import *
|
||||
from tidal import *
|
||||
|
||||
|
||||
def __isSkip__(finalpath, url):
|
||||
if not SETTINGS.checkExist:
|
||||
return False
|
||||
@@ -164,7 +162,7 @@ def downloadTrack(track: Track, album=None, playlist=None, userProgress=None, pa
|
||||
tool.setPartSize(partSize)
|
||||
check, err = tool.start(SETTINGS.showProgress and not SETTINGS.multiThread)
|
||||
if not check:
|
||||
Printf.err(f"DL Track[{track.title}] failed.{str(err)}")
|
||||
Printf.err(f"DL Track '{track.title}' failed: {str(err)}")
|
||||
return False, str(err)
|
||||
|
||||
# encrypted -> decrypt and remove encrypted file
|
||||
@@ -187,13 +185,14 @@ def downloadTrack(track: Track, album=None, playlist=None, userProgress=None, pa
|
||||
|
||||
__setMetaData__(track, album, path, contributors, lyrics)
|
||||
Printf.success(track.title)
|
||||
|
||||
return True, ''
|
||||
except Exception as e:
|
||||
Printf.err(f"DL Track[{track.title}] failed.{str(e)}")
|
||||
Printf.err(f"DL Track '{track.title}' failed: {str(e)}")
|
||||
return False, str(e)
|
||||
|
||||
|
||||
def downloadTracks(tracks, album: Album = None, playlist : Playlist=None):
|
||||
def downloadTracks(tracks, album: Album = None, playlist: Playlist = None):
|
||||
def __getAlbum__(item: Track):
|
||||
album = TIDAL_API.getAlbum(item.album.id)
|
||||
if SETTINGS.saveCovers and not SETTINGS.usePlaylistFolder:
|
||||
|
||||
@@ -9,13 +9,6 @@
|
||||
@Desc :
|
||||
"""
|
||||
|
||||
import aigpy
|
||||
import time
|
||||
|
||||
from model import *
|
||||
from enums import *
|
||||
from tidal import *
|
||||
from printf import *
|
||||
from download import *
|
||||
|
||||
'''
|
||||
|
||||
@@ -8,15 +8,11 @@
|
||||
@Contact : yaronhuang@foxmail.com
|
||||
@Desc :
|
||||
"""
|
||||
import sys
|
||||
import aigpy
|
||||
import _thread
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
from events import *
|
||||
from settings import *
|
||||
from printf import *
|
||||
from enums import *
|
||||
|
||||
|
||||
def enableGui():
|
||||
@@ -38,6 +34,7 @@ else:
|
||||
from PyQt5 import QtWidgets
|
||||
from qt_material import apply_stylesheet
|
||||
|
||||
|
||||
class SettingView(QtWidgets.QWidget):
|
||||
def __init__(self, ) -> None:
|
||||
super().__init__()
|
||||
@@ -55,12 +52,14 @@ else:
|
||||
self.mainGrid.addWidget(self.c_pathTrackFormat)
|
||||
self.mainGrid.addWidget(self.c_pathVideoFormat)
|
||||
|
||||
|
||||
class EmittingStream(QObject):
|
||||
textWritten = pyqtSignal(str)
|
||||
|
||||
def write(self, text):
|
||||
self.textWritten.emit(str(text))
|
||||
|
||||
|
||||
class MainView(QtWidgets.QWidget):
|
||||
s_downloadEnd = pyqtSignal(str, bool, str)
|
||||
|
||||
@@ -314,6 +313,7 @@ else:
|
||||
|
||||
self.set_table_search_results(tracks, Type.Track)
|
||||
|
||||
|
||||
def startGui():
|
||||
aigpy.cmd.enableColor(False)
|
||||
|
||||
@@ -327,7 +327,6 @@ else:
|
||||
|
||||
app.exec_()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
SETTINGS.read(getProfilePath())
|
||||
TOKEN.read(getTokenPath())
|
||||
|
||||
@@ -8,23 +8,18 @@
|
||||
@Contact : yaronhuang@foxmail.com
|
||||
@Desc : tidal api
|
||||
'''
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
from typing import Union, List
|
||||
|
||||
import aigpy
|
||||
import base64
|
||||
import requests
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from model import *
|
||||
from enums import *
|
||||
from settings import *
|
||||
|
||||
import requests
|
||||
import tidalapi
|
||||
|
||||
from model import *
|
||||
from settings import *
|
||||
|
||||
# SSL Warnings | retry number
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
requests.adapters.DEFAULT_RETRIES = 5
|
||||
@@ -47,7 +42,8 @@ class TidalAPI(object):
|
||||
if respond.url.find("playbackinfopostpaywall") != -1 and SETTINGS.downloadDelay is not False:
|
||||
# random sleep between 0.5 and 5 seconds and print it
|
||||
sleep_time = random.randint(500, 5000) / 1000
|
||||
print(f"Sleeping for {sleep_time} seconds, to mimic human behaviour and prevent too many requests error")
|
||||
print(
|
||||
f"Sleeping for {sleep_time} seconds, to mimic human behaviour and prevent too many requests error")
|
||||
time.sleep(sleep_time)
|
||||
|
||||
if respond.status_code == 429:
|
||||
@@ -113,7 +109,7 @@ class TidalAPI(object):
|
||||
def __post__(self, path, data, auth=None, urlpre='https://auth.tidal.com/v1/oauth2'):
|
||||
for index in range(3):
|
||||
try:
|
||||
result = requests.post(urlpre+path, data=data, auth=auth, verify=False).json()
|
||||
result = requests.post(urlpre + path, data=data, auth=auth, verify=False).json()
|
||||
return result
|
||||
except Exception as e:
|
||||
if index == 2:
|
||||
@@ -198,7 +194,7 @@ class TidalAPI(object):
|
||||
|
||||
if not aigpy.string.isNull(userid):
|
||||
if str(result['userId']) != str(userid):
|
||||
raise Exception("User mismatch! Please use your own accesstoken.",)
|
||||
raise Exception("User mismatch! Please use your own accesstoken.", )
|
||||
|
||||
self.key.userId = result['userId']
|
||||
self.key.countryCode = result['countryCode']
|
||||
@@ -385,7 +381,7 @@ class TidalAPI(object):
|
||||
ret.trackid = resp.trackid
|
||||
ret.soundQuality = resp.audioQuality
|
||||
ret.codec = aigpy.string.getSub(xmldata, 'codecs="', '"')
|
||||
ret.encryptionKey = ""#manifest['keyId'] if 'keyId' in manifest else ""
|
||||
ret.encryptionKey = "" # manifest['keyId'] if 'keyId' in manifest else ""
|
||||
ret.urls = self.parse_mpd(xmldata)[0]
|
||||
if len(ret.urls) > 0:
|
||||
ret.url = ret.urls[0]
|
||||
@@ -492,10 +488,11 @@ class TidalAPI(object):
|
||||
return playlists
|
||||
|
||||
def get_playlist_items(self, playlist_id: int) -> Union[tidalapi.Playlist, tidalapi.UserPlaylist]:
|
||||
#tracks = self.session.playlist(playlist_id).items()
|
||||
# tracks = self.session.playlist(playlist_id).items()
|
||||
tracks, videos = TIDAL_API.getItems(playlist_id, Type.Playlist)
|
||||
|
||||
return tracks
|
||||
|
||||
|
||||
# Singleton
|
||||
TIDAL_API = TidalAPI()
|
||||
|
||||
Reference in New Issue
Block a user