PageRenderTime 71ms CodeModel.GetById 18ms app.highlight 47ms RepoModel.GetById 2ms app.codeStats 0ms

/Scraper dll sources/TVDB/TVDB/TVDB.vb

#
Visual Basic | 430 lines | 387 code | 32 blank | 11 comment | 0 complexity | e1282fbec01458c12806dd6f6a3ac1e5 MD5 | raw file
  1Imports System.IO
  2Imports System.Net
  3Imports System.Threading
  4Imports System.Xml
  5
  6Public Class tvdbscraper
  7    Private Structure possibleshowlist
  8        Dim showtitle As String
  9        Dim showid As String
 10        Dim showbanner As String
 11    End Structure
 12
 13    Public Function getposterlist(ByVal tvdbid As String)
 14        Monitor.Enter(Me)
 15        Try
 16            Dim mirrors As New List(Of String)
 17            Dim xmlfile As String
 18            Dim wrGETURL As WebRequest
 19            Dim mirrorsurl As String = "http://www.thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/banners.xml"
 20            wrGETURL = WebRequest.Create(mirrorsurl)
 21            Dim myProxy As New WebProxy("myproxy", 80)
 22            myProxy.BypassProxyOnLocal = True
 23            Dim objStream As Stream
 24            objStream = wrGETURL.GetResponse.GetResponseStream()
 25            Dim objReader As New StreamReader(objStream)
 26            xmlfile = objReader.ReadToEnd
 27            Dim bannerslist As New XmlDocument
 28            'Try
 29            Dim bannerlist As String = "<banners>"
 30            bannerslist.LoadXml(xmlfile)
 31            Dim thisresult As XmlNode = Nothing
 32            For Each thisresult In bannerslist("Banners")
 33
 34                Select Case thisresult.Name
 35                    Case "Banner"
 36                        bannerlist = bannerlist & "<banner>"
 37                        Dim bannerselection As XmlNode = Nothing
 38                        For Each bannerselection In thisresult.ChildNodes
 39                            Select Case bannerselection.Name
 40                                Case "BannerPath"
 41
 42                                    bannerlist = bannerlist & "<url>http://thetvdb.com/banners/" & bannerselection.InnerXml & "</url>"
 43                                Case "BannerType"
 44                                    bannerlist = bannerlist & "<bannertype>" & bannerselection.InnerXml & "</bannertype>"
 45                                Case "BannerType2"
 46                                    bannerlist = bannerlist & "<resolution>" & bannerselection.InnerXml & "</resolution>"
 47                                Case "Language"
 48                                    bannerlist = bannerlist & "<language>" & bannerselection.InnerXml & "</language>"
 49                                Case "Season"
 50                                    bannerlist = bannerlist & "<season>" & bannerselection.InnerXml & "</season>"
 51                                Case ""
 52                            End Select
 53                        Next
 54                        bannerlist = bannerlist & "</banner>"
 55                End Select
 56            Next
 57            bannerlist = bannerlist & "</banners>"
 58            Return bannerlist
 59
 60        Catch EX As Exception
 61            Return EX.ToString
 62        Finally
 63            Monitor.Exit(Me)
 64        End Try
 65    End Function
 66
 67    Public Function getmirrors()
 68        Monitor.Enter(Me)
 69        Try
 70            Dim mirrors As New List(Of String)
 71            Dim xmlfile As String
 72            Dim wrGETURL As WebRequest
 73            Dim mirrorsurl As String = "http://www.thetvdb.com/api/6E82FED600783400/mirrors.xml"
 74            wrGETURL = WebRequest.Create(mirrorsurl)
 75            Dim myProxy As New WebProxy("myproxy", 80)
 76            myProxy.BypassProxyOnLocal = True
 77            Dim objStream As Stream
 78            objStream = wrGETURL.GetResponse.GetResponseStream()
 79            Dim objReader As New StreamReader(objStream)
 80            xmlfile = objReader.ReadToEnd
 81            Dim mirrorslist As New XmlDocument
 82            'Try
 83            mirrorslist.LoadXml(xmlfile)
 84            Dim thisresult As XmlNode = Nothing
 85            For Each thisresult In mirrorslist("Mirrors")
 86
 87                Select Case thisresult.Name
 88                    Case "Mirror"
 89                        Dim mirrorselection As XmlNode = Nothing
 90                        For Each mirrorselection In thisresult.ChildNodes
 91                            Select Case mirrorselection.Name
 92                                Case "mirrorpath"
 93                                    If mirrorselection.InnerText <> Nothing Then
 94                                        mirrors.Add(mirrorselection.InnerText)
 95                                    End If
 96                            End Select
 97                        Next
 98                End Select
 99            Next
100            Return mirrors
101      
102        Catch EX As Exception
103            Return EX.ToString
104        Finally
105            Monitor.Exit(Me)
106        End Try
107    End Function
108
109    Public Function findshows(ByVal title As String, Optional ByVal mirror As String = "http://thetvdb.com")
110        Monitor.Enter(Me)
111        'Try
112        Dim possibleshows As New List(Of possibleshowlist)
113        Dim xmlfile As String
114        Dim wrGETURL As WebRequest
115        Dim mirrorsurl As String = "http://www.thetvdb.com/api/GetSeries.php?seriesname=" & title & "&language=all"
116        wrGETURL = WebRequest.Create(mirrorsurl)
117        Dim myProxy As New WebProxy("myproxy", 80)
118        myProxy.BypassProxyOnLocal = True
119        Dim objStream As Stream
120        objStream = wrGETURL.GetResponse.GetResponseStream()
121        Dim objReader As New StreamReader(objStream)
122        xmlfile = objReader.ReadToEnd
123        Dim showlist As New XmlDocument
124        Try
125            showlist.LoadXml(xmlfile)
126            Dim thisresult As XmlNode = Nothing
127            For Each thisresult In showlist("Data")
128
129                Select Case thisresult.Name
130                    Case "Series"
131                        Dim newshow As New possibleshowlist
132                        Dim mirrorselection As XmlNode = Nothing
133                        For Each mirrorselection In thisresult.ChildNodes
134                            Select Case mirrorselection.Name
135                                Case "seriesid"
136                                    newshow.showid = mirrorselection.InnerXml
137                                Case "SeriesName"
138                                    newshow.showtitle = mirrorselection.InnerXml
139                                Case "banner"
140                                    newshow.showbanner = "http://www.thetvdb.com/banners/" & mirrorselection.InnerXml
141                            End Select
142                        Next
143                        possibleshows.Add(newshow)
144                End Select
145            Next
146            Dim returnstring As String
147            Dim ok As Boolean = False
148            If possibleshows.Count > 0 Then
149                returnstring = "<allshows>"
150                For Each show In possibleshows
151                    If show.showid <> Nothing Then
152                        returnstring = returnstring & "<show>"
153                        returnstring = returnstring & "<showid>" & show.showid & "</showid>"
154                        ok = True
155                        If show.showtitle <> Nothing Then
156                            returnstring = returnstring & "<showtitle>" & show.showtitle & "</showtitle>"
157                        End If
158                        If show.showbanner <> Nothing Then
159                            returnstring = returnstring & "<showbanner>" & show.showbanner & "</showbanner>"
160                        End If
161                        returnstring = returnstring & "</show>"
162                    End If
163                Next
164                returnstring = returnstring & "</allshows>"
165            Else
166                returnstring = "none"
167            End If
168            If ok = False Then returnstring = "none"
169            Return returnstring
170            'Catch EX As Exception
171            '    Return EX.ToString
172            'End Try
173        Catch EX As Exception
174            Return "error"
175        Finally
176            Monitor.Exit(Me)
177        End Try
178    End Function
179
180    Public Function getshow(ByVal tvdbid As String, ByVal language As String)
181        Monitor.Enter(Me)
182        Try
183            Dim tvshowdetails As String = "<fulltvshow>"
184            Dim xmlfile As String
185            Dim wrGETURL As WebRequest
186            Dim episodeguideurl As String = "http://www.thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/all/" & language & ".zip"
187            Dim mirrorsurl As String = "http://www.thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/" & language & ".xml"
188            wrGETURL = WebRequest.Create(mirrorsurl)
189            Dim myProxy As New WebProxy("myproxy", 80)
190            myProxy.BypassProxyOnLocal = True
191            Dim objStream As Stream
192            objStream = wrGETURL.GetResponse.GetResponseStream()
193            Dim objReader As New StreamReader(objStream)
194            xmlfile = objReader.ReadToEnd
195            Dim showlist As New XmlDocument
196            'Try
197            showlist.LoadXml(xmlfile)
198            Dim thisresult As XmlNode = Nothing
199            For Each thisresult In showlist("Data")
200
201                Select Case thisresult.Name
202                    Case "Series"
203                        Dim newshow As New possibleshowlist
204                        Dim mirrorselection As XmlNode = Nothing
205                        For Each mirrorselection In thisresult.ChildNodes
206                            Select Case mirrorselection.Name
207                                Case "SeriesName"
208                                    tvshowdetails = tvshowdetails & "<title>" & mirrorselection.InnerXml & "</title>"
209                                Case "ContentRating"
210                                    tvshowdetails = tvshowdetails & "<mpaa>" & mirrorselection.InnerXml & "</mpaa>"
211                                Case "FirstAired"
212                                    tvshowdetails = tvshowdetails & "<premiered>" & mirrorselection.InnerXml & "</premiered>"
213                                Case "Genre"
214                                    tvshowdetails = tvshowdetails & "<genre>" & mirrorselection.InnerXml & "</genre>"
215                                Case "IMDB_ID"
216                                    tvshowdetails = tvshowdetails & "<imdbid>" & mirrorselection.InnerXml & "</imdbid>"
217                                Case "Network"
218                                    tvshowdetails = tvshowdetails & "<studio>" & mirrorselection.InnerXml & "</studio>"
219                                Case "Overview"
220                                    tvshowdetails = tvshowdetails & "<plot>" & mirrorselection.InnerXml & "</plot>"
221                                Case "Rating"
222                                    tvshowdetails = tvshowdetails & "<rating>" & mirrorselection.InnerXml & "</rating>"
223                                Case "Runtime"
224                                    tvshowdetails = tvshowdetails & "<runtime>" & mirrorselection.InnerXml & "</runtime>"
225                                Case "banner"
226                                    tvshowdetails = tvshowdetails & "<banner>" & "http://thetvdb.com/banners/" & mirrorselection.InnerXml & "</banner>"
227                                Case "fanart"
228                                    tvshowdetails = tvshowdetails & "<fanart>" & "http://thetvdb.com/banners/" & mirrorselection.InnerXml & "</fanart>"
229                                Case "poster"
230                                    tvshowdetails = tvshowdetails & "<poster>" & "http://thetvdb.com/banners/" & mirrorselection.InnerXml & "</poster>"
231                            End Select
232                        Next
233                End Select
234            Next
235
236            tvshowdetails = tvshowdetails & "<episodeguideurl>" & episodeguideurl & "</episodeguideurl>"
237
238
239
240            mirrorsurl = "http://www.thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/actors.xml"
241            wrGETURL = WebRequest.Create(mirrorsurl)
242            Dim objStream2 As Stream
243            objStream2 = wrGETURL.GetResponse.GetResponseStream()
244            Dim objReader2 As New StreamReader(objStream2)
245            xmlfile = objReader2.ReadToEnd
246            Dim showlist2 As New XmlDocument
247            'Try
248            showlist2.LoadXml(xmlfile)
249            thisresult = Nothing
250            For Each thisresult In showlist2("Actors")
251
252                Select Case thisresult.Name
253                    Case "Actor"
254                        tvshowdetails = tvshowdetails & "<actor>"
255                        Dim newshow As New possibleshowlist
256                        Dim mirrorselection As XmlNode = Nothing
257                        For Each mirrorselection In thisresult.ChildNodes
258                            Select Case mirrorselection.Name
259                                Case "id"
260                                    tvshowdetails = tvshowdetails & "<actorid>" & mirrorselection.InnerXml & "</actorid>"
261                                Case "Image"
262                                    If mirrorselection.InnerXml <> Nothing Then
263                                        If mirrorselection.InnerXml <> "" Then
264                                            tvshowdetails = tvshowdetails & "<thumb>" & "http://thetvdb.com/banners/" & mirrorselection.InnerXml & "</thumb>"
265                                        End If
266                                    End If
267                                Case "Name"
268                                    tvshowdetails = tvshowdetails & "<name>" & mirrorselection.InnerXml & "</name>"
269                                Case "Role"
270                                        If mirrorselection.InnerXml <> Nothing Then
271                                            If mirrorselection.InnerXml <> "" Then
272                                                tvshowdetails = tvshowdetails & "<role>" & mirrorselection.InnerXml & "</role>"
273                                            End If
274                                        End If
275                            End Select
276                        Next
277                        tvshowdetails = tvshowdetails & "</actor>"
278                End Select
279            Next
280
281            mirrorsurl = "http://www.thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/actors.xml"
282            wrGETURL = WebRequest.Create(mirrorsurl)
283            Dim objStream3 As Stream
284            objStream3 = wrGETURL.GetResponse.GetResponseStream()
285            Dim objReader3 As New StreamReader(objStream3)
286            xmlfile = objReader3.ReadToEnd
287            Dim showlist3 As New XmlDocument
288            'Try
289            showlist3.LoadXml(xmlfile)
290            thisresult = Nothing
291            For Each thisresult In showlist3("Actors")
292
293                Select Case thisresult.Name
294                    Case "Actor"
295                        tvshowdetails = tvshowdetails & "<actor>"
296                        Dim newshow As New possibleshowlist
297                        Dim mirrorselection As XmlNode = Nothing
298                        For Each mirrorselection In thisresult.ChildNodes
299                            Select Case mirrorselection.Name
300                                Case "id"
301                                    tvshowdetails = tvshowdetails & "<actorid>" & mirrorselection.InnerXml & "</actorid>"
302                                Case "Image"
303                                    If mirrorselection.InnerXml <> Nothing Then
304                                        If mirrorselection.InnerXml <> "" Then
305                                            tvshowdetails = tvshowdetails & "<thumb>" & "http://thetvdb.com/banners/" & mirrorselection.InnerXml & "</thumb>"
306                                        End If
307                                    End If
308                                Case "Name"
309                                    tvshowdetails = tvshowdetails & "<name>" & mirrorselection.InnerXml & "</name>"
310                                Case "Role"
311                                    If mirrorselection.InnerXml <> Nothing Then
312                                        If mirrorselection.InnerXml <> "" Then
313                                            tvshowdetails = tvshowdetails & "<role>" & mirrorselection.InnerXml & "</role>"
314                                        End If
315                                    End If
316                            End Select
317                        Next
318                        tvshowdetails = tvshowdetails & "</actor>"
319                End Select
320            Next
321
322
323            tvshowdetails = tvshowdetails & "</fulltvshow>"
324
325            Return tvshowdetails
326        Catch
327            Return "!!!Error!!!"
328        Finally
329            Monitor.Exit(Me)
330        End Try
331
332
333    End Function
334
335
336    Public Function getepisode(ByVal tvdbid As String, ByVal sortorder As String, ByVal seriesno As String, ByVal episodeno As String, ByVal language As String)
337        Monitor.Enter(Me)
338        Dim episodestring As String = ""
339        Dim episodeurl As String = ""
340        Try
341            'http://thetvdb.com/api/6E82FED600783400/series/70726/default/1/1/en.xml
342
343            Dim xmlfile As String
344            Dim wrGETURL As WebRequest
345            If language.ToLower.IndexOf(".xml") = -1 Then
346                language = language & ".xml"
347            End If
348            episodeurl = "http://thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/" & sortorder & "/" & seriesno & "/" & episodeno & "/" & language
349            wrGETURL = WebRequest.Create(episodeurl)
350            Dim myProxy As New WebProxy("myproxy", 80)
351            myProxy.BypassProxyOnLocal = True
352            Dim objStream As Stream
353            objStream = wrGETURL.GetResponse.GetResponseStream()
354            Dim objReader As New StreamReader(objStream)
355            xmlfile = objReader.ReadToEnd
356            Dim episode As New XmlDocument
357
358            episode.LoadXml(xmlfile)
359
360            episodestring = "<episodedetails>"
361            episodestring = episodestring & "<url>" & episodeurl & "</url>"
362            Dim mirrorslist As New XmlDocument
363            'Try
364            mirrorslist.LoadXml(xmlfile)
365            Dim thisresult As XmlNode = Nothing
366            For Each thisresult In mirrorslist("Data")
367
368                Select Case thisresult.Name
369                    Case "Episode"
370                        Dim mirrorselection As XmlNode = Nothing
371                        For Each mirrorselection In thisresult.ChildNodes
372                            Select Case mirrorselection.Name
373                                Case "EpisodeName"
374                                    episodestring = episodestring & "<title>" & mirrorselection.InnerXml & "</title>"
375                                Case "FirstAired"
376                                    episodestring = episodestring & "<premiered>" & mirrorselection.InnerXml & "</premiered>"
377                                Case "GuestStars"
378                                    Dim tempstring As String = mirrorselection.InnerXml
379                                    Try
380                                        tempstring = tempstring.TrimStart("|")
381                                        tempstring = tempstring.TrimEnd("|")
382                                        Dim tvtempstring2 As String
383                                        Dim tvtempint As Integer
384                                        Dim a() As String
385                                        Dim j As Integer
386                                        tvtempstring2 = ""
387                                        a = tempstring.Split("|")
388                                        tvtempint = a.GetUpperBound(0)
389                                        tvtempstring2 = a(0)
390                                        If tvtempint >= 0 Then
391                                            For j = 0 To tvtempint
392                                                Try
393                                                    episodestring = episodestring & "<actor>" & "<name>" & a(j) & "</name></actor>"
394                                                Catch
395                                                End Try
396                                            Next
397                                        End If
398                                    Catch
399                                    End Try
400                                Case "Director"
401                                    Dim tempstring As String = mirrorselection.InnerXml
402                                    tempstring = tempstring.TrimStart("|")
403                                    tempstring = tempstring.TrimEnd("|")
404                                    episodestring = episodestring & "<director>" & tempstring & "</director>"
405                                Case "Writer"
406                                    Dim tempstring As String = mirrorselection.InnerXml
407                                    tempstring = tempstring.TrimStart("|")
408                                    tempstring = tempstring.TrimEnd("|")
409                                    episodestring = episodestring & "<credits>" & tempstring & "</credits>"
410                                Case "Overview"
411                                    episodestring = episodestring & "<plot>" & mirrorselection.InnerXml & "</plot>"
412                                Case "Rating"
413                                    episodestring = episodestring & "<rating>" & mirrorselection.InnerXml & "</rating>"
414                                Case "filename"
415                                    episodestring = episodestring & "<thumb>http://www.thetvdb.com/banners/" & mirrorselection.InnerXml & "</thumb>"
416                            End Select
417                        Next
418                End Select
419            Next
420            episodestring = episodestring & "</episodedetails>"
421            Return episodestring
422        Catch ex As Exception
423            Return "ERROR - <url>" & episodeurl & "</url>"
424        Finally
425            Monitor.Exit(Me)
426        End Try
427
428    End Function
429
430End Class