Created
April 15, 2018 15:36
-
-
Save Sam-Martin/b98712cbf7915e4266d8e3ffe7ce18a2 to your computer and use it in GitHub Desktop.
Delete Lower Quality Plex Duplicates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Server='192.168.1.9:32400' | |
$PlexToken = 'FGir5aQ5yfpRZZ4ZqxAg' | |
$libraries = Invoke-RestMethod -Uri "http://$server/library/sections/all?X-Plex-Token=$PlexToken" | |
$VideoLibraries = $libraries.MediaContainer.Directory | ?{$_.type -eq 'show'} | |
$Resolutions = @{ | |
"sd" = 1 | |
"420" = 10 | |
"720" = 20 | |
"1080" = 30 | |
} | |
foreach($library in $VideoLibraries){ | |
#$library | |
$episodes = Invoke-RestMethod -Uri "http://$server/library/sections/$($library.key)/all?type=4&duplicate=1&X-Plex-Token=$PlexToken" | |
foreach($episode in $episodes.MediaContainer.Video){ | |
Write-Information "$($episode.GrandparentTitle) $($episode.ParentTitle) $($episode.title)" | |
$MediaFilesByQuality = $episode.Media | Select-Object @{L='width';E={[int]$_.width}}, @{L='Bitrate';E={[int]$_.bitrate}}, id | Sort-Object width,bitrate -Descending | |
$Winner = $MediaFilesByQuality[0] | |
Write-Information "`tWinner is $($Winner.width) at $($Winner.bitrate)bps" | |
$Losers = $MediaFilesByQuality[1..$MediaFilesByQuality.Length] | |
Foreach($Loser in $Losers){ | |
Write-Information "`t`tDeleting loser: $($Loser.width) at $($Loser.bitrate)bps" | |
$url = "http://192.168.1.9:32400$($Episode.Key)/media/$($Loser.id)?X-Plex-Token=$PlexToken" | |
Write-Information $url | |
Invoke-RestMethod $url -Method Delete | |
#Invoke-WebRequest -Uri "http://192.168.1.9:32400/library/metadata/31701/media/60326?X-Plex-Product=Plex%20Web&X-Plex-Version=3.39.5&X-Plex-Client-Identifier=51o3nj392lk2e4zcn61myrda&X-Plex-Platform=Chrome&X-Plex-Platform-Version=65.0&X-Plex-Sync-Version=2&X-Plex-Device=Windows&X-Plex-Device-Name=Chrome&X-Plex-Device-Screen-Resolution=1920x949%2C1920x1080&X-Plex-Token=FGir5aQ5yfpRZZ4ZqxAg&X-Plex-Provider-Version=1.1" -Method "DELETE" | |
#-Headers @{"Cookie"="imdb_top_dvd_rentals_view=thumb; wanted_view=thumb; advanced_toggle_checked=1; snatched_view=list; soon_view=thumb; suggest_view=thumb; late_view=list; blu_ray_com_new_releases_view=thumb; imdb_box_office_view=thumb; imdb_top_250_movies_view=thumb; _ga=GA1.1.821301858.1492893135; _pk_id.1.b9e6=51028061d5d57592.1495274484.60.1523229603.1523229602.; login_cookie=816dfa72c4545e16c4d0e595627feb181f417539; login_salt=69"; "Origin"="http://192.168.1.9:32400"; "Accept-Encoding"="gzip, deflate"; "Accept-Language"="en-GB"; "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"; "Accept"="text/plain, */*; q=0.01"; "Referer"="http://192.168.1.9:32400/web/index.html"; "X-Requested-With"="XMLHttpRequest"} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey dude, thanks for posting this. So you know, though, you published your personal authentication token. You might want to edit/delete this Gist.