core: fix filename lookup and unique file generation for duplicating media items.