Fix: import history from youtube adding trailing space to title#9204
Open
Shadorc wants to merge 2 commits into
Open
Fix: import history from youtube adding trailing space to title#9204Shadorc wants to merge 2 commits into
Shadorc wants to merge 2 commits into
Conversation
Contributor
|
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
efb4f5ff-1298-471a-8973-3d47447115dc
approved these changes
Jun 13, 2026
PikachuEXE
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Related issue
None
Description
When importing watch history from YouTube, FreeTube tries to guess the common start of titles to remove it. It does this by splitting words using spaces. The issue is that by doing this, spaces aren't counted as being part of the start of the title. This leads to extra trailing spaces being added to titles when importing, and these spaces are also present when exporting.
For example, "Watched My Cool Video" will match "Watched" as the starting string, leading to title being " My Cool Video".
Also, if the history only contained one video, the whole title was considered as common, leading to the title being empty once cleaned.
There is still one small issue: if there is only one video in the history, the title will be imported with the common start string, but it can't be fixed with the current approach.
The fix consists of iterating over all titles and removing the last character of the first title while the others do not start with the same string. It doesn't seem like it when reading it, but this approach is faster than the previous one.
Previously: For 4,746 videos in history, average
getCommonStarttime of 2.5msNow: For 4,746 videos in history, average
getCommonStarttime of 0.4msI didn't just use
title: [{ importKey: 'title', predicate: item => item.slice(commonStart.length + 1) }]because some languages probably don't have a space between the start string and the title.I tested extensively with import/export history and behavior in FreeTube, and I didn't find any regression caused by the title change (after removing the trailing space).
Testing
Additional context
YouTube export sample, to save in a ".json" file: