mirror of
https://github.com/yaronzz/Tidal-Media-Downloader.git
synced 2026-06-13 04:05:07 +03:00
* Added tidalapi as dependency.
* Added TreeView to display user's playlists.
This commit is contained in:
@@ -9,4 +9,5 @@ lyricsgenius==3.0.1
|
|||||||
pydub==0.25.1
|
pydub==0.25.1
|
||||||
PyQt5==5.15.7
|
PyQt5==5.15.7
|
||||||
qt-material==2.12
|
qt-material==2.12
|
||||||
lxml==4.7.1
|
lxml==4.7.1
|
||||||
|
tidalapi==0.7.3
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ def mainCommand():
|
|||||||
"hvgl:o:q:r:",
|
"hvgl:o:q:r:",
|
||||||
["help", "version", "gui", "link=", "output=", "quality", "resolution"])
|
["help", "version", "gui", "link=", "output=", "quality", "resolution"])
|
||||||
except getopt.GetoptError as errmsg:
|
except getopt.GetoptError as errmsg:
|
||||||
Printf.err(vars(errmsg)['msg'] + ". Use 'tidal-dl -h' for useage.")
|
Printf.err(vars(errmsg)['msg'] + ". Use 'tidal-dl -h' for usage.")
|
||||||
return
|
return
|
||||||
|
|
||||||
link = None
|
link = None
|
||||||
showGui = False
|
showGui = False
|
||||||
|
|
||||||
for opt, val in opts:
|
for opt, val in opts:
|
||||||
if opt in ('-h', '--help'):
|
if opt in ('-h', '--help'):
|
||||||
Printf.usage()
|
Printf.usage()
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ else:
|
|||||||
def __init__(self, ) -> None:
|
def __init__(self, ) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.initView()
|
self.initView()
|
||||||
self.setMinimumSize(600, 620)
|
self.setMinimumSize(800, 620)
|
||||||
self.setWindowTitle("Tidal-dl")
|
self.setWindowTitle("Tidal-dl")
|
||||||
|
|
||||||
def __info__(self, msg):
|
def __info__(self, msg):
|
||||||
@@ -120,6 +120,16 @@ else:
|
|||||||
item = QtWidgets.QTableWidgetItem(name)
|
item = QtWidgets.QTableWidgetItem(name)
|
||||||
self.c_tableInfo.setHorizontalHeaderItem(index, item)
|
self.c_tableInfo.setHorizontalHeaderItem(index, item)
|
||||||
|
|
||||||
|
# Create Tree View for playlists.
|
||||||
|
self.tree_playlists = QtWidgets.QTreeWidget()
|
||||||
|
self.tree_playlists.setAnimated(False)
|
||||||
|
self.tree_playlists.setIndentation(20)
|
||||||
|
self.tree_playlists.setSortingEnabled(True)
|
||||||
|
self.tree_playlists.resize(200, 400)
|
||||||
|
self.tree_playlists.setColumnCount(2)
|
||||||
|
self.tree_playlists.setHeaderLabels(("Name", "# Tracks"))
|
||||||
|
self.tree_playlists.setColumnWidth(0, 250)
|
||||||
|
|
||||||
# print
|
# print
|
||||||
self.c_printTextEdit = QtWidgets.QTextEdit()
|
self.c_printTextEdit = QtWidgets.QTextEdit()
|
||||||
self.c_printTextEdit.setReadOnly(True)
|
self.c_printTextEdit.setReadOnly(True)
|
||||||
@@ -148,7 +158,8 @@ else:
|
|||||||
self.funcGrid.addWidget(self.c_printTextEdit)
|
self.funcGrid.addWidget(self.c_printTextEdit)
|
||||||
|
|
||||||
self.mainGrid = QtWidgets.QGridLayout(self)
|
self.mainGrid = QtWidgets.QGridLayout(self)
|
||||||
self.mainGrid.addLayout(self.funcGrid, 0, 0)
|
self.mainGrid.addWidget(self.tree_playlists, 0, 0)
|
||||||
|
self.mainGrid.addLayout(self.funcGrid, 0, 1)
|
||||||
self.mainGrid.addWidget(self.c_widgetSetting, 0, 0)
|
self.mainGrid.addWidget(self.c_widgetSetting, 0, 0)
|
||||||
|
|
||||||
# connect
|
# connect
|
||||||
@@ -166,9 +177,9 @@ else:
|
|||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
self.c_tableInfo.setRowCount(0)
|
self.c_tableInfo.setRowCount(0)
|
||||||
|
|
||||||
self.s_type = self.c_combType.currentData()
|
self.s_type = self.c_combType.currentData()
|
||||||
self.s_text = self.c_lineSearch.text()
|
self.s_text = self.c_lineSearch.text()
|
||||||
|
|
||||||
if self.s_text.startswith('http'):
|
if self.s_text.startswith('http'):
|
||||||
tmpType, tmpId = TIDAL_API.parseUrl(self.s_text)
|
tmpType, tmpId = TIDAL_API.parseUrl(self.s_text)
|
||||||
if tmpType == Type.Null:
|
if tmpType == Type.Null:
|
||||||
@@ -269,6 +280,14 @@ else:
|
|||||||
def showSettings(self):
|
def showSettings(self):
|
||||||
self.c_widgetSetting.show()
|
self.c_widgetSetting.show()
|
||||||
|
|
||||||
|
def tree_items_playlists(self):
|
||||||
|
playlists = TIDAL_API.get_playlists()
|
||||||
|
|
||||||
|
for playlist in playlists:
|
||||||
|
item = QtWidgets.QTreeWidgetItem(self.tree_playlists)
|
||||||
|
item.setText(0, playlist.name)
|
||||||
|
item.setText(1, str(playlist.num_tracks))
|
||||||
|
|
||||||
def startGui():
|
def startGui():
|
||||||
aigpy.cmd.enableColor(False)
|
aigpy.cmd.enableColor(False)
|
||||||
|
|
||||||
@@ -278,6 +297,7 @@ else:
|
|||||||
window = MainView()
|
window = MainView()
|
||||||
window.show()
|
window.show()
|
||||||
window.checkLogin()
|
window.checkLogin()
|
||||||
|
window.tree_items_playlists()
|
||||||
|
|
||||||
app.exec_()
|
app.exec_()
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import json
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
from typing import Union, List
|
||||||
|
|
||||||
import aigpy
|
import aigpy
|
||||||
import base64
|
import base64
|
||||||
import requests
|
import requests
|
||||||
@@ -21,6 +23,8 @@ from model import *
|
|||||||
from enums import *
|
from enums import *
|
||||||
from settings import *
|
from settings import *
|
||||||
|
|
||||||
|
import tidalapi
|
||||||
|
|
||||||
# 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
|
||||||
@@ -157,8 +161,14 @@ class TidalAPI(object):
|
|||||||
def verifyAccessToken(self, accessToken) -> bool:
|
def verifyAccessToken(self, accessToken) -> bool:
|
||||||
header = {'authorization': 'Bearer {}'.format(accessToken)}
|
header = {'authorization': 'Bearer {}'.format(accessToken)}
|
||||||
result = requests.get('https://api.tidal.com/v1/sessions', headers=header).json()
|
result = requests.get('https://api.tidal.com/v1/sessions', headers=header).json()
|
||||||
|
|
||||||
if 'status' in result and result['status'] != 200:
|
if 'status' in result and result['status'] != 200:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Set tidalapi session.
|
||||||
|
self.session = tidalapi.session.Session()
|
||||||
|
self.session.load_oauth_session("Bearer", accessToken)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def refreshAccessToken(self, refreshToken) -> bool:
|
def refreshAccessToken(self, refreshToken) -> bool:
|
||||||
@@ -193,6 +203,7 @@ class TidalAPI(object):
|
|||||||
self.key.userId = result['userId']
|
self.key.userId = result['userId']
|
||||||
self.key.countryCode = result['countryCode']
|
self.key.countryCode = result['countryCode']
|
||||||
self.key.accessToken = accessToken
|
self.key.accessToken = accessToken
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def getAlbum(self, id) -> Album:
|
def getAlbum(self, id) -> Album:
|
||||||
@@ -233,6 +244,7 @@ class TidalAPI(object):
|
|||||||
|
|
||||||
def search(self, text: str, type: Type, offset: int = 0, limit: int = 10) -> SearchResult:
|
def search(self, text: str, type: Type, offset: int = 0, limit: int = 10) -> SearchResult:
|
||||||
typeStr = type.name.upper() + "S"
|
typeStr = type.name.upper() + "S"
|
||||||
|
|
||||||
if type == Type.Null:
|
if type == Type.Null:
|
||||||
typeStr = "ARTISTS,ALBUMS,TRACKS,VIDEOS,PLAYLISTS"
|
typeStr = "ARTISTS,ALBUMS,TRACKS,VIDEOS,PLAYLISTS"
|
||||||
|
|
||||||
@@ -474,6 +486,15 @@ class TidalAPI(object):
|
|||||||
|
|
||||||
raise Exception("No result.")
|
raise Exception("No result.")
|
||||||
|
|
||||||
|
def get_playlists(self) -> List[Union["Playlist", "UserPlaylist"]]:
|
||||||
|
playlists = self.session.user.playlists()
|
||||||
|
|
||||||
|
return playlists
|
||||||
|
|
||||||
|
def get_playlist_items(self, playlist_id: int) -> Union[tidalapi.Playlist, tidalapi.UserPlaylist]:
|
||||||
|
tracks = self.session.playlist(playlist_id).items()
|
||||||
|
|
||||||
|
return tracks
|
||||||
|
|
||||||
# Singleton
|
# Singleton
|
||||||
TIDAL_API = TidalAPI()
|
TIDAL_API = TidalAPI()
|
||||||
|
|||||||
Reference in New Issue
Block a user