Skip to content

Commit

Permalink
Merge branch 'Zeabyte/development' into custom-builds/tmp
Browse files Browse the repository at this point in the history
* Zeabyte/development:
  Prefer replaceAll over replace
  Optimized regex for replacing illegal characters in file names
  Added regular expression to replace common forbidden characters in export file name
  Changed whitespace replacement in export file names to underscore
  Added functionality to export a single playlist
  • Loading branch information
PikachuEXE committed Oct 7, 2024
2 parents 196d77b + ce443a8 commit ab1bee8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
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(' ', '_').replaceAll(/["%*/:<>?\\|]/g, '_')
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

0 comments on commit ab1bee8

Please sign in to comment.