<a href="http://www.blogger.com/tv/How%20I%20Met%20Your%20Mother/05/how.i.met.your.mother.s05e11.720p.hdtv.x264-ctu.mkv">Season 5 Episode 11</a>;
The web interface isn't bad, but I like to mess around with scripting and command line stuff, so here's a powershell script that will play the latest show matching a given string. (Examples:
latest how
, latest -n 2 dollhouse
)
param(
[switch]$switch = $false,
[string]$query = $(Read-Host -prompt "Keyword"),
[int]$num = $(if ($switch) {Read-Host -prompt "Number"} else {1})
)
$player = "C:\Program Files\SMPlayer\smplayer.exe"
$client = New-Object System.Net.WebClient
$data = $client.DownloadData("http://spot/")
$page = [System.Text.Encoding]::ASCII.GetString($data)
# They are displayed on the page with newest on top, but we want to play them in order (oldest to newest)
$matches = [regex]::Matches($page, "href=`"([^\<\>]*?$query[^\<\>]*?\.[^\<\>]*?)`"", "IgnoreCase") | Select-Object -first $num | Sort-Object
$files = ""
foreach ($m in $matches) {
$files += "'http://spot/$($m.groups[1])' "
}
if ($files.Length -gt 0) {
echo $files
Start-Process $player $files
}
else { echo "Could not find anything matching '$query'" }
Notes:
- [^\<\>] means "any character except < or >". The *? means "any number of the preceding". So in this case, it means "any number of characters except < or >". Useful for reading the text between tags.
- The bit at the top lets you optionally specify the number of matches to use with -num (or -n), defaulting to 1 otherwise. If you don't give it a query, it will prompt you. (It doesn't properly handle the case of -num w/o a number, but I don't care at this point. You'll get an error message, just not a nice one).
No comments:
Post a Comment