Skip to content

Fix: import history from youtube adding trailing space to title#9204

Open
Shadorc wants to merge 2 commits into
FreeTubeApp:developmentfrom
Shadorc:fix/import-yt-history-title
Open

Fix: import history from youtube adding trailing space to title#9204
Shadorc wants to merge 2 commits into
FreeTubeApp:developmentfrom
Shadorc:fix/import-yt-history-title

Conversation

@Shadorc

@Shadorc Shadorc commented May 28, 2026

Copy link
Copy Markdown
Contributor

Pull Request Type

  • Bugfix
  • Feature Implementation
  • Documentation
  • Other

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 getCommonStart time of 2.5ms
Now: For 4,746 videos in history, average getCommonStart time of 0.4ms

I 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

  1. Remove watch history
  2. Import history from YouTube export (sample in additional context section)
  3. Check that the "history.db" file does not contain a title field with a trailing space
  4. Export history as YouTube format
  5. Check that the resulting exported file does not contain an extra space between "Watched" and the video title

Additional context

YouTube export sample, to save in a ".json" file:

[{
  "header": "YouTube",
  "title": "Vous avez regardé The Bald Paradox 🤔 (explained)",
  "titleUrl": "https://www.youtube.com/watch?v\u003dgjR-Z2oSFWI",
  "subtitles": [{
    "name": "Zack D. Films",
    "url": "https://www.youtube.com/channel/UCvz84_Q0BbvZThy75mbd-Dg"
  }],
  "time": "2026-05-27T20:50:42.333Z",
  "products": ["YouTube"],
  "activityControls": ["Historique des vidéos regardées sur YouTube"]
}]

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) May 28, 2026 11:37
@github-actions github-actions Bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label May 28, 2026
@github-actions

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: waiting for review For PRs that are complete, tested, and ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants