denywinarto 5 Posted August 22, 2025 Posted August 22, 2025 So I'm trying to write a script to populate my home channel with top 10 movies collection that can be played, with below code, but i'm stuck at Querying emby db for imdb/tmdb param( [switch]$Push ) # ==== CONFIG ==== $traktFeedUrl = "https://api.trakt.tv/users/emby/lists/top-10-movies" $traktClientId = "745354353d6f9eed30d8d64a72bcd970d" # required for Trakt API $embyServer = "http://localhost:8096" $apiKey = "5435390e75" # =============== Write-Host "`n? Fetching top-10 feed from Trakt..." # Fetch Trakt feed $headers = @{ "Content-Type" = "application/json" "trakt-api-version" = "2" "trakt-api-key" = $traktClientId } try { $traktItems = Invoke-RestMethod -Uri $traktFeedUrl -Headers $headers -Method Get } catch { Write-Host "!! Failed to fetch Trakt feed: $_" exit 1 } Write-Host "? Loaded $($traktItems.Count) items from Trakt feed" Write-Host "-----------------------------------------------`n" # Fetch all movies from Emby with ProviderIds, handling pagination Write-Host "? Fetching all movies from Emby..." $embyMovies = @() $startIndex = 0 $limit = 100000 $totalCount = 0 do { $embyUrl = "$embyServer/Items?IncludeItemTypes=Movie&Fields=ProviderIds&startIndex=$startIndex&limit=$limit&api_key=$apiKey" try { $response = Invoke-RestMethod -Uri $embyUrl -Method Get if ($response.Items.Count -gt 0) { $embyMovies += $response.Items } $startIndex += $response.Items.Count $totalCount = $response.TotalRecordCount } catch { Write-Host "!! Failed to fetch movies from Emby: $_" exit 1 } } while ($embyMovies.Count -lt $totalCount) Write-Host "? Loaded $($embyMovies.Count) movies from Emby library" Write-Host "-----------------------------------------------`n" $results = @() $rank = 1 foreach ($item in $traktItems) { $tmdbId = $item.movie.ids.tmdb $title = $item.movie.title $year = $item.movie.year Write-Host "DEBUG: Searching Emby for TMDb $tmdbId ($title)" # Search Emby for matching TMDb ID $match = $embyMovies | Where-Object { $_.ProviderIds.Tmdb -eq [string]$tmdbId } | Select-Object -First 1 if ($match) { $results += [PSCustomObject]@{ Rank = $rank Title = $title Year = $year EmbyName = $match.Name EmbyYear = $match.ProductionYear EmbyId = $match.Id } Write-Host "MATCH FOUND: '$title' matched with Emby movie '$($match.Name)'" } else { Write-Host "No match found for '$title' (TMDb $tmdbId)" $results += [PSCustomObject]@{ Rank = $rank Title = $title Year = $year EmbyName = "" EmbyYear = "" EmbyId = "" } } $rank++ } # Show summary table $results | Format-Table Rank, Title, Year, EmbyName, EmbyYear, EmbyId -AutoSize $matched = ($results | Where-Object { $_.EmbyId -ne "" }).Count $missed = $results.Count - $matched Write-Host "`nMatched: $matched | Missed: $missed`n" if (-not $Push) { Write-Host "Dry-run only. Re-run with -Push to create/update the collection." } ? Fetching all movies from Emby... ? Loaded 0 movies from Emby library ----------------------------------------------- DEBUG: Searching Emby for TMDb 1061474 (Superman) No match found for 'Superman' (TMDb 1061474) DEBUG: Searching Emby for TMDb 1234821 (Jurassic World Rebirth) No match found for 'Jurassic World Rebirth' (TMDb 1234821) DEBUG: Searching Emby for TMDb 1100988 (28 Years Later) No match found for '28 Years Later' (TMDb 1100988) DEBUG: Searching Emby for TMDb 1087192 (How to Train Your Dragon) No match found for 'How to Train Your Dragon' (TMDb 1087192) DEBUG: Searching Emby for TMDb 648878 (Eddington) No match found for 'Eddington' (TMDb 648878) DEBUG: Searching Emby for TMDb 986056 (Thunderbolts*) No match found for 'Thunderbolts*' (TMDb 986056) DEBUG: Searching Emby for TMDb 552524 (Lilo & Stitch) No match found for 'Lilo & Stitch' (TMDb 552524) DEBUG: Searching Emby for TMDb 1233413 (Sinners) No match found for 'Sinners' (TMDb 1233413) DEBUG: Searching Emby for TMDb 1106289 (The Pickup) No match found for 'The Pickup' (TMDb 1106289) DEBUG: Searching Emby for TMDb 541671 (Ballerina) No match found for 'Ballerina' (TMDb 541671) Rank Title Year EmbyName EmbyYear EmbyId ---- ----- ---- -------- -------- ------ 1 Superman 2025 2 Jurassic World Rebirth 2025 3 28 Years Later 2025 4 How to Train Your Dragon 2025 5 Eddington 2025 6 Thunderbolts* 2025 7 Lilo & Stitch 2025 8 Sinners 2025 9 The Pickup 2025 10 Ballerina 2025 The result is like this even though i have 8 of the 10 movies. Seems like it failed to find the TMDB id API key is already correct, i tested with this and it outputs all users. PS C:\> Invoke-RestMethod -Uri "http://localhost:8096/Users?api_key=f2fgfd" i recreated it again but the result is the same. Any thoughts?
Luke 42077 Posted August 22, 2025 Posted August 22, 2025 Hi, did you check the metadata editor for these titles to see what info you have in your server database?
denywinarto 5 Posted August 22, 2025 Author Posted August 22, 2025 (edited) 12 minutes ago, Luke said: Hi, did you check the metadata editor for these titles to see what info you have in your server database? Yes Luke, here's one example, eddington and ballerina are the ones i dont have, also if it matters, i have rather huge library around 40k ish movies.. Edited August 22, 2025 by denywinarto
Solution adminExitium 355 Posted August 22, 2025 Solution Posted August 22, 2025 Try adding Recursive=true to the API query. It's needed when you are doing the query from the root, rather than a specific library or folder (i.e. without a parent id). 1
denywinarto 5 Posted August 23, 2025 Author Posted August 23, 2025 13 hours ago, adminExitium said: Try adding Recursive=true to the API query. It's needed when you are doing the query from the root, rather than a specific library or folder (i.e. without a parent id). Yes this is what eventually used, thanks anyway.
Killface69 96 Posted August 28, 2025 Posted August 28, 2025 (edited) Maybe Trakt returns an integer, while Emby stores the Tmdb id as strIng? Or the provider id is tmdb in lowercase. Other than that, you could gather all Tmdb ids from Trakt and search for the provider id list 'tmdb.123,tmdb.345'. I'll look up the API call. Edited August 28, 2025 by Killface69
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now