Skip to content

Commit

Permalink
save selected local music folders
Browse files Browse the repository at this point in the history
  • Loading branch information
weiy committed Jan 23, 2019
1 parent 9656073 commit be6a80a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
33 changes: 27 additions & 6 deletions MusicPlayer/features/configNativeFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import os
import glob
import pickle
import os.path

try:
import eyed3
except ImportError:
print('eyed3没有成功加载或安装,请不要使用本地音乐功能!')

from base import QFileDialog, QObject, QTableWidgetItem
from base import QFileDialog, QObject, QTableWidgetItem, checkFolder
from addition import itv2time


Expand All @@ -31,6 +32,8 @@ def findFolder(topFolder):


class ConfigNative(QObject):
loadLocalFolder = 'cookies/native/local.cks'
allCookiesFolder = [loadLocalFolder]

def __init__(self, native):
super(ConfigNative, self).__init__()
Expand All @@ -40,6 +43,7 @@ def __init__(self, native):
self.folder = []

self.bindConnect()
self.loadCookies()

def bindConnect(self):
self.native.selectButton.clicked.connect(self.selectFolder)
Expand All @@ -53,8 +57,13 @@ def selectFolder(self):
else:
self.folder.append(selectFolder)

mediaFiles = glob.glob(selectFolder+'/*.mp3')
allFolder = getAllFolder(selectFolder)
self.loadMusic()

def loadMusic(self):

for folder in self.folder:
mediaFiles = glob.glob(folder+'/*.mp3')
allFolder = getAllFolder(folder)
for i in allFolder:
mediaFiles.extend(glob.glob(i+'/*.mp3'))

Expand All @@ -74,15 +83,15 @@ def selectFolder(self):
author = music.tag.artist

if not name:
filePath = i[1].replace(selectFolder, '')
filePath = i[1].replace(folder, '')
name = filePath[1:][:-4]
if not author:
author = ''
except:
try:
# TODO
# if more folders exist.
filePath = i[1].replace(selectFolder, '')
filePath = i[1].replace(folder, '')
name = filePath[1:][:-4]
except Exception as e:
name = i[1]
Expand All @@ -102,4 +111,16 @@ def itemDoubleClickedEvent(self):
currentRow = self.native.singsTable.currentRow()
data = self.musicList[currentRow]

self.native.parent.playWidgets.setPlayerAndPlayList(data)
self.native.parent.playWidgets.setPlayerAndPlayList(data)

@checkFolder(allCookiesFolder)
def saveCookies(self):
with open(self.loadLocalFolder, 'wb') as f:
pickle.dump(self.folder, f)

@checkFolder(allCookiesFolder)
def loadCookies(self):
with open(self.loadLocalFolder, 'rb') as f:
self.folder = pickle.load(f)

self.loadMusic()
3 changes: 2 additions & 1 deletion MusicPlayer/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def closeEvent(self, event):
self.header.config.saveCookies()
self.playWidgets.saveCookies()
self.downloadFrame.config.saveCookies()

self.nativeMusic.config.saveCookies()

# 关闭并保存数据库
self.db.commitAndClose()

Expand Down

0 comments on commit be6a80a

Please sign in to comment.