2024-11-29, 05:24 PM
(This post was last modified: 2024-11-29, 05:26 PM by kodiuser. Edited 1 time in total.)
I have been playing and sorted it with PowerShell. Copy this into a new file (Jellyfin_Fix.ps1) and execute it.
It will scan all your libraries that are of type "tvshow" and output a proper PowerShell object with the relevant details.
Just remember to add your API key and User ID at the bottom where indicated.
Enjoy.
----------
It will scan all your libraries that are of type "tvshow" and output a proper PowerShell object with the relevant details.
Just remember to add your API key and User ID at the bottom where indicated.
Enjoy.
----------
Code:
Clear-Host
Function Get-TVLibrary {
Param (
[object]$authInfo
)
$headers = @{}
$headers['X-MediaBrowser-Token'] = $authInfo.ApiKey
$response = Invoke-RestMethod -Uri "$($authInfo.Url)/Views" -Method Get -Headers $headers
ForEach ($item In ($response.Items | Sort-Object -Property 'Name')) {
If ($item.CollectionType -eq 'tvshows') {
[pscustomobject]@{'Id' = $item.Id; 'Name' = $item.Name}
}
}
}
Function Get-LibraryItem {
Param (
[object]$authInfo,
[string]$LibraryId
)
$headers = @{}
$headers['X-MediaBrowser-Token'] = $authInfo.ApiKey
$response = Invoke-RestMethod -Uri "$($authInfo.Url)/Items?=SortName%2CPath&ParentId=$LibraryId" -Method Get -Headers $headers
ForEach ($item In ($response.Items | Sort-Object -Property 'Name')) {
[pscustomobject]@{'Id' = $item.Id; 'Name' = $item.Name}
}
}
Function Get-Item {
Param (
[object]$authInfo,
[string]$ItemId
)
$headers = @{}
$headers['X-MediaBrowser-Token'] = $authInfo.ApiKey
Return (Invoke-RestMethod -Uri "$($authInfo.Url)/Items/$ItemId" -Method Get -Headers $headers)
}
Function Read-Library {
Param (
$AuthInfo,
$Library
)
ForEach ($item In $Library) {
$shows = (Get-LibraryItem -authInfo $AuthInfo -LibraryId $item.Id)
ForEach ($show In $shows) {
$showItem = (Get-Item -authInfo $AuthInfo -ItemId $show.Id)
$showItem.Name = $showItem.Name.replace(':', '').replace('!', '').replace('/', ' ').replace('?', '').replace('&', 'And').replace('*', '.')
$showItem.Name = $showItem.Name.TrimEnd('.') # Synology Really does not like folder names that end with a dot (.)
$showPath = $showItem.Name
$origPath = ($showItem.Path).split('/')[-1]
If (-not $showItem.Name.EndsWith(')')) {
# Discard entries with year or language suffix. For exmaple: "TV Show (2024)" -or- "TV Show (Korean)"
$showPath = ($origPath) -replace "\s\((?:\d{4}|\w{1,})\)", ''
}
# If ($showPath -eq $origPath) { $origPath = '' }
If (($showItem.Name) -ine ($showPath)) {
[pscustomobject]@{
'Library' = $Library.Name
'Jellyfin Title' = $showitem.Name
'Cleaned Title' = $showPath
'Original Title' = $origPath
}
}
}
}
}
$authInfo = @{
ApiKey = '3f5ab1e3a75b4830b25780cd0a772839'
Url = 'http://192.168.42.31:8096/Users/4fccdac58fd4477893a7f6acdb50bd71'
}
Get-TVLibrary -authInfo $authInfo | ForEach-Object {
Read-Library -AuthInfo $authInfo -Library $_
} | Format-Table -AutoSize