Refactoring: Mainly removed unused imports.

This commit is contained in:
Robert Honz
2023-10-23 15:00:06 +02:00
parent 379eca8458
commit 56c9cf5695
4 changed files with 25 additions and 37 deletions
+9 -10
View File
@@ -8,16 +8,14 @@
@Contact : yaronhuang@foxmail.com @Contact : yaronhuang@foxmail.com
@Desc : @Desc :
''' '''
import aigpy
import logging
from paths import *
from printf import *
from decryption import *
from tidal import *
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from decryption import *
from printf import *
from tidal import *
def __isSkip__(finalpath, url): def __isSkip__(finalpath, url):
if not SETTINGS.checkExist: if not SETTINGS.checkExist:
return False return False
@@ -164,7 +162,7 @@ def downloadTrack(track: Track, album=None, playlist=None, userProgress=None, pa
tool.setPartSize(partSize) tool.setPartSize(partSize)
check, err = tool.start(SETTINGS.showProgress and not SETTINGS.multiThread) check, err = tool.start(SETTINGS.showProgress and not SETTINGS.multiThread)
if not check: 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) return False, str(err)
# encrypted -> decrypt and remove encrypted file # 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) __setMetaData__(track, album, path, contributors, lyrics)
Printf.success(track.title) Printf.success(track.title)
return True, '' return True, ''
except Exception as e: 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) 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): def __getAlbum__(item: Track):
album = TIDAL_API.getAlbum(item.album.id) album = TIDAL_API.getAlbum(item.album.id)
if SETTINGS.saveCovers and not SETTINGS.usePlaylistFolder: if SETTINGS.saveCovers and not SETTINGS.usePlaylistFolder:
-7
View File
@@ -9,13 +9,6 @@
@Desc : @Desc :
""" """
import aigpy
import time
from model import *
from enums import *
from tidal import *
from printf import *
from download import * from download import *
''' '''
+5 -6
View File
@@ -8,15 +8,11 @@
@Contact : yaronhuang@foxmail.com @Contact : yaronhuang@foxmail.com
@Desc : @Desc :
""" """
import sys
import aigpy
import _thread
import importlib import importlib
import sys
from events import * from events import *
from settings import *
from printf import * from printf import *
from enums import *
def enableGui(): def enableGui():
@@ -38,6 +34,7 @@ else:
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from qt_material import apply_stylesheet from qt_material import apply_stylesheet
class SettingView(QtWidgets.QWidget): class SettingView(QtWidgets.QWidget):
def __init__(self, ) -> None: def __init__(self, ) -> None:
super().__init__() super().__init__()
@@ -55,12 +52,14 @@ else:
self.mainGrid.addWidget(self.c_pathTrackFormat) self.mainGrid.addWidget(self.c_pathTrackFormat)
self.mainGrid.addWidget(self.c_pathVideoFormat) self.mainGrid.addWidget(self.c_pathVideoFormat)
class EmittingStream(QObject): class EmittingStream(QObject):
textWritten = pyqtSignal(str) textWritten = pyqtSignal(str)
def write(self, text): def write(self, text):
self.textWritten.emit(str(text)) self.textWritten.emit(str(text))
class MainView(QtWidgets.QWidget): class MainView(QtWidgets.QWidget):
s_downloadEnd = pyqtSignal(str, bool, str) s_downloadEnd = pyqtSignal(str, bool, str)
@@ -314,6 +313,7 @@ else:
self.set_table_search_results(tracks, Type.Track) self.set_table_search_results(tracks, Type.Track)
def startGui(): def startGui():
aigpy.cmd.enableColor(False) aigpy.cmd.enableColor(False)
@@ -327,7 +327,6 @@ else:
app.exec_() app.exec_()
if __name__ == '__main__': if __name__ == '__main__':
SETTINGS.read(getProfilePath()) SETTINGS.read(getProfilePath())
TOKEN.read(getTokenPath()) TOKEN.read(getTokenPath())
+11 -14
View File
@@ -8,23 +8,18 @@
@Contact : yaronhuang@foxmail.com @Contact : yaronhuang@foxmail.com
@Desc : tidal api @Desc : tidal api
''' '''
import json
import random import random
import re import re
import time import time
from typing import Union, List from typing import Union, List
import aigpy
import base64
import requests
from xml.etree import ElementTree from xml.etree import ElementTree
from model import * import requests
from enums import *
from settings import *
import tidalapi import tidalapi
from model import *
from settings import *
# SSL Warnings | retry number # SSL Warnings | retry number
requests.packages.urllib3.disable_warnings() requests.packages.urllib3.disable_warnings()
requests.adapters.DEFAULT_RETRIES = 5 requests.adapters.DEFAULT_RETRIES = 5
@@ -47,7 +42,8 @@ class TidalAPI(object):
if respond.url.find("playbackinfopostpaywall") != -1 and SETTINGS.downloadDelay is not False: if respond.url.find("playbackinfopostpaywall") != -1 and SETTINGS.downloadDelay is not False:
# random sleep between 0.5 and 5 seconds and print it # random sleep between 0.5 and 5 seconds and print it
sleep_time = random.randint(500, 5000) / 1000 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) time.sleep(sleep_time)
if respond.status_code == 429: 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'): def __post__(self, path, data, auth=None, urlpre='https://auth.tidal.com/v1/oauth2'):
for index in range(3): for index in range(3):
try: 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 return result
except Exception as e: except Exception as e:
if index == 2: if index == 2:
@@ -198,7 +194,7 @@ class TidalAPI(object):
if not aigpy.string.isNull(userid): if not aigpy.string.isNull(userid):
if str(result['userId']) != str(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.userId = result['userId']
self.key.countryCode = result['countryCode'] self.key.countryCode = result['countryCode']
@@ -385,7 +381,7 @@ class TidalAPI(object):
ret.trackid = resp.trackid ret.trackid = resp.trackid
ret.soundQuality = resp.audioQuality ret.soundQuality = resp.audioQuality
ret.codec = aigpy.string.getSub(xmldata, 'codecs="', '"') 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] ret.urls = self.parse_mpd(xmldata)[0]
if len(ret.urls) > 0: if len(ret.urls) > 0:
ret.url = ret.urls[0] ret.url = ret.urls[0]
@@ -492,10 +488,11 @@ class TidalAPI(object):
return playlists return playlists
def get_playlist_items(self, playlist_id: int) -> Union[tidalapi.Playlist, tidalapi.UserPlaylist]: 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) tracks, videos = TIDAL_API.getItems(playlist_id, Type.Playlist)
return tracks return tracks
# Singleton # Singleton
TIDAL_API = TidalAPI() TIDAL_API = TidalAPI()