Last active
October 23, 2016 20:05
-
-
Save vadyua/07a0edc6a21ec2f4c90e63ddfc68755b to your computer and use it in GitHub Desktop.
This file contains 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
Param( | |
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true,HelpMessage="Provide a full path to movie files")] | |
[alias("p")] | |
[ValidateScript({ $_.Replace("[", "``[").Replace("]", "``]"); Test-Path -Path $_ -PathType 'Container'})] | |
[System.String]$path, | |
[Parameter(Position=1,ValueFromPipeline=$true)] | |
[alias("api")] | |
[int]$apikey = "098f6bcd4621d373cade4e832627b4f6" # Get your own! https://developers.themoviedb.org/3/getting-started/authentication | |
) | |
Add-Type -AssemblyName System.Web | |
Get-ChildItem -Path $path -Force | ?{!$_.PSIsContainer -and $_.Name -match "\.(avi|mkv|mp4|xvid)$"} | Select -First 10 | %{ | |
$dir = $_.Directory.Fullname | |
$imdburi = "https://api.themoviedb.org/3/search/movie?query={0}&language=ru-RU&api_key={1}" -f [System.Web.HttpUtility]::UrlEncode([System.IO.Path]::GetFileNameWithoutExtension($_.Name)), $apikey | |
$movie = Invoke-WebRequest -Uri $imdburi | |
(ConvertFrom-Json $movie.Content).results | Select -First 1 | %{ | |
#$r = Invoke-WebRequest -Uri ("https://api.themoviedb.org/3/movie/{0}/images?api_key={1}" -f $_.id, $apikey) | |
#$images = (ConvertFrom-Json $r).backdrops | |
$filename = "{0} - {1} ({2}){3}" -f $_.original_title, $_.title, ([datetime]::Parse($_.release_date)).Year, [System.IO.Path]::GetExtension($_.poster_path) | |
$filename = $filename -replace ":",' - ' -replace ' {2}', ' ' | |
$filename = ([char[]]$filename | ?{[IO.Path]::GetinvalidFileNameChars() -notcontains $_ }) -join '' | |
Invoke-WebRequest -Uri ("https://image.tmdb.org/t/p/w640"+$_.poster_path) -OutFile "$dir\$filename" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment