(accessToken: string, playlistsData: PlaylistsData, searchQuery: string, config: any)
| 25 | } |
| 26 | |
| 27 | async export(accessToken: string, playlistsData: PlaylistsData, searchQuery: string, config: any) { |
| 28 | let playlistFileNames = new Set<string>() |
| 29 | let playlistCsvExports = new Array<string>() |
| 30 | |
| 31 | const playlists = searchQuery === "" ? await playlistsData.all() : await playlistsData.search(searchQuery) |
| 32 | |
| 33 | let doneCount = 0 |
| 34 | |
| 35 | for (const playlist of playlists) { |
| 36 | this.props.onPlaylistExportStarted(playlist.name, doneCount) |
| 37 | |
| 38 | let exporter = new PlaylistExporter(accessToken, playlist, config) |
| 39 | let csvData = await exporter.csvData() |
| 40 | let fileName = exporter.fileName(false) |
| 41 | |
| 42 | for (let i = 1; playlistFileNames.has(fileName + exporter.fileExtension()); i++) { |
| 43 | fileName = exporter.fileName(false) + ` (${i})` |
| 44 | } |
| 45 | |
| 46 | playlistFileNames.add(fileName + exporter.fileExtension()) |
| 47 | playlistCsvExports.push(csvData) |
| 48 | |
| 49 | doneCount++ |
| 50 | } |
| 51 | |
| 52 | this.props.onPlaylistsExportDone() |
| 53 | |
| 54 | var zip = new JSZip() |
| 55 | |
| 56 | Array.from(playlistFileNames).forEach(function (fileName, i) { |
| 57 | zip.file(fileName, playlistCsvExports[i]) |
| 58 | }) |
| 59 | |
| 60 | zip.generateAsync({ type: "blob" }).then(function (content) { |
| 61 | saveAs(content, "spotify_playlists.zip"); |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | exportPlaylists = () => { |
| 66 | this.setState( |
no test coverage detected