Skip to content

Instantly share code, notes, and snippets.

@Fishbowler
Last active May 31, 2021 20:59
Show Gist options
  • Save Fishbowler/052dfe2de8d80f9c3ef6fad86a9f1995 to your computer and use it in GitHub Desktop.
Save Fishbowler/052dfe2de8d80f9c3ef6fad86a9f1995 to your computer and use it in GitHub Desktop.
Update Kodi Library after moving source
-- Written for when a LAN media source changes IP - you want all the same scanned media, watched state, etc, not having to start fresh
-- Caveats:
-- * Only covers videos, I don't anything else on Kodi
-- * SQLLite is intentionally feature-light, making this script a little longer than you'd expect, and a little clunky to use
-- Instructions:
-- * Fetch the latest MyVideos database from your userdata (in my case, this was from an Nvidia Shield)
-- * Run this on a copy in case it goes wrong!
-- * Set the variables
-- * Uncomment and run one update block
-- * Recomment/delete, and move onto the next
-- * With Kodi stopped, replace the database in the Userdata with the modified one, and enjoy!
WITH const AS (
SELECT '%192.168.1.99%' AS oldsourcesearchstring,
'192.168.1.99' AS oldsource,
'192.168.86.86' AS newsource)
----------------------------
-- update episode as e1
-- set c18 = (
-- select REPLACE(c18,oldsource,newsource)
-- from episode as e2, const
-- where e2.idEpisode = e1.idEpisode
-- )
-- where exists (
-- select idEpisode from episode as e3, const
-- where c18 like oldsourcesearchstring
-- and e3.idEpisode = e1.idEpisode
-- )
----------------------------
-- update movie as m1
-- set c22 = (
-- select REPLACE(c22,oldsource,newsource)
-- from movie as m2, const
-- where m2.idMovie = m1.idMovie
-- )
-- where exists (
-- select idMovie from movie as m3, const
-- where c22 like oldsourcesearchstring
-- and m3.idMovie = m1.idMovie
-- )
----------------------------
-- update path as p1
-- set strPath = (
-- select REPLACE(strPath,oldsource,newsource)
-- from path as p2, const
-- where p2.idPath = p1.idPath
-- )
-- where exists (
-- select idPath from path as p3, const
-- where strPath like oldsourcesearchstring
-- and p3.idPath = p1.idPath
-- )
----------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment