Skip to content

Instantly share code, notes, and snippets.

@lucasew
Created January 17, 2024 20:43
Show Gist options
  • Save lucasew/a25b8d8f0126e2cef5677ef2d21b28c1 to your computer and use it in GitHub Desktop.
Save lucasew/a25b8d8f0126e2cef5677ef2d21b28c1 to your computer and use it in GitHub Desktop.
Command I used to generate the PostgreSQL command to insert the watched videos in my Invidious instance from the Takeout dump of YouTube.
# Get yours by using the following query: `select email from users;`
[email protected]
HISTORY_FILE_YOUTUBE=histórico\ de\ visualizações.html
# Basically it parses all YouTube video ids on the HTML file and generates a query to insert on Invidious.
# As far as I tested there are no issues of having duplicated items on that array.
# On my instance I run postgres bare metal instead of containers so it allows me to login as the postgres
# user by having a shell opened in the context of that user. This can be achieved with the `sudo su - postgres`
# then start psql to get the database shell, from that change to the invidious database with `\c invidious` and then
# you are ready to paste the query.
# The query generated is only big, but not complex or hard to grasp what is going on. Read it before submitting.
printf "update users set watched = watched || '{%s}' where email = '$YOUR_USER';\n" $(cat $HISTORY_FILE_PATH | tr '"' '\n' | grep v= | sed 's;[^$]*v=\([^$\<]*\)[^$]*;"\1";' |sort | uniq | tr '\n' ', ' | sed 's;,$;;')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment