コード例 #1
0
    def __init__(self, url, tags=None):
        super(DRealLocalMediaContent, self).__init__(url)
        if tags:
            self._tags = tags
        else:
            self._tags = Song(url)

        if 'title' in self._tags:
            self.title = self._tags['title']

        if 'artist' in self._tags:
            self.artist = self._tags['artist']

        if 'album' in self._tags:
            self.album = self._tags['album']

        if 'cover' in self._tags:
            if CoverWorker.isSongCoverExisted(self.artist, self.title):
                self.cover = CoverWorker.getCoverPathByArtistSong(
                    self.artist, self.title)
            elif CoverWorker.isAlbumCoverExisted(self.artist, self.album):
                self.cover = CoverWorker.getCoverPathByArtistAlbum(
                    self.artist, self.album)
            else:
                self.cover = CoverWorker.getCoverPathByArtist(self.artist)

        if 'duration' in self._tags:
            self.duration = self._tags['duration']
コード例 #2
0
 def saveTags(self):
     if not self.stopDownloaded:
         song = SongDict(self.filename)
         song.artist = self.singerName
         song.title = self.name
         song.album = self.albumName
         song.size = os.path.getsize(self.filename)
         song.saveTags()
コード例 #3
0
 def saveTags(self):
     if not self.stopDownloaded:
         song = SongDict(self.filename)
         song.artist = self.singerName
         song.title = self.name
         song.album = self.albumName
         song.size = os.path.getsize(self.filename)
         song.saveTags()
         self.addSongToDB.emit(self.filename)
コード例 #4
0
    def addSong(self, fpath):
        songDict = SongDict(fpath)
        ext, coverData = songDict.getMp3FontCover()
        if ext and coverData:
            if os.sep in songDict['artist']:
                songDict['artist'] = songDict['artist'].replace(os.sep, '')
            coverName = CoverWorker.songCoverPath(songDict['artist'],
                                                  songDict['title'])
            with open(coverName, 'wb') as f:
                f.write(coverData)
            songDict['cover'] = coverName
        if isinstance(songDict['artist'], str):
            songDict['artist'] = songDict['artist'].decode('utf-8')
        if isinstance(songDict['album'], str):
            songDict['album'] = songDict['album'].decode('utf-8')
        if isinstance(songDict['folder'], str):
            songDict['folder'] = songDict['folder'].decode('utf-8')

        url = songDict['url']
        if url in self._songsDict:
            self._songsDict[url] = songDict
            self._tempSongs[url] = songDict
            return
        else:
            self._songsDict[url] = songDict
            self._tempSongs[url] = songDict

        #add or update song view
        songObj = QmlSongObject(**songDict)
        self._songObjs[url] = songObj
        self._songObjsListModel.append(songObj)

        # add or update artist view
        artist = songDict['artist']
        if artist not in self._artistsDict:
            self._artistsDict[artist] = {
                'name': artist,
                'count': 0,
                'cover': CoverWorker.getCoverPathByArtist(artist)
            }
        _artistDict = self._artistsDict[artist]
        _artistDict['count'] = _artistDict['count'] + 1
        self._artistsDict[artist] = _artistDict

        if artist not in self._artistObjs:
            artistObj = QmlArtistObject(**_artistDict)
            self._artistObjs[artist] = artistObj
            self._artistObjsListModel.append(artistObj)
        else:
            artistObj = self._artistObjs[artist]
            index = self._artistObjs.keys().index(artist)
            artistObj.count = _artistDict['count']
            self._artistObjsListModel.setProperty(index, 'count',
                                                  _artistDict['count'])

        # add or update album view
        album = songDict['album']
        if album not in self._albumsDict:
            self._albumsDict[album] = {
                'name': album,
                'artist': artist,
                'count': 0,
                'cover': CoverWorker.getCoverPathByArtistAlbum(artist, album)
            }
        _albumDict = self._albumsDict[album]
        _albumDict['count'] = _albumDict['count'] + 1
        self._albumsDict[album] = _albumDict

        if album not in self._albumObjs:
            albumObj = QmlAlbumObject(**_albumDict)
            self._albumObjs[album] = albumObj
            self._albumObjsListModel.append(albumObj)
        else:
            albumObj = self._albumObjs[album]
            index = self._albumObjs.keys().index(album)
            albumObj.count = _albumDict['count']
            self._albumObjsListModel.setProperty(index, 'count',
                                                 _albumDict['count'])

        # add or update folder view
        folder = songDict['folder']
        if folder not in self._foldersDict:
            self._foldersDict[folder] = {
                'name': folder,
                'count': 0,
                'cover': CoverWorker.getFolderCover()
            }
        _folderDict = self._foldersDict[folder]
        _folderDict['count'] = _folderDict['count'] + 1
        self._foldersDict[folder] = _folderDict

        if folder not in self._folderObjs:
            folderObj = QmlFolderObject(**_folderDict)
            self._folderObjs[folder] = folderObj
            self._folderObjsListModel.append(folderObj)
        else:
            folderObj = self._folderObjs[folder]
            index = self._folderObjs.keys().index(folder)
            folderObj.count = _folderDict['count']
            self._folderObjsListModel.setProperty(index, 'count',
                                                  _folderDict['count'])

        self.songCountChanged.emit(len(self._songsDict))

        if contexts[
                'WindowManageWorker'].currentMusicManagerPageName == "ArtistPage":
            if not CoverWorker.isArtistCoverExisted(artist):
                self.downloadArtistCover.emit(artist)
コード例 #5
0
ファイル: muscimanageworker.py プロジェクト: binwen925/QMusic
    def addSong(self, fpath):
        songDict = SongDict(fpath)
        ext, coverData = songDict.getMp3FontCover()
        if ext and coverData:
            if os.sep in songDict['artist']:
                songDict['artist'] = songDict['artist'].replace(os.sep, '')
            coverName = CoverWorker.songCoverPath(songDict['artist'],
                                                  songDict['title'])
            with open(coverName, 'wb') as f:
                f.write(coverData)
            songDict['cover'] = coverName
        if isinstance(songDict['artist'], str):
            songDict['artist'] = songDict['artist'].decode('utf-8')
        if isinstance(songDict['album'], str):
            songDict['album'] = songDict['album'].decode('utf-8')
        if isinstance(songDict['folder'], str):
            songDict['folder'] = songDict['folder'].decode('utf-8')

        songDict['created_date'] = time.time()

        url = songDict['url']
        if url in self._songsDict:
            self._songsDict[url] = songDict
            self._tempSongs[url] = songDict
            return
        else:
            self._songsDict[url] = songDict
            self._tempSongs[url] = songDict

        #add or update song view
        songObj = QmlSongObject(**songDict)
        self._songObjs[url] = songObj
        self._songObjsListModel.append(songObj)

        # add or update artist view
        artist = songDict['artist']
        if artist not in self._artistsDict:
            self._artistsDict[artist] = {
                'name': artist,
                'count': 0,
                'cover': CoverWorker.getCoverPathByArtist(artist)
            }
        _artistDict = self._artistsDict[artist]
        _artistDict['count'] = _artistDict['count'] + 1
        self._artistsDict[artist] = _artistDict

        if artist not in self._artistObjs:
            artistObj = QmlArtistObject(**_artistDict)
            self._artistObjs[artist] = artistObj
            self._artistObjsListModel.append(artistObj)
        else:
            artistObj = self._artistObjs[artist]
            index = self._artistObjs.keys().index(artist)
            artistObj.count = _artistDict['count']
            self._artistObjsListModel.setProperty(index, 'count',
                                                  _artistDict['count'])

        # add or update album view
        album = songDict['album']
        if album not in self._albumsDict:
            self._albumsDict[album] = {
                'name': album,
                'artist': artist,
                'count': 0,
                'cover': CoverWorker.getCoverPathByArtistAlbum(artist, album)
            }
        _albumDict = self._albumsDict[album]
        _albumDict['count'] = _albumDict['count'] + 1
        self._albumsDict[album] = _albumDict

        if album not in self._albumObjs:
            albumObj = QmlAlbumObject(**_albumDict)
            self._albumObjs[album] = albumObj
            self._albumObjsListModel.append(albumObj)
        else:
            albumObj = self._albumObjs[album]
            index = self._albumObjs.keys().index(album)
            albumObj.count = _albumDict['count']
            self._albumObjsListModel.setProperty(index, 'count',
                                                 _albumDict['count'])

        # add or update folder view
        folder = songDict['folder']
        if folder not in self._foldersDict:
            self._foldersDict[folder] = {
                'name': folder,
                'count': 0,
                'cover': CoverWorker.getFolderCover()
            }
        _folderDict = self._foldersDict[folder]
        _folderDict['count'] = _folderDict['count'] + 1
        self._foldersDict[folder] = _folderDict

        if folder not in self._folderObjs:
            folderObj = QmlFolderObject(**_folderDict)
            self._folderObjs[folder] = folderObj
            self._folderObjsListModel.append(folderObj)
        else:
            folderObj = self._folderObjs[folder]
            index = self._folderObjs.keys().index(folder)
            folderObj.count = _folderDict['count']
            self._folderObjsListModel.setProperty(index, 'count',
                                                  _folderDict['count'])

        self.songCountChanged.emit(len(self._songsDict))

        # if windowManageWorker.currentMusicManagerPageName == "ArtistPage":
        if not CoverWorker.isArtistCoverExisted(artist):
            self.downloadArtistCover.emit(artist)

        if not CoverWorker.isAlbumCoverExisted(artist, album):
            self.downloadAlbumCover.emit(artist, album)