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