forked from Yankees4life/Jellyfin-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartcollections.ps1
29 lines (25 loc) · 1.31 KB
/
smartcollections.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Jellyfin server settings
$jellyfin_url = 'http://localhost:8096'
$jellyfin_api_key = ''
# Set up the smart collection criteria
$collection_name = 'New Releases 2023'
$collection_type = 'movies'
$collection_genre = 'action'
$collection_year = '2023'
# Build the search query
$query = "$jellyfin_url/Items?SortBy=DateCreated&SortOrder=Descending&IncludeItemTypes=Movie&Recursive=true&Fields=BasicSyncInfo,PrimaryImageAspectRatio,SortName,Overview&Genres=$collection_genre&Years=$collection_year&api_key=$jellyfin_api_key"
# Search for movies based on the smart collection criteria
$results = Invoke-RestMethod -Method Get -Uri $query
# Create the new collection in Jellyfin
if ($results.TotalRecordCount -gt 0) {
$collection_items = $results.Items.Id -join ","
$create_collection_query = "$jellyfin_url/Collections?Name=$collection_name&Ids=$collection_items&CollectionType=$collection_type&api_key=$jellyfin_api_key"
$response = Invoke-RestMethod -Method Post -Uri $create_collection_query
if ($response.StatusCode -eq 200) {
Write-Host "Successfully created collection '$collection_name' with $($results.TotalRecordCount) items."
} else {
Write-Host "Failed to create collection."
}
} else {
Write-Host "No items found that match the smart collection criteria."
}