Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to export a single playlist #5779

Merged
merged 7 commits into from
Nov 4, 2024
Merged
38 changes: 38 additions & 0 deletions src/renderer/components/playlist-info/playlist-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
ctrlFHandler,
formatNumber,
showToast,
getTodayDateStrLocalTimezone,
writeFileFromDialog,
showSaveDialog,
} from '../../helpers/utils'
import debounce from 'lodash.debounce'

Expand Down Expand Up @@ -412,6 +415,41 @@ export default defineComponent({
showToast(this.playlistDeletionDisabledLabel)
},

handlePlaylistExport: async function () {
const dateStr = getTodayDateStrLocalTimezone()
const title = this.selectedUserPlaylist.playlistName.replaceAll(' ', '-')
Zeabyte marked this conversation as resolved.
Show resolved Hide resolved
const exportFileName = 'freetube-playlist-' + title + '-' + dateStr + '.db'

const options = {
defaultPath: exportFileName,
filters: [
{
name: 'Database File',
extensions: ['db']
}
]
}

const data = JSON.stringify(this.selectedUserPlaylist) + '\n'

// See data-settings.js `promptAndWriteToFile`
const response = await showSaveDialog(options)
if (response.canceled || response.filePath === '') {
// User canceled the save dialog
return
}

try {
await writeFileFromDialog(response, data)
} catch (writeErr) {
const message = this.$t('Settings.Data Settings.Unable to write file')
showToast(`${message}: ${writeErr}`)
return
}

showToast(this.$t('User Playlists.The playlist has been successfully exported'))
},

exitEditMode: function () {
this.editMode = false

Expand Down
7 changes: 7 additions & 0 deletions src/renderer/components/playlist-info/playlist-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@
theme="destructive"
@click="showRemoveDuplicateVideosPrompt = true"
/>
<ft-icon-button
v-if="!editMode"
:title="$t('User Playlists.Export Playlist')"
:icon="['fas', 'file-arrow-down']"
theme="secondary"
@click="handlePlaylistExport"
/>
<ft-icon-button
v-if="!editMode && userPlaylistAnyVideoWatched"
:title="$t('User Playlists.Remove Watched Videos')"
Expand Down
2 changes: 2 additions & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ User Playlists:
Remove Watched Videos: Remove Watched Videos
Enable Quick Bookmark With This Playlist: Enable Quick Bookmark With This Playlist
Quick Bookmark Enabled: Quick Bookmark Enabled
Export Playlist: Export This Playlist
The playlist has been successfully exported: The playlist has been successfully exported
Are you sure you want to remove {playlistItemCount} duplicate videos from this playlist? This cannot be undone: Are you sure you want to remove 1 duplicate video from this playlist? This cannot be undone. | Are you sure you want to remove {playlistItemCount} duplicate videos from this playlist? This cannot be undone.
Are you sure you want to remove {playlistItemCount} watched videos from this playlist? This cannot be undone: Are you sure you want to remove 1 watched video from this playlist? This cannot be undone. | Are you sure you want to remove {playlistItemCount} watched videos from this playlist? This cannot be undone.
Delete Playlist: Delete Playlist
Expand Down