Jump to content

Remove duplicate versions from library that has been removed


Go to solution Solved by gudvardur,

Recommended Posts

Posted

Hi all,

I have two Libraries, TV Shows and Movies... Under each, I had two folder locations.... Both of that folder locations sometimes (often) had the same content... Now I removed one of the folder locations from each library so now there is only one folder location in each Library... However, Emby still keeps versions of older content that existed in the removed location and I'm unable to play any content unless I select the other version... 

I've tried rescaning both libraries... I've tried to refresh metadata and allow it to overwrite... neither of those seem to work... How can I remove all versions that point to this old location?

Posted

Sure thing... 

For example this specific episode I can't play unless I Select the lower version that is located in /opt/media/rikflix/tv, the upper version was located in /opt/media/nesral/tv

Screenshot2025-09-12at12_59_04.thumb.png.7ea3387b95a644c6d66a9af35864b0fd.png

Screenshot2025-09-12at12_59_50.png.eaff46c90a0bf08eddd80d2793f06b29.png

I had both /opt/media/rikflix/tv and /opt/media/nesral/tv in the Folder list below... and this episode (obove) existed in both folders... This picture below reflects how the Library is currently configured... 

Screenshot2025-09-12at13_00_27.png.8172b87b8ccba035ee409dce5204c44a.png

 

But then I needed to remove /opt/media/nesral/tv and now I'm unable to play this episode (And many other TV shows that existed on both locations), I can play this episode if I select the lower version like shown in the top picture that points to /opt/media/rikflix/tv..... 

Screenshot2025-09-12at13_02_13.png.8afff7e4089409d25f0dbd54616b5337.png

Posted

From embyserver logs... 

3520268 -bufsize:v:0 7040536 -sc_threshold:v:0 0 -keyint_min:v:0 72 -r:v:0 23.976024627685547 -pix_fmt:v:0 yuv420p -preset:v:0 veryfast -profile:v:0 high -x264opts:v:0 "subme=0:me_range=4:rc_lookahead=10:partitions=none" -crf:v:0 23 -c:a:0 aac -ab:a:0 192000 -ac:a:0 2 -metadata:s:a:0 language=eng -filter:a:0 "volume=2" -disposition:a:0 default -max_delay 5000000 -avoid_negative_ts disabled -f segment -map_metadata -1 -map_chapters -1 -segment_format mpegts -segment_list "/var/lib/emby/transcoding-temp/C16CFE/C16CFE.m3u8" -segment_list_type m3u8 -segment_time 00:00:03.000 -segment_start_number 0 -individual_header_trailer 0 -write_header_trailer 0 -segment_write_temp 1 "/var/lib/emby/transcoding-temp/C16CFE/C16CFE_%d.ts"
	
	13:02:04.101 ffmpeg version 5.1-emby_2023_06_25 Copyright (c) 2000-2022 the FFmpeg developers and softworkz for Emby LLC
	13:02:04.101   built with gcc 10.3.0 (crosstool-NG 1.25.0)
	13:02:04.101 Execution Date: 2025-09-12 13:02:04
	13:02:04.105 /opt/media/nesral/tv/Star Trek - Strange New Worlds/Season 03/Star Trek - Strange New Worlds - s03e02 - Wedding Bell Blues - HDTV-1080p.mkv: No such file or directory
	13:02:04.105 EXIT
Posted

So bottom line, how can I get rid of all versions that point to the old location /opt/media/nesral/tv from my server? And keep /opt/media/rikkflix/tv version... 

Screenshot2025-09-12at13_19_02.thumb.png.d8e3f70e68d31140ea5fc65fb84cdec9.png

Posted

Anyone have suggestion how to remove the extra version that does not exist on disk anymore?

  • 3 weeks later...
Posted

@gudvardurcan you try removing the whole star trek folder from your library, then run a library scan, and then add the star trek folder back? Please see if that helps. Thanks !

  • Solution
Posted

Solution I ended up doing...

Step 1 - Stop Service

Stop emby-server service

Step 2 - Backup

Do full backup of /var/lib/emby

Step 3 - Delete unwanted versions

sqlite3 /var/lib/emby/data/library.db "
PRAGMA foreign_keys = OFF;

-- Remove streams linked to deleted paths
DELETE FROM MediaStreams2
WHERE Path LIKE '/opt/media/nesral/tv%'
   OR Path LIKE '/opt/media/nesral/movies%';

-- Remove dependents whose parent media has a nesral path
DELETE FROM ItemExtradata
WHERE ItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

DELETE FROM ItemLinks2
WHERE ItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%')
   OR LinkedId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

DELETE FROM ItemPeople2
WHERE ItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

DELETE FROM Chapters3
WHERE ItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

DELETE FROM ImportedCollections
WHERE ItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

DELETE FROM UserItemShares
WHERE ItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

DELETE FROM AncestorIds2
WHERE ItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%')
   OR AncestorId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

DELETE FROM ListItems
WHERE ListId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%')
   OR ListItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

DELETE FROM SyncJobItems2
WHERE ItemId IN (SELECT Id FROM MediaItems WHERE Path LIKE '/opt/media/nesral/%' OR Images LIKE '%/opt/media/nesral/%');

-- Now remove the main media entries
DELETE FROM MediaItems
WHERE Path LIKE '/opt/media/nesral/tv%'
   OR Path LIKE '/opt/media/nesral/movies%'
   OR Images LIKE '%/opt/media/nesral/tv%'
   OR Images LIKE '%/opt/media/nesral/movies%';

PRAGMA foreign_keys = ON;
VACUUM;
ANALYZE;
"

Of course path could be something else that suits you... 

Step 4 - Check if anything is left

sqlite3 /var/lib/emby/data/library.db "
SELECT COUNT(*) FROM MediaItems WHERE Path LIKE '%/opt/media/nesral%';
SELECT COUNT(*) FROM MediaItems WHERE Images LIKE '%/opt/media/nesral%';
SELECT COUNT(*) FROM MediaStreams2 WHERE Path LIKE '%/opt/media/nesral%';
"

If all three return 0, your Emby database is clean.

Step 5 - Restart Emby

Everything is fixed... 

Posted

Thanks for following up.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...