Skip to content

Commit

Permalink
Ver.2.3.0
Browse files Browse the repository at this point in the history
Signed-off-by: zlk-sys <18079031125@163.com>
  • Loading branch information
zlk-sys committed May 5, 2024
1 parent 9717432 commit 4a58723
Show file tree
Hide file tree
Showing 27 changed files with 359 additions and 1,430 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
31 changes: 8 additions & 23 deletions Interface/mymusic_beta.py → Interface/localmusics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
import sys

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QListWidgetItem, QListWidget, QWidget, QHBoxLayout, QLabel, QVBoxLayout
from PyQt5.QtWidgets import QApplication, QListWidgetItem, QWidget, QHBoxLayout, QVBoxLayout

from qfluentwidgets import ListView, setTheme, Theme, ListWidget
from qfluentwidgets import ListWidget
import os
from qfluentwidgets import ToolButton, PrimaryToolButton
from qfluentwidgets import FluentIcon as FIF
import subprocess
from helper.config import cfg
from helper.inital import mkf

path = cfg.get(cfg.downloadFolder)
if not os.path.exists(path):
os.makedirs(path)
mkf()
def get_all_music():
all_music = []
path = cfg.get(cfg.downloadFolder)
Expand All @@ -23,12 +22,12 @@ def get_all_music():
all_music.append(file_name)
return all_music

class Demo(QWidget):
class localmusics(QWidget):

def __init__(self):
super().__init__()
# setTheme(Theme.DARK)
self.setObjectName("Demo")
self.setObjectName("localmusics")
self.hBoxLayout = QHBoxLayout(self)
self.vBoxLayout = QVBoxLayout(self)
self.listWidget = ListWidget(self)
Expand All @@ -41,8 +40,7 @@ def __init__(self):
# item.setIcon(QIcon(':/qfluentwidgets/images/logo.png'))
# item.setCheckState(Qt.Unchecked)
self.listWidget.addItem(item)

self.setStyleSheet("Demo{background: rgb(249, 249, 249)} ")

self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.listWidget.clicked.connect(self.openbutton)
self.resize(300, 400)
Expand Down Expand Up @@ -91,17 +89,4 @@ def ref(self):
stands = self.data
for stand in stands:
item = QListWidgetItem(stand)
self.listWidget.addItem(item)


if __name__ == "__main__":
# enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

app = QApplication(sys.argv)
w = Demo()
w.show()
app.exec()
self.listWidget.addItem(item)
52 changes: 0 additions & 52 deletions Interface/note.py

This file was deleted.

95 changes: 38 additions & 57 deletions Interface/playlist.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import json
import AZMusicAPI
from PyQt5.QtCore import QModelIndex, Qt
from PyQt5.QtCore import QTimer, QThread
from PyQt5.QtWidgets import QApplication, QTableWidgetItem, QWidget, QAbstractItemView, QHBoxLayout
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot
from PyQt5 import QtCore, QtWidgets
import win32api, win32con
from PyQt5.QtCore import QThread
from PyQt5.QtWidgets import QTableWidgetItem, QWidget, QAbstractItemView
from qfluentwidgets import ComboBox, LineEdit, PushButton, SubtitleLabel, TableWidget, ProgressBar
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5 import QtCore
import os
import requests
from mutagen.easyid3 import EasyID3
from helper.config import cfg
from helper.getvalue import playlist_search_log, apipath, playlist_download_log, autoapi, playlistpath
from helper.flyoutmsg import dlerr, dlsuc

try:
u = open("api.json", "r")
u = open(apipath, "r")
data = json.loads(u.read())
api = data["api"]
u.close()
except:
api = "https://ncma.zenglingkun.cn/"

if not os.path.isdir("playlist"):
os.mkdir("playlist")
api = autoapi


class downloading(QThread):
Expand All @@ -29,7 +27,7 @@ class downloading(QThread):
@pyqtSlot()
def run(self):
musicpath = cfg.get(cfg.downloadFolder)
u = open("log\\list_download.json", "r")
u = open(playlist_download_log, "r")
data = json.loads(u.read())
u.close()
id = data["id"]
Expand All @@ -38,11 +36,10 @@ def run(self):
singer = data["singer"]
url = AZMusicAPI.geturl(id=id, api=api)
if url == "Error 3":
win32api.MessageBox(0, '这首歌曲无版权,暂不支持下载', '错误', win32con.MB_ICONWARNING)
dlerr(content='这首歌曲无版权,暂不支持下载', parent=self)
return 0
elif url == "NetworkError":
win32api.MessageBox(0, '您可能是遇到了以下其一问题:网络错误 / 服务器宕机 / IP被封禁', '错误',
win32con.MB_ICONWARNING)
dlerr(content='您可能是遇到了以下其一问题:网络错误 / 服务器宕机 / IP被封禁', parent = self)
return 0
response = requests.get(url, stream=True)
file_size = int(response.headers.get('content-length', 0))
Expand All @@ -64,7 +61,7 @@ class getlist(QThread):

@pyqtSlot()
def run(self):
u = open("log\\list_search.json", "r")
u = open(playlist_search_log, "r")
data = json.loads(u.read())
u.close()
type_value = data["type_value"]
Expand All @@ -87,8 +84,8 @@ def run(self):
if data_y["code"] != 400:
name = data["name"]
data = data["tracks"]
if not os.path.isdir("playlist\\" + name):
os.mkdir("playlist\\{}".format(name))
if not os.path.isdir(playlistpath + "\\" + name):
os.mkdir("{}\\{}".format(playlistpath, name))
data_v = []
try:
for i in range(len(data)):
Expand All @@ -102,7 +99,7 @@ def run(self):
except:
data_v.append({"id": '-1', "name": 'error', "artists": 'error',
"album": 'error'})
u = open("playlist\\{}\\index.json".format(name), "w")
u = open("{}\\{}\\index.json".format(playlistpath, name), "w")
u.write(json.dumps({"content": data_v}))
u.close()
else:
Expand All @@ -114,8 +111,8 @@ def run(self):
if data_y["code"] == 200:
name = data["name"]
data = data["tracks"]
if not os.path.exists("playlist\\{}".format(name)):
os.mkdir("playlist\\{}".format(name))
if not os.path.exists("{}\\{}".format(playlistpath, name)):
os.mkdir("{}\\{}".format(playlistpath, name))
data_v = []
try:
for i in range(len(data)):
Expand All @@ -129,7 +126,7 @@ def run(self):
except:
data_v.append({"id": '-1', "name": 'error', "artists": 'error',
"album": 'error'})
u = open("playlist\\{}\\index.json".format(name), "w")
u = open("{}\\{}\\index.json".format(playlistpath, name), "w")
u.write(json.dumps({"content": data_v}))
u.close()
self.finished.emit()
Expand Down Expand Up @@ -194,7 +191,7 @@ def __init__(self):
self.lworker.finished.connect(self.search)
self.dworker = downloading()
self.dworker.finished.connect(self.download)
data = get_folders("playlist")
data = get_folders(playlistpath)
self.TableWidget.setRowCount(len(data))
self.TableWidget.clearContents()
for i in range(len(data)):
Expand All @@ -214,15 +211,15 @@ def searchstart(self):
self.PushButton.setEnabled(False)
# self.getlist_worker.started.connect(
# lambda: self.lworker.run(type_value=self.ComboBox.text(), value=self.LineEdit.text(), api_value=api))
u = open("log\\list_search.json", "w")
u = open(playlist_search_log, "w")
u.write(json.dumps({"type_value": self.ComboBox.text(), "value": self.LineEdit.text(), "api_value": api}))
u.close()
self.lworker.start()

def music(self):
try:
name = get_folders("playlist")[self.TableWidget.currentIndex().row()]
u = open("playlist\\{}\\index.json".format(name), "r")
name = get_folders(playlistpath)[self.TableWidget.currentIndex().row()]
u = open("{}\\{}\\index.json".format(playlistpath, name), "r")
data = json.loads(u.read())
u.close()
data = data["content"]
Expand All @@ -242,11 +239,10 @@ def music(self):
self.TableWidget_2.resizeColumnsToContents()
self.TableWidget_2.setRowCount(len(data))
except:
win32api.MessageBox(0, '您双击的行无数据', '错误', win32con.MB_ICONWARNING)

dlerr(content='您双击的行无数据', parent=self)
@pyqtSlot()
def search(self):
data = get_folders("playlist")
data = get_folders(playlistpath)
self.TableWidget.setRowCount(len(data))
self.TableWidget.clearContents()
for i in range(len(data)):
Expand All @@ -264,8 +260,14 @@ def rundownload(self):
self.PushButton_2.setEnabled(False)
self.pro_bar.setValue(0)
self.pro_bar.setHidden(False)
row = self.TableWidget_2.currentIndex().row()
id_v = str(self.TableWidget_2.item(row, 0).text())
try:
row = self.TableWidget_2.currentIndex().row()
id_v = str(self.TableWidget_2.item(row, 0).text())
except AttributeError:
self.TableWidget_2.clearSelection()
self.PushButton_2.setEnabled(False)
dlerr(content='您选中的行无数据', parent=self)
return 0
if id_v != "":
song_id = id_v
song = str(self.TableWidget_2.item(row, 1).text())
Expand All @@ -275,26 +277,24 @@ def rundownload(self):
if os.path.exists(cfg.get(cfg.downloadFolder)) == False:
os.mkdir(cfg.get(cfg.downloadFolder))
except:
win32api.MessageBox(0, '音乐下载路径无法读取\创建失败', '错误', win32con.MB_ICONWARNING)
dlerr(content='音乐下载路径无法读取\创建失败', parent=self)
return 0
# self.download_worker.started.connect(
# lambda: self.dworker.run(id=song_id, api=api, song=song, singer=singer))
if not os.path.exists("log"):
os.mkdir("log")
u = open("log\\list_download.json", 'w')
u = open(playlist_download_log, 'w')
u.write(json.dumps({"id": song_id, "api": api, "song": song, "singer": singer, "album": album}))
u.close()
self.dworker.start()
else:
self.TableWidget_2.clearSelection()
self.PushButton_2.setEnabled(False)
win32api.MessageBox(0, '您选中的行无数据', '错误', win32con.MB_ICONWARNING)
dlerr(content='您选中的行无数据', parent=self)

def download(self, pro):
musicpath = cfg.get(cfg.downloadFolder)
if pro == "200":
self.pro_bar.setValue(100)
u = open("log\\list_download.json", "r")
u = open(playlist_download_log, "r")
data = json.loads(u.read())
u.close()
song = data["song"]
Expand All @@ -308,7 +308,7 @@ def download(self, pro):
audio["artist"] = singer
audio.save()
text = '音乐下载完成!\n歌曲名:{}\n艺术家:{}\n保存路径:{}'.format(song, singer, path)
win32api.MessageBox(0, text, '音乐下载完成', win32con.MB_OK)
dlsuc(content=text, parent=self)
self.TableWidget_2.clearSelection()
self.PushButton_2.setEnabled(False)
self.pro_bar.setHidden(True)
Expand All @@ -324,10 +324,6 @@ def retranslateUi(self):
self.PushButton_2.setText(_translate("self", "下载"))
self.PushButton_2.setEnabled(False)


from qfluentwidgets import ComboBox, LineEdit, PushButton, SubtitleLabel, TableWidget, ProgressBar


def get_folders(folder_path):
folders = []

Expand All @@ -337,18 +333,3 @@ def get_folders(folder_path):
folders.append(item)

return folders


if __name__ == "__main__":
import sys

QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = playlist()
ui.__init__()
Form.show()
sys.exit(app.exec_())
Loading

0 comments on commit 4a58723

Please sign in to comment.