Pad buttons now displays name when adding api-supported urls
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from modules.padslist import Pads
|
from modules.padslist import Pads
|
||||||
|
from gui.modules.pads.pad_name import get_button_name
|
||||||
from gui.gui import Ui_MainWindow
|
from gui.gui import Ui_MainWindow
|
||||||
from PyQt5 import QtWidgets, QtCore
|
from PyQt5 import QtWidgets, QtCore
|
||||||
from PyQt5.QtWidgets import QMainWindow
|
from PyQt5.QtWidgets import QMainWindow
|
||||||
@@ -20,11 +21,11 @@ def fill_pads(ui: Ui_MainWindow, MainWindow: QMainWindow, p: Player):
|
|||||||
item = first_pads_list[i]
|
item = first_pads_list[i]
|
||||||
if item == '':
|
if item == '':
|
||||||
continue
|
continue
|
||||||
ui.first_pads_dict[os.path.split(item)[-1][:24:]] = item
|
ui.first_pads_dict[get_button_name(item)] = item
|
||||||
button = QtWidgets.QPushButton()
|
button = QtWidgets.QPushButton()
|
||||||
button.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
|
button.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
|
||||||
QtWidgets.QSizePolicy.Expanding))
|
QtWidgets.QSizePolicy.Expanding))
|
||||||
button.setText(os.path.split(item)[-1][:24:])
|
button.setText(get_button_name(item))
|
||||||
button.clicked.connect(
|
button.clicked.connect(
|
||||||
(
|
(
|
||||||
lambda: (
|
lambda: (
|
||||||
@@ -46,11 +47,11 @@ def fill_pads(ui: Ui_MainWindow, MainWindow: QMainWindow, p: Player):
|
|||||||
item = second_pads_list[i]
|
item = second_pads_list[i]
|
||||||
if item == '':
|
if item == '':
|
||||||
continue
|
continue
|
||||||
ui.second_pads_dict[os.path.split(item)[-1][:24:]] = item
|
ui.second_pads_dict[get_button_name(item)] = item
|
||||||
button = QtWidgets.QPushButton()
|
button = QtWidgets.QPushButton()
|
||||||
button.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
|
button.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
|
||||||
QtWidgets.QSizePolicy.Expanding))
|
QtWidgets.QSizePolicy.Expanding))
|
||||||
button.setText(os.path.split(item)[-1][:24:])
|
button.setText(get_button_name(item))
|
||||||
button.clicked.connect(
|
button.clicked.connect(
|
||||||
(
|
(
|
||||||
lambda: (
|
lambda: (
|
||||||
|
|||||||
46
gui/modules/pads/pad_name.py
Normal file
46
gui/modules/pads/pad_name.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import validators
|
||||||
|
import pafy
|
||||||
|
import sclib
|
||||||
|
from modules.spotify.spotify_dl import Spotify
|
||||||
|
from modules.anonfiles.anonfiles import Anonfiles
|
||||||
|
import urllib.parse
|
||||||
|
import os.path
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def get_button_name(path: str, length: int = 24) -> str:
|
||||||
|
if not os.path.isfile('temp/' + '0' * 32):
|
||||||
|
with open('temp/' + '0' * 32, 'w') as f:
|
||||||
|
f.write('{}')
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open('temp/' + '0' * 32) as f:
|
||||||
|
name_cache = json.load(f)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
with open('temp/' + '0' * 32) as f:
|
||||||
|
f.write('{}')
|
||||||
|
name_cache = dict()
|
||||||
|
|
||||||
|
if name_cache.get(path):
|
||||||
|
return name_cache.get(path)
|
||||||
|
|
||||||
|
if validators.url(path):
|
||||||
|
if 'spotify' in path.lower():
|
||||||
|
name = (lambda x: f"{x.artist} - {x.name}")(Spotify().get_song(path))
|
||||||
|
elif 'youtu' in path.lower():
|
||||||
|
name = (lambda x: f"{x.title} ({x.author})")(pafy.new(path))
|
||||||
|
elif 'anonfiles' in path.lower():
|
||||||
|
name = urllib.parse.quote(Anonfiles.get_direct(path), safe=':/').split('/')[-1]
|
||||||
|
elif 'soundcloud' in path.lower():
|
||||||
|
name = (lambda x: f"{x.artist} - {x.title}")(sclib.SoundcloudAPI().resolve(path))
|
||||||
|
else:
|
||||||
|
name = path.split('/')[-1]
|
||||||
|
else:
|
||||||
|
name = os.path.split(path)[-1]
|
||||||
|
|
||||||
|
name_cache[path] = name[:length:]
|
||||||
|
with open('temp/' + '0' * 32, 'w') as f:
|
||||||
|
json.dump(name_cache, f)
|
||||||
|
|
||||||
|
return name[:length:]
|
||||||
Reference in New Issue
Block a user