2024-11-06, 02:26 AM
You can use your browser's console to invoke the Jellyfin API directly. I knocked out a quick Go program recently to mass remove TvDb IDs from shows; this is more a less a quick and dirty conversion of that. I'll also mention I'm not particularly adept with JavaScript at all, I got ChatGPT to look over my work...
Good advice in general, but especially so when running code that performs an action in mass: Shutdown your Jellyfin server first and backup its data folder! I've intentionally made it so that this stops working after attempting to manipulate the first match - remove the last-most
In your browser, go to the Jellyfin web interface, make sure you're logged in as an administrator (or a user that has permissions to edit items) and then bring up the browser console (on Windows/*NIX, press the F12 key). Paste the following in, press Enter, and cross your fingers:
The name of the first matching movie will be printed, go and see its metadata and see if it worked. I'm not particularly knowledgeable with the Jellyfin API, there might be more efficient ways to do this. Still better than direct database manipulation, however, I reckon.
The first part retrieves every movie on your server. The IDs of movies where there's a person with a "Line Producer" role are stored. Then, the complete information for each matching movie is pulled down, a new array of people where the existing entries are added except for the people we don't want, a metadata lock is requested on the movie and then the modified information is sent back to the Jellyfin server to update.
Good advice in general, but especially so when running code that performs an action in mass: Shutdown your Jellyfin server first and backup its data folder! I've intentionally made it so that this stops working after attempting to manipulate the first match - remove the last-most
break
if/once you've confirmed this hasn't blown up your collections' metadata. This attempts to remove all the people listed as "Casting Director" (case-sensitive, changable via the targetField
variable) as per the following view, and then locks the item: In your browser, go to the Jellyfin web interface, make sure you're logged in as an administrator (or a user that has permissions to edit items) and then bring up the browser console (on Windows/*NIX, press the F12 key). Paste the following in, press Enter, and cross your fingers:
PHP Code:
await (async () => {
const targetField = "Line Producer";
const allMovies = await (await fetch(`${ApiClient._serverAddress}/Items?enableImages=false&enableTotalRecordCount=false&fields=People&includeItemTypes=Movie&recursive=true`, {
"headers": {
"Accept": "application/json",
"Authorization": `MediaBrowser Client="${ApiClient._appName}", Device="${ApiClient._deviceName}", DeviceId="${ApiClient._deviceId}", Version="${ApiClient._serverVersion}", Token="${ApiClient.accessToken()}"`,
},
"method": "GET"
})).json();
const ids = allMovies.Items.flatMap(movie =>
movie.People.some(person => person.Role === targetField) ? [movie.Id] : []
);
for (const id of ids) {
const itemReq = await fetch(`${ApiClient._serverAddress}/Items/${id}?userId=${ApiClient._currentUser.Id}`, {
"headers": {
"Accept": "application/json",
"Authorization": `MediaBrowser Client="${ApiClient._appName}", Device="${ApiClient._deviceName}", DeviceId="${ApiClient._deviceId}", Version="${ApiClient._serverVersion}", Token="${ApiClient.accessToken()}"`,
},
"method": "GET"
});
if (!itemReq.ok)
break;
const movie = await itemReq.json();
console.log(movie.Name);
movie.People = movie.People.filter(person => person.Role !== targetField);
movie.LockData = true;
try {
await fetch(`${ApiClient._serverAddress}/Items/${id}`, {
"headers": {
"Authorization": `MediaBrowser Client="${ApiClient._appName}", Device="${ApiClient._deviceName}", DeviceId="${ApiClient._deviceId}", Version="${ApiClient._serverVersion}", Token="${ApiClient.accessToken()}"`,
"Content-Type": "application/json",
},
"body": JSON.stringify(movie),
"method": "POST"
});
} catch (err) {
console.error(err.message);
break;
}
break;
}
})();
The name of the first matching movie will be printed, go and see its metadata and see if it worked. I'm not particularly knowledgeable with the Jellyfin API, there might be more efficient ways to do this. Still better than direct database manipulation, however, I reckon.
The first part retrieves every movie on your server. The IDs of movies where there's a person with a "Line Producer" role are stored. Then, the complete information for each matching movie is pulled down, a new array of people where the existing entries are added except for the people we don't want, a metadata lock is requested on the movie and then the modified information is sent back to the Jellyfin server to update.