Advertisement
Moktart

ContentScraper

Nov 4th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [System.Reflection.Assembly]::LoadWithPartialName("System.web")
  2. [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  3. [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
  4.  
  5.     $mainurl = "http://www.animeflavor.com"
  6.         $urls = @{}
  7.         $episodes = @{}
  8.  
  9. Function GetList($MainUrl){
  10.     Write-host "Grabbing first WebRequest: $mainurl"
  11.     $content = invoke-webrequest $MainUrl -TimeoutSec 11 -ErrorAction Stop
  12.     $URLList = $($content.AllElements | ?{$_.tagname -eq "LI"} | select -expand innerhtml | select-string -pattern ".*(http.*)`"").matches.groups.captures.value | ?{$_ -match ("^http.*" + $targetshow + ".*")} | select -unique
  13.     return $URLList
  14.     }
  15.  
  16. Function WatchShow ($episodeUrl, $ShowName, $EpisodeName, [switch]$watchnow) {
  17.     $content = invoke-webrequest -uri "$mainurl/$episodeUrl" -TimeoutSec 9
  18.     $nextUrl = $content.RawContent | select-string -Pattern "`"(?<url>\/nan\/.+php)`"" | %{$_.matches.captures.groups[1].value}
  19.     $content = invoke-webrequest -uri "http://www.animeflavor.com$nextUrl"
  20.     $fileUrl = $content.scripts | ? innerHTML -match "afplayer" | select -expand innerHTML | select-string -Pattern "file.*(?<url>http.+)`'" |%{ $_.matches.captures.groups[1].value}
  21.     $filepathy = "`"$pwd\$EpisodeName.flv`""
  22.     write-host "Wgetting: $encodedfileurl"
  23.     $WgetArguments = @{argumentlist = "/c wget -c `"$fileUrl`" -O $FilePathy"}
  24.     if (-not $watchnow) {$WgetArguments += @{wait=$true}}
  25.     if (-not (test-path $filepathy)) {start-process "cmd.exe" @WGetarguments}
  26.     if ($watchnow){
  27.         sleep 10
  28.         start-process $player -argumentlist $filepathy
  29.         }
  30.     }
  31.  
  32. Function WatchEpisode() {
  33.     $EpisodeName = $Global:EpisodeCombo.SelectedItem
  34.     $showName = $Global:ShowCombo.SelectedItem
  35.     $episodeUrl  = $episodes[$EpisodeName]
  36.     WatchShow $episodeUrl $showName $EpisodeName -watchnow
  37.     }
  38.  
  39. Function Form([array]$Size, $Text) {
  40.     $Form = New-Object System.Windows.Forms.Form
  41.     $Form.width = $Size[0]
  42.     $Form.height = $Size[1]
  43.     $Form.Text = $Text
  44.     $Form.AutoSize = $True
  45.     $Form.AutoSizeMode = "GrowAndShrink"
  46.     Return $Form
  47.     }
  48.  
  49. Function Click ($selection) {WatchOne $selection}
  50.  
  51.  
  52. Function GetShowList() {
  53.     $Genre = $Global:GenreCombo.selectedItem
  54.     $content = Invoke-WebRequest -uri "$mainurl/$genre"
  55.     $($content.ParsedHtml.getElementById("postareainner")).getElementsByTagName("a") | %{$urls.add($_.innerText,$_.pathname)}
  56.     $Global:ShowCombo.Items.Clear()
  57.     $urls.keys | sort | % {$Global:ShowCombo.Items.Add($_) | Out-Null}
  58.     $Global:ShowCombo.Enabled = $True
  59.     }
  60.  
  61. Function GetEpisodeList() {
  62.     $Global:Show = $Global:ShowCombo.SelectedItem
  63.     $showUrl = $urls[$Global:Show]
  64.     write-host "$mainurl/$showUrl"
  65.     $content = Invoke-WebRequest -uri "$mainurl/$showUrl"
  66.     $($content.ParsedHtml.getElementsByTagName("div") | ? IHTMLELEMENT_classname -eq "book-navigation").getElementsByTagName("a") | %{$episodes.add($_.innerText,$_.pathname)}
  67.     $Global:EpisodeCombo.Items.Clear()
  68.     $episodes.keys | sort | % {$Global:EpisodeCombo.Items.Add($_) | Out-Null}
  69.     $Global:EpisodeCombo.Enabled = $True
  70.     }
  71.  
  72. Function DropDown($Form, [Array]$Size, [Array]$Location, $List, $Action, $Enabled){
  73.     $DropDown = new-object System.Windows.Forms.ComboBox
  74.     $DropDown.Location = new-object System.Drawing.Size($Location[0],$Location[1])
  75.     $DropDown.Size = new-object System.Drawing.Size($Size[0],$Size[1])
  76.     ForEach ($Item in $List) {$DropDown.Items.Add($Item) | Out-Null}
  77.     $DropDown.Add_SelectedIndexChanged($Action)
  78.     $DropDown.Enabled = $Enabled
  79.     $Form.Controls.Add($DropDown)
  80.     Return $DropDown
  81.     }
  82.  
  83.  
  84. $Genres = @("cartoons","anime")
  85. $Player = 'C:\Program Files (x86)\VideoLAN\VLC\vlc.exe'
  86.  
  87.  
  88. #(width/height) (X/Y)
  89. $Global:Form =         Form          @(100,150) "Watch!"
  90. $Global:GenreCombo =   DropDown      $Global:Form @(300,1)    @(30,30)  $Genres {GetShowList} $True
  91. $Global:ShowCombo =    DropDown      $Global:Form @(300,1)    @(30,50)  @() {GetEpisodeList} $False
  92. $Global:EpisodeCombo = DropDown      $Global:Form @(300,1)    @(30,70)  @() {WatchEpisode} $False
  93.  
  94. $Global:Form.Add_Shown({$Global:Form.Activate()})
  95. $Global:Form.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement