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
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, '_')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to replace more chars
See
https://www.mtu.edu/umc/services/websites/writing/characters-avoid/

I use Special !@#$%^&*()-_=+[]{};:'".>/?\| List as test name and I got freetube-playlist-Special_!@#$_^&_()-_=+[]{};_'_.______List-2024-10-07 on MacOS
Need a windows guy to test the result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PikachuEXE I thought that the characters I listed in the Regexp would be those that are absolutely illegal for use in certain OS’s. The guide you linked calls some absolutely common, usual and legal characters "illegal" and "forbidden". So, just to confirm, this is more about conventions, right?

Thanks for having a look at it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have access to Windows machine so I can't test it
Here is a screenshot of forbidden char message
2024-10-07 18_55_11-重新命名

I will create a custom build to test on Windows machine later

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On windows I have freetube-playlist-Special_!@#$_^&_()-_=+[]{};_'_.______List-2024-10-07.db, same as MacOS

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: Maybe we should merge the logic here with the logic for replacing the names of files created for screenshots?

export function replaceFilenameForbiddenChars(filenameOriginal) {

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