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

Update playlist import to only add duplicate playlist items sometimes #5783

Merged

Conversation

PikachuEXE
Copy link
Collaborator

Pull Request Type

  • Bugfix
  • Feature Implementation
  • Documentation
  • Other

Related issue

closes #5038

Description

Updates the behaviour of importing playlists when existing playlist found

Before:

  • Add playlist item unique by playlistItemId

After:

  • If both existing & incoming playlists have unique videos only (i.e. unique videoId values)
    Only add playlist items from incoming playlist with videoId absent in existing playlist
  • If either existing or incoming playlist has duplicate videos, add videos unique by playlistItemId (old behaviour)

Screenshots

Testing

(A) Both existing & incoming playlists have unique videos only

(B) Only incoming playlist has "duplicate" videos

  • import PC1, import PC2

(C) Only existing playlist has "duplicate" videos

  • import PC2, import PC1

(D) Only existing playlist has "duplicate" videos

  • import PC2 twice (should still have 4 items coz unique by playlistItemId)

Desktop

  • OS:
  • OS Version:
  • FreeTube version:

Additional context

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) October 3, 2024 02:07
@github-actions github-actions bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Oct 3, 2024
Copy link
Member

@efb4f5ff-1298-471a-8973-3d47447115dc efb4f5ff-1298-471a-8973-3d47447115dc left a comment

Choose a reason for hiding this comment

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

(A) Both existing & incoming playlists have unique videos only

Expected behavior: Not seeing any duplicates (This is the testcase from the issue)

(B) Only incoming playlist has "duplicate" videos

Expected behavior: You will see the duplicate because PC2 got it in its db

(C) Only existing playlist has "duplicate" videos

Expected behavior: You will see the duplicate because PC2 got it in its db

(D) Only existing playlist has "duplicate" videos

Expected behavior: You will see the duplicate because PC2 got it in its db

LGTM

})
}
const existingPlaylist = this.allPlaylists.find((playlist) => {
return playlist.playlistName === playlistObject.playlistName
Copy link
Member

@absidue absidue Oct 9, 2024

Choose a reason for hiding this comment

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

It probably makes sense to try to match by _id first, because if you rename the playlist on one computer you still want it to be the same when you import it on the other computer instead of being treated as a completely separate playlist.

That being said I've just realised that the _id is considered an ignored key, so there is no way that a renamed playlist could ever match, because the import will make sure that the _id won't match, but that problem already existed before this pull request. Also interesting that we don't save the lastPlayedAt field when it's a new playlist.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree but no way this belongs to this PR (plus need test cases)
I can make another PR to make it find by _id first later

lastPlayedAt not saved for new/existing playlist intentionally
Obvious for existing playlist but for new playlist it's never played locally and I consider it as a "local property" (e.g. importing other people's playlist)

Copy link
Member

Choose a reason for hiding this comment

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

I have to say I personally never use the playlists, but the way I use the other export and import options is for backup purposes, which means I only ever import my own stuff in my FreeTube install (dev mode is an exception because there I only use it to test stuff and that data is saved in a separate location), I would expect everything possible to be imported.

Importing someone else's files is probably a pretty rare use case, that is only really becoming possible because of the open PR to export single playlists.

Comment on lines 944 to 948
// Find by `playlistItemId` if present
videoExists = existingPlaylist.videos.some((x) => {
// Allow duplicate (by videoId) videos to be added
return x.videoId === video.videoId
})
Copy link
Member

Choose a reason for hiding this comment

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

Could you please update this comment to match what the code does.

* development: (59 commits)
  Translated using Weblate (Belarusian)
  Translated using Weblate (Belarusian)
  Translated using Weblate (Belarusian)
  Enable Belarusian locale (FreeTubeApp#5841)
  Translated using Weblate (Russian)
  Translated using Weblate (Japanese)
  fix cmd+m shortcut to minimize the window on macos and not mute the video (FreeTubeApp#5828) (FreeTubeApp#5829)
  Update dependabot.yml to add new eslint packages into the eslint group (FreeTubeApp#5837)
  Bump the babel group with 4 updates (FreeTubeApp#5831)
  Bump globals from 15.9.0 to 15.10.0 (FreeTubeApp#5835)
  Bump lefthook from 1.7.17 to 1.7.18 (FreeTubeApp#5836)
  Bump the eslint group with 2 updates (FreeTubeApp#5832)
  Bump @eslint/js from 9.11.1 to 9.12.0 (FreeTubeApp#5833)
  Bump @eslint/compat from 1.1.1 to 1.2.0 (FreeTubeApp#5834)
  Translated using Weblate (Belarusian)
  Translated using Weblate (Hebrew)
  Translated using Weblate (Chinese (Traditional Han script))
  Turn `vue/no-useless-template-attributes` eslint rule back on (FreeTubeApp#5830)
  Translated using Weblate (Serbian)
  Translated using Weblate (Belarusian)
  ...
@absidue
Copy link
Member

absidue commented Oct 10, 2024

I think you may have missed what I was trying to say with please update the comment, as you updated a different one. The one I originally commented on says that it is searching by playlist item ID, but then the code right below it is searching by video ID...

Copy link
Collaborator Author

@PikachuEXE PikachuEXE left a comment

Choose a reason for hiding this comment

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

For editing online

src/renderer/components/data-settings/data-settings.js Outdated Show resolved Hide resolved
@FreeTubeBot FreeTubeBot merged commit 126df9a into FreeTubeApp:development Oct 10, 2024
5 checks passed
@github-actions github-actions bot removed the PR: waiting for review For PRs that are complete, tested, and ready for review label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Videos duplicate themselves when importing playlists
5 participants