def __thread_func__(model: TaskItemModel, track: Track): mag, track.album = API.getAlbum(track.album.id) model.path = getBasePath(track) cover = API.getCoverData(track.album.cover) model.SIGNAL_REFRESH_VIEW.emit('setPic', cover) model.SIGNAL_REFRESH_VIEW.emit('addListItems', [track]) time.sleep(1)
def debug(): checkLogin() API.key.accessToken = TOKEN.accessToken API.key.userId = TOKEN.userid API.key.countryCode = TOKEN.countryCode # https://api.tidal.com/v1/mixes/{01453963b7dbd41c8b82ccb678d127/items?countryCode={country} API.getMix("01453963b7dbd41c8b82ccb678d127") # msg, result = API.search('Mojito', Type.Null, 0, 10) msg, lyric = API.getLyrics('144909909') pass
def __playlist__(conf, obj): Printf.playlist(obj) msg, tracks, videos = API.getItems(obj.uuid, Type.Playlist) if not aigpy.string.isNull(msg): Printf.err(msg) return for index, item in enumerate(tracks): mag, album = API.getAlbum(item.album.id) item.trackNumberOnPlaylist = index + 1 downloadTrack(item, album, obj) if conf.saveCovers and not conf.usePlaylistFolder: __downloadCover__(conf, album) for item in videos: downloadVideo(item, None)
def __downloadCover__(conf, album): if album == None: return path = getAlbumPath(conf, album) + '/cover.jpg' url = API.getCoverUrl(album.cover, "1280", "1280") if url is not None: aigpy.net.downloadFile(url, path)
def start(user, conf, string): __loadAPI__(user) if aigpy.string.isNull(string): Printf.err('Please enter something.') return strings = string.split(" ") for item in strings: if aigpy.string.isNull(item): continue if os.path.exists(item): file(user, conf, item) return msg, etype, obj = API.getByString(item) if etype == Type.Null or not aigpy.string.isNull(msg): Printf.err(msg + " [" + item + "]") return if etype == Type.Album: __album__(conf, obj) if etype == Type.Track: __track__(conf, obj) if etype == Type.Video: __video__(conf, obj) if etype == Type.Artist: __artist__(conf, obj) if etype == Type.Playlist: __playlist__(conf, obj) if etype == Type.Mix: __mix__(conf, obj)
def __thread_func__(model: TaskItemModel, album: Album): cover = API.getCoverData(album.cover) model.SIGNAL_REFRESH_VIEW.emit('setPic', cover) msg, tracks, videos = API.getItems(album.id, Type.Album) if not aigpy.stringHelper.isNull(msg): model.view.setErrmsg(msg) return for item in tracks: item.album = album for item in videos: item.album = album model.SIGNAL_REFRESH_VIEW.emit('addListItems', tracks + videos) time.sleep(1)
def __artist__(conf, obj): msg, albums = API.getArtistAlbums(obj.id, conf.includeEP) Printf.artist(obj, len(albums)) if not aigpy.string.isNull(msg): Printf.err(msg) return for item in albums: __album__(conf, item)
def __thread_func__(model: TaskItemModel, playlist: Playlist): cover = API.getCoverData(playlist.squareImage) model.SIGNAL_REFRESH_VIEW.emit('setPic', cover) msg, tracks, videos = API.getItems(playlist.uuid, Type.Playlist) if not aigpy.stringHelper.isNull(msg): model.view.setErrmsg(msg) return for item in tracks: mag, album = API.getAlbum(item.album.id) item.playlist = playlist item.album = album for item in videos: item.playlist = playlist model.SIGNAL_REFRESH_VIEW.emit('addListItems', tracks + videos) time.sleep(1)
def __mix__(conf, obj: Mix): Printf.mix(obj) for index, item in enumerate(obj.tracks): mag, album = API.getAlbum(item.album.id) item.trackNumberOnPlaylist = index + 1 downloadTrack(item, album) if conf.saveCovers and not conf.usePlaylistFolder: __downloadCover__(conf, album) for item in obj.videos: downloadVideo(item, None)
def login(): print(LANG.AUTH_START_LOGIN) msg, check = API.getDeviceCode() if not check: Printf.err(msg) return # print(LANG.AUTH_LOGIN_CODE.format(green(API.key.userCode))) print(LANG.AUTH_NEXT_STEP.format(green("http://" + API.key.verificationUrl + "/" + API.key.userCode), yellow(displayTime(API.key.authCheckTimeout)))) print(LANG.AUTH_WAITING) loginByWeb() return
def setTableItems(self, stype: Type, indexOffset: int, result: tidal_dl.model.SearchResult): if stype == Type.Album: items = result.albums.items datas = [] for index, item in enumerate(items): rowData = [ str(index + 1 + indexOffset), QUrl(API.getCoverUrl(item.cover)), API.getFlag(item, Type.Album, True), item.title, item.artists[0].name, str(item.releaseDate), getDurationString(item.duration) ] datas.append(rowData) elif stype == Type.Track: items = result.tracks.items datas = [] for index, item in enumerate(items): rowData = [ str(index + 1 + indexOffset), API.getFlag(item, Type.Track, True), item.title, item.album.title, item.artists[0].name, getDurationString(item.duration) ] datas.append(rowData) elif stype == Type.Video: items = result.videos.items datas = [] for index, item in enumerate(items): rowData = [ str(index + 1 + indexOffset), QUrl(API.getCoverUrl(item.imageID)), API.getFlag(item, Type.Video, True), item.title, item.artists[0].name, getDurationString(item.duration) ] datas.append(rowData) elif stype == Type.Playlist: items = result.playlists.items datas = [] for index, item in enumerate(items): rowData = [ str(index + 1 + indexOffset), QUrl(API.getCoverUrl(item.squareImage)), item.title, '', getDurationString(item.duration) ] datas.append(rowData) for index, rowData in enumerate(datas): for colIdx, obj in enumerate(rowData): self._table[stype].addItem(index, colIdx, obj) self.__clearTableRowItems__(stype, len(items)) self._table[stype].viewport().update()
def __album__(conf, obj): Printf.album(obj) msg, tracks, videos = API.getItems(obj.id, Type.Album) if not aigpy.string.isNull(msg): Printf.err(msg) return if conf.saveAlbumInfo: __saveAlbumInfo__(conf, obj, tracks) if conf.saveCovers: __downloadCover__(conf, obj) for item in tracks: downloadTrack(item, obj) for item in videos: downloadVideo(item, obj)
def setAccessToken(): while True: print("-------------AccessToken---------------") token = Printf.enter("accessToken('0' go back):") if token == '0': return msg, check = API.loginByAccessToken(token, TOKEN.userid) if not check: Printf.err(msg) continue break print("-------------RefreshToken---------------") refreshToken = Printf.enter("refreshToken('0' to skip):") if refreshToken == '0': refreshToken = TOKEN.refreshToken TOKEN.accessToken = token TOKEN.refreshToken = refreshToken TOKEN.expiresAfter = 0 TOKEN.countryCode = API.key.countryCode TokenSettings.save(TOKEN)
def __thread_search__(model: SearchModel, index: int): typeIndex = model.view.getSelectedTabIndex() searchText = model.view.getSearchText() if aigpy.stringHelper.isNull(searchText): model._lock.release() return # search limit = 20 offset = (index - 1) * limit stype = tidal_dl.Type(typeIndex) msg, model._resultData = API.search(searchText, stype, offset, limit) if not aigpy.stringHelper.isNull(msg): model.SIGNAL_REFRESH_VIEW.emit('setSearchErrmsg', msg) model._lock.release() return # get page index total = model.__getSumByResult__(stype) if total <= 0: model.SIGNAL_REFRESH_VIEW.emit('setSearchErrmsg', 'Search results are empty...') model._lock.release() return maxIdx = total // limit + (1 if total % limit > 0 else 0) if index > maxIdx: model._lock.release() return # set view model.SIGNAL_REFRESH_VIEW.emit('setPageIndex', (index, maxIdx)) model.SIGNAL_REFRESH_VIEW.emit('setTableItems', (stype, offset, model._resultData)) model._lock.release()
def __thread_func__(model: TaskItemModel, video: Video): cover = API.getCoverData(video.imageID) model.SIGNAL_REFRESH_VIEW.emit('setPic', cover) model.SIGNAL_REFRESH_VIEW.emit('addListItems', [video]) time.sleep(1)
def __track__(conf, obj): msg, album = API.getAlbum(obj.album.id) if conf.saveCovers: __downloadCover__(conf, album) downloadTrack(obj, album)
def __thread_getCode__(model: LoginModel): msg, check = API.getDeviceCode() if check: model.SIGNAL_REFRESH_VIEW.emit('userCode', API.key.userCode) else: model.SIGNAL_REFRESH_VIEW.emit('showMsg', msg)