Skip to content

Commit

Permalink
fix missevan kit 1.0 some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tich committed Aug 26, 2018
1 parent c8ec5cd commit 725cdc2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
27 changes: 22 additions & 5 deletions missevan-kit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import os
import threading
from contextlib import closing
import time
import random

base_headers = {
'Accept':'application/json, text/javascript, */*; q=0.01',
Expand Down Expand Up @@ -68,6 +70,8 @@ def connectSlots(self):

self.toolButton.clicked.connect(lambda: QDesktopServices.openUrl(QUrl.fromLocalFile("./sound")))

self.clearAll.clicked.connect(self.clearAllDownloaded)

def searchInfo(self):
text = self.lineEdit.text()
if not text:
Expand All @@ -93,6 +97,7 @@ def getSoundSrc(self, sid, single = True):
base_headers['Referer'] = 'http://www.missevan.com/sound/player?id=' + sid
r =requests.get(url, headers = base_headers)
data = r.json()
print(type(sid))
if data['state'] == 'error':
return
user = data['info']['user']['username']
Expand Down Expand Up @@ -120,6 +125,7 @@ def getListSrc(self, sound):
global listInfo
for x in sound:
self.getSoundSrc(x, False)
time.sleep(0.1+random.randint(100, 200)/100)
self.tableWidget.clearContents()
self.tableWidget.setRowCount(len(listInfo))
for r, x in enumerate(listInfo):
Expand Down Expand Up @@ -171,16 +177,19 @@ def getLikeList(self, uid):

def downloadSound(self):
row = self.tableWidget.rowCount()
self.tableWidget2.clearContents()
self.tableWidget2.setRowCount(row)
row2 = self.tableWidget2.rowCount()
# self.tableWidget2.clearContents()
if not row:
return
self.tableWidget2.setRowCount(row+row2)
for x in range(row):
item = QTableWidgetItem(self.tableWidget.item(x, 1).text())
self.tableWidget2.setItem(x, 0, item)
self.tableWidget2.setItem(x, 1, QTableWidgetItem("下载中"))
self.tableWidget2.setItem(x+row2, 0, item)
self.tableWidget2.setItem(x+row2, 1, QTableWidgetItem("下载中"))
# qpb = QProgressBar()
# qpb.setValue(0)
# self.tableWidget2.setCellWidget(x, 1, qpb)
threading.Thread(target=self.downloadSingle, args = (x, )).start()
threading.Thread(target=self.downloadSingle, args = (x+row2, )).start()

def downloadSingle(self, index):
url = 'http://192.168.73.133/static.missevan.com/MP3/' + self.tableWidget.item(index, 2).text()
Expand All @@ -200,6 +209,14 @@ def downloadSingle(self, index):
# count += len(data)
self.tableWidget2.setItem(index, 1, QTableWidgetItem("下载完成"))

def clearAllDownloaded(self):
row = self.tableWidget2.rowCount()
if not row:
return
for x in range(row-1, -1, -1):
if self.tableWidget2.item(x, 1).text() == '下载完成':
self.tableWidget2.removeRow(x)

if __name__ == "__main__":
app = QApplication(sys.argv)
w = MissevanKit()
Expand Down
5 changes: 5 additions & 0 deletions missevan-kit/ui_mwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def setupUi(self, MWin):
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem)
self.clearAll = QtWidgets.QToolButton(self.tab2)
self.clearAll.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.clearAll.setObjectName("clearAll")
self.horizontalLayout_3.addWidget(self.clearAll)
self.toolButton = QtWidgets.QToolButton(self.tab2)
self.toolButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.toolButton.setObjectName("toolButton")
Expand Down Expand Up @@ -236,6 +240,7 @@ def retranslateUi(self, MWin):
item.setText(_translate("MWin", "标题"))
item = self.tableWidget2.horizontalHeaderItem(1)
item.setText(_translate("MWin", "下载进度"))
self.clearAll.setText(_translate("MWin", "清空已下载"))
self.toolButton.setText(_translate("MWin", "打开保存文件夹"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab2), _translate("MWin", "下载"))
self.plainTextEdit.setPlainText(_translate("MWin", "GitHub:LewisTian\n"
Expand Down

0 comments on commit 725cdc2

Please sign in to comment.