diff --git a/CHANGELOG.md b/CHANGELOG.md index 7855486..df00b6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [1.0.16] - 2024-04-11 + +* * ✨ [New] `New-PlexSmartCollection` for creating new smart collections in Plex libraries (thanks to [solid03](https://github.com/solid03)). + ## [1.0.15] - 2024-03-22 * ✨ [New] `Remove-PlexCollection` for removing collections from Plex libraries (thanks to [solid03](https://github.com/solid03)). diff --git a/Documentation/Add-PlexItemToPlaylist.md b/Documentation/Add-PlexItemToPlaylist.md index 6133cae..fd365ee 100644 --- a/Documentation/Add-PlexItemToPlaylist.md +++ b/Documentation/Add-PlexItemToPlaylist.md @@ -13,7 +13,8 @@ Copies a single item to a playlist. ## SYNTAX ``` -Add-PlexItemToPlaylist [-PlaylistId] [-ItemId] [-WhatIf] [-Confirm] [] +Add-PlexItemToPlaylist [-PlaylistId] [-ItemId] [-ProgressAction ] + [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -91,6 +92,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Add-PlexLabel.md b/Documentation/Add-PlexLabel.md index d15e928..2d6b1dc 100644 --- a/Documentation/Add-PlexLabel.md +++ b/Documentation/Add-PlexLabel.md @@ -13,7 +13,8 @@ Adds a label to a Plex item (movie, show, or album). ## SYNTAX ``` -Add-PlexLabel [-Id] [-Label] [-WhatIf] [-Confirm] [] +Add-PlexLabel [-Id] [-Label] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -91,6 +92,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Copy-PlexPlaylist.md b/Documentation/Copy-PlexPlaylist.md index a336f02..8768884 100644 --- a/Documentation/Copy-PlexPlaylist.md +++ b/Documentation/Copy-PlexPlaylist.md @@ -15,8 +15,8 @@ To overwrite, use the -Force switch. ## SYNTAX ``` -Copy-PlexPlaylist [-Id] [[-NewPlaylistName] ] [-Username] [-Force] [-WhatIf] - [-Confirm] [] +Copy-PlexPlaylist [-Id] [[-NewPlaylistName] ] [-Username] [-Force] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -125,6 +125,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Find-PlexItem.md b/Documentation/Find-PlexItem.md index 456158c..b00a988 100644 --- a/Documentation/Find-PlexItem.md +++ b/Documentation/Find-PlexItem.md @@ -14,7 +14,7 @@ This function uses the search ability of Plex find items on your Plex server. ``` Find-PlexItem [-ItemName] [[-ItemType] ] [[-LibraryTitle] ] [[-Year] ] - [-ExactNameMatch] [-WhatIf] [-Confirm] [] + [-ExactNameMatch] [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -150,6 +150,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Get-PlexCollection.md b/Documentation/Get-PlexCollection.md index 40e6f09..27a80c7 100644 --- a/Documentation/Get-PlexCollection.md +++ b/Documentation/Get-PlexCollection.md @@ -14,12 +14,13 @@ Gets collections. ### CollectionId ``` -Get-PlexCollection -Id [-IncludeItems] [] +Get-PlexCollection -Id [-IncludeItems] [-ProgressAction ] [] ``` ### LibraryId ``` -Get-PlexCollection -LibraryId [-IncludeItems] [] +Get-PlexCollection -LibraryId [-IncludeItems] [-ProgressAction ] + [] ``` ## DESCRIPTION @@ -37,6 +38,12 @@ Get-PlexCollection -LibraryId 1 Get-PlexCollection -Id 723 -IncludeItems ``` +### EXAMPLE 3 +``` +# Get all collections from library 1 with the name, id (ratingkey) and number of items in the collection: +Get-PlexCollection -LibraryId 1 | Select-Object title,ratingkey,childcount +``` + ## PARAMETERS ### -Id @@ -84,6 +91,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Get-PlexItem.md b/Documentation/Get-PlexItem.md index efb6782..dcb1c2c 100644 --- a/Documentation/Get-PlexItem.md +++ b/Documentation/Get-PlexItem.md @@ -14,12 +14,12 @@ Get a specific item. ### Id ``` -Get-PlexItem -Id [-IncludeTracks] [] +Get-PlexItem -Id [-IncludeTracks] [-ProgressAction ] [] ``` ### Library ``` -Get-PlexItem -LibraryTitle [] +Get-PlexItem -LibraryTitle [-ProgressAction ] [] ``` ## DESCRIPTION @@ -90,6 +90,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Get-PlexLibrary.md b/Documentation/Get-PlexLibrary.md index 5f408a8..8a8727a 100644 --- a/Documentation/Get-PlexLibrary.md +++ b/Documentation/Get-PlexLibrary.md @@ -14,17 +14,17 @@ By default, returns a list of libraries on a Plex server. ### All (Default) ``` -Get-PlexLibrary [] +Get-PlexLibrary [-ProgressAction ] [] ``` ### Id ``` -Get-PlexLibrary [-Id ] [] +Get-PlexLibrary [-Id ] [-ProgressAction ] [] ``` ### Name ``` -Get-PlexLibrary [-Name ] [] +Get-PlexLibrary [-Name ] [-ProgressAction ] [] ``` ## DESCRIPTION @@ -70,6 +70,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Get-PlexPlaylist.md b/Documentation/Get-PlexPlaylist.md index 862ad45..bc12fd2 100644 --- a/Documentation/Get-PlexPlaylist.md +++ b/Documentation/Get-PlexPlaylist.md @@ -14,19 +14,20 @@ Gets playlists. ### All (Default) ``` -Get-PlexPlaylist [-IncludeItems] [-AlternativeToken ] [-WhatIf] [-Confirm] [] +Get-PlexPlaylist [-IncludeItems] [-AlternativeToken ] [-ProgressAction ] [-WhatIf] + [-Confirm] [] ``` ### Id ``` -Get-PlexPlaylist [-Id ] [-IncludeItems] [-AlternativeToken ] [-WhatIf] [-Confirm] - [] +Get-PlexPlaylist [-Id ] [-IncludeItems] [-AlternativeToken ] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ### Name ``` -Get-PlexPlaylist [-Name ] [-IncludeItems] [-AlternativeToken ] [-WhatIf] [-Confirm] - [] +Get-PlexPlaylist [-Name ] [-IncludeItems] [-AlternativeToken ] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -140,6 +141,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Get-PlexServer.md b/Documentation/Get-PlexServer.md index a783607..b379cf2 100644 --- a/Documentation/Get-PlexServer.md +++ b/Documentation/Get-PlexServer.md @@ -13,7 +13,7 @@ Returns a list of online Plex Servers that you have access to (remote access mus ## SYNTAX ``` -Get-PlexServer [[-Name] ] [] +Get-PlexServer [[-Name] ] [-ProgressAction ] [] ``` ## DESCRIPTION @@ -43,6 +43,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). @@ -50,7 +65,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## OUTPUTS -### ``` ### accessToken : abcd123456ABCDEFG ### name : thor ### address : 87.50.66.123 @@ -80,7 +94,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ### sourceTitle : username_of_friend ### ownerId : 6728195 ### home : 0 -### ``` ## NOTES ## RELATED LINKS diff --git a/Documentation/Get-PlexSession.md b/Documentation/Get-PlexSession.md index 150ea44..009472e 100644 --- a/Documentation/Get-PlexSession.md +++ b/Documentation/Get-PlexSession.md @@ -13,7 +13,7 @@ Gets a list of sessions (streams) on the Plex server. ## SYNTAX ``` -Get-PlexSession [-WhatIf] [-Confirm] [] +Get-PlexSession [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -59,6 +59,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Get-PlexShare.md b/Documentation/Get-PlexShare.md index e14b42b..7fe703c 100644 --- a/Documentation/Get-PlexShare.md +++ b/Documentation/Get-PlexShare.md @@ -14,12 +14,13 @@ Gets a user and the share status of your libraries with them. ### username ``` -Get-PlexShare [-Username ] [-WhatIf] [-Confirm] [] +Get-PlexShare [-Username ] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ### email ``` -Get-PlexShare [-Email ] [-WhatIf] [-Confirm] [] +Get-PlexShare [-Email ] [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -107,6 +108,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Get-PlexUser.md b/Documentation/Get-PlexUser.md index 241a4a1..6f3b73c 100644 --- a/Documentation/Get-PlexUser.md +++ b/Documentation/Get-PlexUser.md @@ -13,7 +13,8 @@ Gets a list of users associated with your account (e.g those you have shared wit ## SYNTAX ``` -Get-PlexUser [[-Username] ] [-IncludeToken] [-WhatIf] [-Confirm] [] +Get-PlexUser [[-Username] ] [-IncludeToken] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -90,6 +91,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Get-PlexWatchHistory.md b/Documentation/Get-PlexWatchHistory.md index 0d518be..b70afbc 100644 --- a/Documentation/Get-PlexWatchHistory.md +++ b/Documentation/Get-PlexWatchHistory.md @@ -13,7 +13,8 @@ Returns a list of watched/listened to items from the Plex server. ## SYNTAX ``` -Get-PlexWatchHistory [[-Username] ] [-WhatIf] [-Confirm] [] +Get-PlexWatchHistory [[-Username] ] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -75,6 +76,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/New-PlexPlaylist.md b/Documentation/New-PlexPlaylist.md index 4b2c7f6..79a3836 100644 --- a/Documentation/New-PlexPlaylist.md +++ b/Documentation/New-PlexPlaylist.md @@ -13,8 +13,8 @@ Creates a new playlist. ## SYNTAX ``` -New-PlexPlaylist [-Name] [-Type] [-ItemId] [-WhatIf] [-Confirm] - [] +New-PlexPlaylist [-Name] [-Type] [-ItemId] [-ProgressAction ] + [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -112,6 +112,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/New-PlexSmartCollection.md b/Documentation/New-PlexSmartCollection.md new file mode 100644 index 0000000..7ebdc27 --- /dev/null +++ b/Documentation/New-PlexSmartCollection.md @@ -0,0 +1,237 @@ +--- +external help file: PSPlex-help.xml +Module Name: PSPlex +online version: +schema: 2.0.0 +--- + +# New-PlexSmartCollection + +## SYNOPSIS +Creates a new smart collection. + +## SYNTAX + +``` +New-PlexSmartCollection [-Name] [-LibraryId] [-Filter] [[-MatchType] ] + [-ProgressAction ] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +Creates a new smart collection. + +## EXAMPLES + +### EXAMPLE 1 +``` +New-PlexSmartCollection -Name "Star Trek" -LibraryId 1 -Filter "Title Contains Star Trek" +``` + +### EXAMPLE 2 +``` +New-PlexSmartCollection -Name "80's" -LibraryId 1 -Filter "Decade Is 1980" +``` + +### EXAMPLE 3 +``` +New-PlexSmartCollection -Name "Old Favorites" -LibraryId 1 -Filter "Plays IsGreaterThan 2; LastPlayed IsNotInTheLast 1y" +``` + +### EXAMPLE 4 +``` +New-PlexSmartCollection -Name "Trek Wars" -LibraryId 1 -MatchType MatchAny -Filter "title contains star trek; title contains star wars" +``` + +## PARAMETERS + +### -Name +Name of the smart collection. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -LibraryId +ID of the library to create the smart collection in. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Filter +Specifies the query string that retrieves the items in the smart collection. +The syntax matches the Plex Web GUI as closely as possible. +Clauses are separated by a semi-colon ( ; ). + +Syntax: + +- \ \ \ +- \ \ \;\ \ \ + +- Attributes: + - String + - Title + - Studio + - Edition + - Numeric + - Rating + - Year + - Decade + - Plays + - Exact + - ContentRating + - Genre + - Collection + - Actor + - Country + - SubtitleLanguage + - AudioLanguage + - Label + - Boolean + - Unmatched + - Duplicate + - Unplayed + - HDR + - InProgress + - Trash + - Semi-Boolean + - Resolution + - Date + - ReleaseDate + - DateAdded + - LastPlayed + + - Operators: + - String + - Contains + - DoesNotContain + - Is + - IsNot + - BeginsWith + - EndsWith + - Numeric + - Is + - IsNot + - IsGreaterThan + - IsLessThan + - Exact + - Is + - IsNot + - Boolean + - IsTrue + - IsFalse + - Semi-Boolean + - Is + - Date + - IsBefore (Value format: yyyy-mm-dd) + - IsAfter (Value format: yyyy-mm-dd) + - IsInTheLast + - IsNotInTheLast + +- Examples: + - "DateAdded IsNotInTheLast 2y; Unplayed IsTrue" + - "Title BeginsWith Star Trek; Unplayed IsTrue" + - "Actor Is Jim Carrey; Genre Is Comedy" + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MatchType +Specifies how filter clauses are matched. + +- MatchAll: Matches all clauses. +- MatchAny: Matches any cluase. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: MatchAll +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Documentation/Remove-PlexCollection.md b/Documentation/Remove-PlexCollection.md index d04f529..61f3b0c 100644 --- a/Documentation/Remove-PlexCollection.md +++ b/Documentation/Remove-PlexCollection.md @@ -13,7 +13,8 @@ Removes a Plex collection. ## SYNTAX ``` -Remove-PlexCollection [-Id] [-WhatIf] [-Confirm] [] +Remove-PlexCollection [-Id] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -28,7 +29,7 @@ Remove-PlexCollection -Id 12345 ### EXAMPLE 2 ``` -Get-PlexCollection | Where-object {[int]$_.childCount -lt 5} | Select-Object -ExpandProperty ratingKey | Remove-PlexCollection +Get-PlexCollection -LibraryId 1 | Where-object {[int]$_.childCount -lt 5} | Select-Object -ExpandProperty ratingKey | Remove-PlexCollection ``` ## PARAMETERS @@ -79,6 +80,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Remove-PlexLabel.md b/Documentation/Remove-PlexLabel.md index 47c9314..30d55b4 100644 --- a/Documentation/Remove-PlexLabel.md +++ b/Documentation/Remove-PlexLabel.md @@ -13,7 +13,8 @@ Removes a label from a Plex item (movie, show, or album). ## SYNTAX ``` -Remove-PlexLabel [-Id] [-Label] [-WhatIf] [-Confirm] [] +Remove-PlexLabel [-Id] [-Label] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -91,6 +92,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Remove-PlexPlaylist.md b/Documentation/Remove-PlexPlaylist.md index dafd5b8..9cd074f 100644 --- a/Documentation/Remove-PlexPlaylist.md +++ b/Documentation/Remove-PlexPlaylist.md @@ -13,7 +13,8 @@ Remove a playlist from your or another user's account. ## SYNTAX ``` -Remove-PlexPlaylist [-Id] [[-AlternativeToken] ] [-WhatIf] [-Confirm] [] +Remove-PlexPlaylist [-Id] [[-AlternativeToken] ] [-ProgressAction ] + [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -91,6 +92,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Remove-PlexShare.md b/Documentation/Remove-PlexShare.md index 6bf9bd0..2a984b5 100644 --- a/Documentation/Remove-PlexShare.md +++ b/Documentation/Remove-PlexShare.md @@ -14,12 +14,14 @@ Removes a shared library from a user. ### LibraryTitle ``` -Remove-PlexShare -Username -LibraryTitle [-WhatIf] [-Confirm] [] +Remove-PlexShare -Username -LibraryTitle [-ProgressAction ] [-WhatIf] + [-Confirm] [] ``` ### LibraryId ``` -Remove-PlexShare -Username -LibraryId [-WhatIf] [-Confirm] [] +Remove-PlexShare -Username -LibraryId [-ProgressAction ] [-WhatIf] + [-Confirm] [] ``` ## DESCRIPTION @@ -110,6 +112,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Set-PlexConfiguration.md b/Documentation/Set-PlexConfiguration.md index fcbb60f..e8ab423 100644 --- a/Documentation/Set-PlexConfiguration.md +++ b/Documentation/Set-PlexConfiguration.md @@ -13,7 +13,8 @@ Obtains an access token for your account and saves it and your server details. ## SYNTAX ``` -Set-PlexConfiguration [-Credential] [-DefaultServerName] [] +Set-PlexConfiguration [-Credential] [-DefaultServerName] + [-ProgressAction ] [] ``` ## DESCRIPTION @@ -58,6 +59,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Set-PlexDefaultServer.md b/Documentation/Set-PlexDefaultServer.md index 76d4c04..5fd9d9a 100644 --- a/Documentation/Set-PlexDefaultServer.md +++ b/Documentation/Set-PlexDefaultServer.md @@ -13,7 +13,7 @@ Set the default Plex server. ## SYNTAX ``` -Set-PlexDefaultServer [-Name] [] +Set-PlexDefaultServer [-Name] [-ProgressAction ] [] ``` ## DESCRIPTION @@ -43,6 +43,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Set-PlexItemEdition.md b/Documentation/Set-PlexItemEdition.md index 83ad58b..c9a96de 100644 --- a/Documentation/Set-PlexItemEdition.md +++ b/Documentation/Set-PlexItemEdition.md @@ -13,7 +13,8 @@ Sets the edition on a Plex (movie) item. ## SYNTAX ``` -Set-PlexItemEdition [-Id] [-Edition] [-WhatIf] [-Confirm] [] +Set-PlexItemEdition [-Id] [-Edition] [-ProgressAction ] [-WhatIf] + [-Confirm] [] ``` ## DESCRIPTION @@ -89,6 +90,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Set-PlexItemRating.md b/Documentation/Set-PlexItemRating.md index a7f9895..a327ac3 100644 --- a/Documentation/Set-PlexItemRating.md +++ b/Documentation/Set-PlexItemRating.md @@ -13,7 +13,8 @@ Sets the rating on a Plex item. ## SYNTAX ``` -Set-PlexItemRating [-Id] [-Rating] [-WhatIf] [-Confirm] [] +Set-PlexItemRating [-Id] [-Rating] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -90,6 +91,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Set-PlexItemWatchStatus.md b/Documentation/Set-PlexItemWatchStatus.md index 6768b75..439b76d 100644 --- a/Documentation/Set-PlexItemWatchStatus.md +++ b/Documentation/Set-PlexItemWatchStatus.md @@ -13,8 +13,8 @@ Set the watch status for a Plex item. ## SYNTAX ``` -Set-PlexItemWatchStatus [-Id] [-Status] [[-AlternativeToken] ] [-WhatIf] [-Confirm] - [] +Set-PlexItemWatchStatus [-Id] [-Status] [[-AlternativeToken] ] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -27,6 +27,13 @@ Set the watch status for a Plex item. Set-PlexItemWatchStatus -Id 1234 -Status played ``` +### EXAMPLE 2 +``` +Set the watch status for item Id 1234 to 'played' for another user: +$User = Get-PlexUser -Username 'username' -IncludeToken +Set-PlexItemWatchStatus -Id 1234 -Status played -AlternativeToken $User.Token +``` + ## PARAMETERS ### -Id @@ -106,6 +113,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Set-PlexWebhook.md b/Documentation/Set-PlexWebhook.md index efa080a..d9dd94b 100644 --- a/Documentation/Set-PlexWebhook.md +++ b/Documentation/Set-PlexWebhook.md @@ -13,7 +13,8 @@ Sets a URL for your Plex server to use for webhooks. ## SYNTAX ``` -Set-PlexWebhook [[-Url] ] [-WhatIf] [-Confirm] [] +Set-PlexWebhook [[-Url] ] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -74,6 +75,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Stop-PlexSession.md b/Documentation/Stop-PlexSession.md index 90f3f2c..e0596bc 100644 --- a/Documentation/Stop-PlexSession.md +++ b/Documentation/Stop-PlexSession.md @@ -14,12 +14,14 @@ Stops a Plex session. ### SessionId ``` -Stop-PlexSession -Id [-Reason ] [-WhatIf] [-Confirm] [] +Stop-PlexSession -Id [-Reason ] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ### SessionObject ``` -Stop-PlexSession -SessionObject [-Reason ] [-WhatIf] [-Confirm] [] +Stop-PlexSession -SessionObject [-Reason ] [-ProgressAction ] [-WhatIf] + [-Confirm] [] ``` ## DESCRIPTION @@ -113,6 +115,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Update-PlexItemMetadata.md b/Documentation/Update-PlexItemMetadata.md index 520c22d..a48a24d 100644 --- a/Documentation/Update-PlexItemMetadata.md +++ b/Documentation/Update-PlexItemMetadata.md @@ -13,7 +13,8 @@ Update the metadata for a Plex item. ## SYNTAX ``` -Update-PlexItemMetadata [-Id] [-WhatIf] [-Confirm] [] +Update-PlexItemMetadata [-Id] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -74,6 +75,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/Documentation/Update-PlexLibrary.md b/Documentation/Update-PlexLibrary.md index 1e4230a..6b3527f 100644 --- a/Documentation/Update-PlexLibrary.md +++ b/Documentation/Update-PlexLibrary.md @@ -13,7 +13,8 @@ Initiates an update on a library. ## SYNTAX ``` -Update-PlexLibrary [-Id] [-WhatIf] [-Confirm] [] +Update-PlexLibrary [-Id] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -74,6 +75,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/README.md b/README.md index 05b3e34..38751f8 100644 --- a/README.md +++ b/README.md @@ -58,10 +58,17 @@ Remove-PlexPlaylist -Id 12345 Remove-PlexShare -LibraryId 5 -Username 'yourfriend@theiremail.com' ``` +**Create a smart collection:** + +```powershell +$Library = Get-PlexLibrary -Name 'movies' +New-PlexSmartCollection -Name "Harry Potter" -LibraryId $Library.key -Filter "Title Contains Harry Potter" +``` + **Remove a collection called 'test' a library called 'movies'** ```powershell $Library = Get-PlexLibrary -Name 'movies' -Get-PlexCollection -LibraryId $Library | Where-Object { $_.title -eq 'test' } | Select -Expand ratingKey | Remove-PlexCollection +Get-PlexCollection -LibraryId $Library.key | Where-Object { $_.title -eq 'test' } | Select -Expand ratingKey | Remove-PlexCollection ```
diff --git a/Source/PSPlex.psd1 b/Source/PSPlex.psd1 index 58db4a0..a7f4e7f 100644 --- a/Source/PSPlex.psd1 +++ b/Source/PSPlex.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSPlex.psm1' # Version number of this module. - ModuleVersion = '1.0.15' + ModuleVersion = '1.0.16' # Supported PSEditions CompatiblePSEditions = 'Core', 'Desktop' @@ -84,6 +84,7 @@ 'Get-PlexUser' 'Get-PlexWatchHistory' 'New-PlexPlaylist' + 'New-PlexSmartCollection' 'Remove-PlexCollection' 'Remove-PlexPlaylist' 'Remove-PlexLabel' diff --git a/Source/Private/Resolve-PlexFilter.ps1 b/Source/Private/Resolve-PlexFilter.ps1 new file mode 100644 index 0000000..d1f42a6 --- /dev/null +++ b/Source/Private/Resolve-PlexFilter.ps1 @@ -0,0 +1,180 @@ +function Resolve-PlexFilter +{ + <# + .SYNOPSIS + Parses filter string into Plex API query. + .DESCRIPTION + Parses filter string into Plex API query. Filter syntax is ' '. Clauses are separated by semi-colons (;) + .EXAMPLE + Resolve-PlexFilter -MatchAll -Filter "Title BeginsWith Star Trek; Unplayed IsTrue" + .EXAMPLE + Resolve-PlexFilter -MatchAny -Filter "DateAdded IsNotInTheLast 2y; Unplayed IsTrue" + .EXAMPLE + Resolve-PlexFilter -MatchAll -Filter "Actor IsNot Robert Pattinson; Title BeginsWith bat" -LibraryId 1 + #> + + [CmdletBinding()] + [OutputType([string])] + param( + [Parameter(Mandatory)] + [string] + $Filter, + + [Parameter()] + [ValidateSet("MatchAll", "MatchAny")] + [string] + $MatchType = "MatchAll", + + [Parameter()] + [string] + $LibraryId, + + [Parameter(DontShow)] + [switch] + $IKnowWhatImDoing + ) + + end + { + # Copied from Plex web GUI. + $Operators = @{ + # Class = @{ + # Operator1 = "..." + # Operator2 = "..." + # } + String = @{ + Contains = "=" + DoesNotContain = "!=" + Is = "==" + IsNot = "!==" + BeginsWith = "<=" + EndsWith = ">=" + } + Numeric = @{ + Is = "=" + IsNot = "!=" + IsGreaterThan = ">>=" + IsLessThan = "<<=" + } + Exact = @{ + Is = "=" + IsNot = "!=" + } + Bool = @{ + IsTrue = "=1" + IsFalse = "!=1" + } + SemiBool = @{ + Is = "=" + } + Date = @{ + IsBefore = "<<=" + IsAfter = ">>=" + IsInTheLast = ">>=-" + IsNotInTheLast = "<<=-" + } + } + + # Copied from Plex web GUI and translated into Plex DB attributes. + $Attributes = @{ + # NameinGUI = @{ Class = "ClassName" ; Name = "NameInDB" } + Title = @{ Class = "String" ; Name = "title" } + Studio = @{ Class = "String" ; Name = "studio" } + Edition = @{ Class = "String" ; Name = "editionTitle" } + Rating = @{ Class = "Numeric" ; Name = "userRating" } + Year = @{ Class = "Numeric" ; Name = "year" } + Decade = @{ Class = "Numeric" ; Name = "decade" } + Plays = @{ Class = "Numeric" ; Name = "viewCount" } + ContentRating = @{ Class = "Exact" ; Name = "contentRating" } + Genre = @{ Class = "Exact" ; Name = "genre" } + Collection = @{ Class = "Exact" ; Name = "collection" } + Director = @{ Class = "Exact" ; Name = "director" } + Writer = @{ Class = "Exact" ; Name = "writer" } + Producer = @{ Class = "Exact" ; Name = "producer" } + Actor = @{ Class = "Exact" ; Name = "actor" } + Country = @{ Class = "Exact" ; Name = "country" } + SubtitleLanguage = @{ Class = "Exact" ; Name = "subtitleLanguage" } + AudioLanguage = @{ Class = "Exact" ; Name = "audioLanguage" } + Label = @{ Class = "Exact" ; Name = "label" } + Unmatched = @{ Class = "Bool" ; Name = "unmatched" } + Duplicate = @{ Class = "Bool" ; Name = "duplicate" } + Unplayed = @{ Class = "Bool" ; Name = "unwatched" } + HDR = @{ Class = "Bool" ; Name = "hdr" } + InProgress = @{ Class = "Bool" ; Name = "inProgress" } + Trash = @{ Class = "Bool" ; Name = "trash" } + Resolution = @{ Class = "SemiBool" ; Name = "resolution" } + ReleaseDate = @{ Class = "Date" ; Name = "originallyAvailableAt" } + DateAdded = @{ Class = "Date" ; Name = "addedAt" } + LastPlayed = @{ Class = "Date" ; Name = "lastViewedAt" } + } + + try + { + $Query = foreach ($Clause in ($Filter -split ';')) + { + # Parse out values from clause + if (-not ($Clause -match '(?\w+) (?\w+)(?: (?.*))?')) + { + throw "Unable to parse filter clause '$Clause'. Syntax is ' '." + } + + # Translate clause into API query and verify that it makes sense. + $Attribute = $Attributes[$Matches.Attribute] + $Operator = $Operators[$Attribute.Class].($Matches.Operator) + if (-not $Attribute) + { + throw "Unable to parse filter clause '$Clause'. Attribute does not exist in Plex DB." + } + if (-not $Operator) + { + throw "Unable to parse filter clause '$Clause'. Operator not supported by the attribute." + } + + # Translate Exact class into Plex DB key + if ($Attribute.Class -eq 'Exact') + { + # Import PlexConfigData + if (!$script:PlexConfigData) + { + try + { + Import-PlexConfiguration -WhatIf:$False + } + catch + { + throw $_ + } + } + $Uri = Get-PlexAPIUri -RestEndpoint "library/sections/$LibraryId/$($Attribute.Name)" -ErrorAction Stop + $Key = ((Invoke-RestMethod -Uri $Uri -Method Get -ErrorAction Stop).MediaContainer.Directory | Where-Object { $_.title -eq $Matches.Value }).key + #TODO implement caching for attribute keys + if (-not ($Key -or $IKnowWhatImDoing)) + { + throw ("Unable to find key for '{0}' in library '{1}'." -f $Matches.Value, $LibraryId) + } + + $Matches.Value = @($Matches.Value, $Key)[[bool]$Key] # Null check for key + } + + # Return API query + $Attribute.Name, $Operator, $Matches.Value -join '' + } + + # Return entire API query + switch ($MatchType) + { + "MatchAll" { $Query -join '&' ; continue } + "MatchAny" { "push=1&{0}&pop=1" -f ($Query -join '&or=1&') ; continue } + default { throw "You should not see this." } + } + } + catch + { + if ($_.Exception.Message -match "Index operation failed") + { + throw "Unable to parse filter clause '$Clause'." + } + else { $PSCmdlet.ThrowTerminatingError($_) } + } + } +} \ No newline at end of file diff --git a/Source/Public/Get-PlexCollection.ps1 b/Source/Public/Get-PlexCollection.ps1 index 3298255..a7ff59c 100644 --- a/Source/Public/Get-PlexCollection.ps1 +++ b/Source/Public/Get-PlexCollection.ps1 @@ -15,6 +15,9 @@ function Get-PlexCollection Get-PlexCollection -LibraryId 1 .EXAMPLE Get-PlexCollection -Id 723 -IncludeItems + .EXAMPLE + # Get all collections from library 1 with the name, id (ratingkey) and number of items in the collection: + Get-PlexCollection -LibraryId 1 | Select-Object title,ratingkey,childcount #> [CmdletBinding()] diff --git a/Source/Public/Get-PlexUser.ps1 b/Source/Public/Get-PlexUser.ps1 index c477381..1be40f0 100644 --- a/Source/Public/Get-PlexUser.ps1 +++ b/Source/Public/Get-PlexUser.ps1 @@ -77,6 +77,10 @@ function Get-PlexUser { Write-Verbose -Message "Function: $($MyInvocation.MyCommand): Filtering by username" [array]$Results = $Data.MediaContainer.User | Where-Object { $_.username -eq $Username } + if(!$Results) + { + throw "Username '$Username' not found." + } } else { diff --git a/Source/Public/New-PlexSmartCollection.ps1 b/Source/Public/New-PlexSmartCollection.ps1 new file mode 100644 index 0000000..08a8b18 --- /dev/null +++ b/Source/Public/New-PlexSmartCollection.ps1 @@ -0,0 +1,205 @@ +function New-PlexSmartCollection +{ + <# + .SYNOPSIS + Creates a new smart collection. + .DESCRIPTION + Creates a new smart collection. + .PARAMETER Name + Name of the smart collection. + .PARAMETER LibraryId + ID of the library to create the smart collection in. + .PARAMETER Filter + Specifies the query string that retrieves the items in the smart collection. The syntax matches the Plex Web GUI as closely as possible. Clauses are separated by a semi-colon ( ; ). + + Syntax: + + - + - ; + + - Attributes: + - String + - Title + - Studio + - Edition + - Numeric + - Rating + - Year + - Decade + - Plays + - Exact + - ContentRating + - Genre + - Collection + - Actor + - Country + - SubtitleLanguage + - AudioLanguage + - Label + - Boolean + - Unmatched + - Duplicate + - Unplayed + - HDR + - InProgress + - Trash + - Semi-Boolean + - Resolution + - Date + - ReleaseDate + - DateAdded + - LastPlayed + + - Operators: + - String + - Contains + - DoesNotContain + - Is + - IsNot + - BeginsWith + - EndsWith + - Numeric + - Is + - IsNot + - IsGreaterThan + - IsLessThan + - Exact + - Is + - IsNot + - Boolean + - IsTrue + - IsFalse + - Semi-Boolean + - Is + - Date + - IsBefore (Value format: yyyy-mm-dd) + - IsAfter (Value format: yyyy-mm-dd) + - IsInTheLast + - IsNotInTheLast + + - Examples: + - "DateAdded IsNotInTheLast 2y; Unplayed IsTrue" + - "Title BeginsWith Star Trek; Unplayed IsTrue" + - "Actor Is Jim Carrey; Genre Is Comedy" + + .PARAMETER MatchType + Specifies how filter clauses are matched. + + - MatchAll: Matches all clauses. + - MatchAny: Matches any cluase. + .EXAMPLE + New-PlexSmartCollection -Name "Star Trek" -LibraryId 1 -Filter "Title Contains Star Trek" + .EXAMPLE + New-PlexSmartCollection -Name "80's" -LibraryId 1 -Filter "Decade Is 1980" + .EXAMPLE + New-PlexSmartCollection -Name "Old Favorites" -LibraryId 1 -Filter "Plays IsGreaterThan 2; LastPlayed IsNotInTheLast 1y" + .EXAMPLE + New-PlexSmartCollection -Name "Trek Wars" -LibraryId 1 -MatchType MatchAny -Filter "title contains star trek; title contains star wars" + #> + + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(Mandatory)] + [string] + $Name, + + [Parameter(Mandatory)] + [string] + $LibraryId, + + [Parameter(Mandatory)] + [string] + $Filter, + + [Parameter()] + [ValidateSet("MatchAll", "MatchAny")] + [string] + $MatchType = "MatchAll" + ) + + ############################################################################# + #Region Import Plex Configuration + if(!$script:PlexConfigData) + { + try + { + Import-PlexConfiguration -WhatIf:$False + } + catch + { + throw $_ + } + } + #EndRegion + + ############################################################################# + #Region Check if collection already exists + try + { + $Collections = Get-PlexCollection -LibraryId $LibraryId + if ($Collections.title -contains $Name) + { + throw "Collection '$Name' already exits" + } + } + catch + { + $PSCmdlet.ThrowTerminatingError($_) + } + #EndRegion + + ############################################################################# + #Region Get machine identifier + Write-Verbose -Message "Function: $($MyInvocation.MyCommand): Getting list of Plex servers (to get machine identifier)" + try + { + $CurrentPlexServer = Get-PlexServer -Name $DefaultPlexServer.PlexServer -ErrorAction Stop + if(!$CurrentPlexServer) + { + throw "Could not find $CurrentPlexServer in $($Servers -join ', ')" + } + } + catch + { + throw $_ + } + #EndRegion + + ############################################################################# + #Region Construct Uri + try + { + $Items = Resolve-PlexFilter -MatchType $MatchType -LibraryId $LibraryId -Filter $Filter + $Params = [ordered]@{ + type = '1' + title = [System.Uri]::EscapeDataString($Name) + smart = '1' + sectionId = $LibraryId + uri = [System.Uri]::EscapeDataString("server://$($CurrentPlexServer.machineIdentifier)/com.plexapp.plugins.library/library/sections/$LibraryId/all?type=1&sort=titleSort&$Items") + } + + $DataUri = (Get-PlexAPIUri -RestEndpoint "library/collections" -Params $Params) + } + catch + { + $PSCmdlet.ThrowTerminatingError($_) + } + #EndRegion + + ############################################################################# + #Region Make request + if($PSCmdlet.ShouldProcess("Library $LibraryId", "Create Smart Collection '$Name'")) + { + Write-Verbose -Message "Function: $($MyInvocation.MyCommand): Creating Smart Collection $Name in Libary '$LibraryId'" + try + { + $Data = Invoke-RestMethod -Uri $DataUri -Method POST + return $Data.mediacontainer.metadata + } + catch + { + throw $_ + } + } + #EndRegion +} \ No newline at end of file diff --git a/Source/Public/Remove-PlexCollection.ps1 b/Source/Public/Remove-PlexCollection.ps1 index e354b70..b7a81c5 100644 --- a/Source/Public/Remove-PlexCollection.ps1 +++ b/Source/Public/Remove-PlexCollection.ps1 @@ -10,7 +10,7 @@ function Remove-PlexCollection .EXAMPLE Remove-PlexCollection -Id 12345 .EXAMPLE - Get-PlexCollection | Where-object {[int]$_.childCount -lt 5} | Select-Object -ExpandProperty ratingKey | Remove-PlexCollection + Get-PlexCollection -LibraryId 1 | Where-object {[int]$_.childCount -lt 5} | Select-Object -ExpandProperty ratingKey | Remove-PlexCollection #> [CmdletBinding(SupportsShouldProcess)] diff --git a/Source/Public/Set-PlexItemWatchStatus.ps1 b/Source/Public/Set-PlexItemWatchStatus.ps1 index ede73c6..6892bfd 100644 --- a/Source/Public/Set-PlexItemWatchStatus.ps1 +++ b/Source/Public/Set-PlexItemWatchStatus.ps1 @@ -13,6 +13,10 @@ function Set-PlexItemWatchStatus Token for another user. .EXAMPLE Set-PlexItemWatchStatus -Id 1234 -Status played + .EXAMPLE + Set the watch status for item Id 1234 to 'played' for another user: + $User = Get-PlexUser -Username 'username' -IncludeToken + Set-PlexItemWatchStatus -Id 1234 -Status played -AlternativeToken $User.Token #> [CmdletBinding(SupportsShouldProcess)]