PageRenderTime 93ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/Forms/frmMovieFanart.vb

#
Visual Basic | 479 lines | 404 code | 69 blank | 6 comment | 0 complexity | 55592694e87bedfd260a6c840faaad10 MD5 | raw file
Possible License(s): GPL-2.0
  1. Imports System.Net
  2. Imports System.IO
  3. Imports System.Xml
  4. Public Class frmMovieFanart
  5. Dim WithEvents bigpicbox As PictureBox
  6. Dim bigpanel As Panel
  7. Dim WithEvents picboxes As PictureBox
  8. Dim WithEvents checkboxes As RadioButton
  9. Dim WithEvents labels As Label
  10. Dim WithEvents savebutton As Button
  11. Dim fanartpath As String = Form1.workingMovieDetails.fileinfo.fanartpath
  12. Dim fanartList As New List(Of str_ListOfPosters)
  13. Dim mainfanart As PictureBox
  14. Dim resolutionlbl As Label
  15. Private Sub zoomimage(ByVal sender As Object, ByVal e As EventArgs)
  16. Dim tempstring As String = sender.name
  17. Dim tempstring2 As String
  18. Dim tempint As Integer
  19. tempstring = tempstring.Replace("picture", "")
  20. tempint = Convert.ToDecimal(tempstring)
  21. tempstring2 = fanartList(tempint).hdposter
  22. Dim buffer(4000000) As Byte
  23. Dim size As Integer = 0
  24. Dim bytesRead As Integer = 0
  25. bigpanel = New Panel
  26. With bigpanel
  27. .Width = Me.Width
  28. .Height = Me.Height
  29. .BringToFront()
  30. .Dock = DockStyle.Fill
  31. End With
  32. bigpicbox = New PictureBox()
  33. With bigpicbox
  34. .Location = New Point(0, 0)
  35. .Width = bigpanel.Width
  36. .Height = bigpanel.Height
  37. .SizeMode = PictureBoxSizeMode.Zoom
  38. '.Image = sender.image
  39. .ImageLocation = tempstring2
  40. .Visible = True
  41. .BorderStyle = BorderStyle.Fixed3D
  42. AddHandler bigpicbox.DoubleClick, AddressOf closeimage
  43. .Dock = DockStyle.Fill
  44. End With
  45. Dim sizex As Integer = bigpicbox.Width
  46. Dim sizey As Integer = bigpicbox.Height
  47. Me.Controls.Add(bigpanel)
  48. bigpanel.BringToFront()
  49. Me.bigpanel.Controls.Add(bigpicbox)
  50. Me.Refresh()
  51. End Sub
  52. Private Sub closeimage()
  53. Me.Controls.Remove(bigpanel)
  54. bigpanel = Nothing
  55. Me.Controls.Remove(bigpicbox)
  56. bigpicbox = Nothing
  57. End Sub
  58. Private Sub bigpicbox_LoadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles bigpicbox.LoadCompleted
  59. Dim bigpanellabel As Label
  60. bigpanellabel = New Label
  61. With bigpanellabel
  62. .Location = New Point(20, 200)
  63. .Width = 150
  64. .Height = 50
  65. .Visible = True
  66. .Text = "Double Click Image To" & vbCrLf & "Return To Browser"
  67. ' .BringToFront()
  68. End With
  69. Me.bigpanel.Controls.Add(bigpanellabel)
  70. bigpanellabel.BringToFront()
  71. Application.DoEvents()
  72. If Not bigpicbox.Image Is Nothing And bigpicbox.Image.Width > 20 Then
  73. Dim sizey As Integer = bigpicbox.Image.Height
  74. Dim sizex As Integer = bigpicbox.Image.Width
  75. Dim tempstring As String
  76. tempstring = "Full Image Resolution :- " & sizex.ToString & " x " & sizey.ToString
  77. resolutionlbl = New Label
  78. With resolutionlbl
  79. .Location = New Point(311, 450)
  80. .Width = 180
  81. .Text = tempstring
  82. .BackColor = Color.Transparent
  83. End With
  84. Me.bigpanel.Controls.Add(resolutionlbl)
  85. resolutionlbl.BringToFront()
  86. Me.Refresh()
  87. Application.DoEvents()
  88. Dim tempstring2 As String = resolutionlbl.Text
  89. Else
  90. 'bigpicbox.ImageLocation = posterurls(rememberint + 1, 1)
  91. End If
  92. End Sub
  93. Private Sub moviefanart_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  94. Try
  95. Dim exists As Boolean = System.IO.File.Exists(fanartpath)
  96. If exists = True Then
  97. mainfanart = New PictureBox
  98. With mainfanart
  99. .Location = New Point(0, 0)
  100. .Width = 423
  101. .Height = 240
  102. .SizeMode = PictureBoxSizeMode.Zoom
  103. .Visible = True
  104. .BorderStyle = BorderStyle.Fixed3D
  105. End With
  106. mainfanart.Visible = True
  107. Dim OriginalImage As New Bitmap(fanartpath)
  108. Dim Image2 As New Bitmap(OriginalImage)
  109. mainfanart.Image = Image2
  110. OriginalImage.Dispose()
  111. Me.Panel1.Controls.Add(mainfanart)
  112. Label2.Visible = False
  113. Else
  114. mainfanart = New PictureBox
  115. With mainfanart
  116. .Location = New Point(0, 0)
  117. .Width = 423
  118. .Height = 240
  119. .SizeMode = PictureBoxSizeMode.Zoom
  120. .Visible = False
  121. .BorderStyle = BorderStyle.Fixed3D
  122. End With
  123. Me.Panel1.Controls.Add(mainfanart)
  124. Label2.Visible = True
  125. End If
  126. Try
  127. Dim tmdbposterscraper As New tmdb_posters.Class1
  128. fanartList.Clear()
  129. Dim tmdbimageresults As String = tmdbposterscraper.gettmdbposters_newapi(Form1.workingMovieDetails.fullmoviebody.imdbid)
  130. Dim bannerslist As New XmlDocument
  131. bannerslist.LoadXml(tmdbimageresults)
  132. Dim thisresult As XmlNode = Nothing
  133. For Each item In bannerslist("tmdb_posterlist")
  134. Select Case item.name
  135. Case "fanart"
  136. Dim newfanart As New str_ListOfPosters(True)
  137. For Each backdrop In item
  138. If backdrop.childnodes(0).innertext = "original" Then
  139. newfanart.hdposter = backdrop.childnodes(1).innertext
  140. newfanart.hdwidth = backdrop.childnodes(2).innertext
  141. newfanart.hdheight = backdrop.childnodes(3).innertext
  142. End If
  143. If backdrop.childnodes(0).innertext = "poster" Then
  144. newfanart.ldposter = backdrop.childnodes(1).innertext
  145. newfanart.ldwidth = backdrop.childnodes(2).innertext
  146. newfanart.ldheight = backdrop.childnodes(3).innertext
  147. End If
  148. If newfanart.hdposter <> Nothing And newfanart.ldposter <> Nothing Then
  149. If newfanart.hdposter <> "" And newfanart.ldposter <> "" Then
  150. If newfanart.hdposter.IndexOf("http") <> -1 And newfanart.ldposter.IndexOf("http") <> -1 Then
  151. If newfanart.hdposter.IndexOf(".jpg") <> -1 Or newfanart.hdposter.IndexOf(".png") <> -1 Then
  152. If newfanart.ldposter.IndexOf(".jpg") <> -1 Or newfanart.ldposter.IndexOf(".png") <> -1 Then
  153. fanartList.Add(newfanart)
  154. Exit For
  155. End If
  156. End If
  157. End If
  158. End If
  159. End If
  160. Next
  161. End Select
  162. Next
  163. Catch ex As Exception
  164. #If SilentErrorScream Then
  165. Throw ex
  166. #End If
  167. End Try
  168. If fanartList.Count > 0 Then
  169. Dim location As Integer = 0
  170. Dim itemcounter As Integer = 0
  171. For Each item In fanartList
  172. picboxes() = New PictureBox()
  173. With picboxes
  174. .Location = New Point(location, 0)
  175. If fanartList.Count > 2 Then
  176. .Width = 326
  177. .Height = 185
  178. Else
  179. .Width = 353
  180. .Height = 200
  181. End If
  182. .SizeMode = PictureBoxSizeMode.Zoom
  183. .ImageLocation = item.ldposter
  184. .Visible = True
  185. .BorderStyle = BorderStyle.Fixed3D
  186. .Name = "picture" & itemcounter.ToString
  187. AddHandler picboxes.DoubleClick, AddressOf zoomimage
  188. End With
  189. checkboxes() = New RadioButton()
  190. With checkboxes
  191. If fanartList.Count > 2 Then
  192. .Location = New Point(location + 150, 183)
  193. Else
  194. .Location = New Point(location + 180, 198)
  195. End If
  196. .Name = "checkbox" & itemcounter.ToString
  197. .SendToBack()
  198. End With
  199. itemcounter += 1
  200. location += 325
  201. Me.Panel2.Controls.Add(picboxes())
  202. Me.Panel2.Controls.Add(checkboxes())
  203. Next
  204. Else
  205. Dim mainlabel2 As Label
  206. mainlabel2 = New Label
  207. With mainlabel2
  208. .Location = New Point(0, 100)
  209. .Width = 700
  210. .Height = 100
  211. .Font = New System.Drawing.Font("Arial", 15, FontStyle.Bold)
  212. .Text = "No Fanart Was Found At www.themoviedb.org For This Movie"
  213. End With
  214. Me.Panel2.Controls.Add(mainlabel2)
  215. End If
  216. Catch ex As Exception
  217. ExceptionHandler.LogError(ex)
  218. End Try
  219. End Sub
  220. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  221. Try
  222. Label2.Text = "Please Wait, Trying to Download Fanart"
  223. Me.Refresh()
  224. Application.DoEvents()
  225. Dim tempstring As String = String.Empty
  226. Dim tempint As Integer
  227. Dim tempstring2 As String = String.Empty
  228. Dim allok As Boolean = False
  229. For Each button As Control In Me.Panel2.Controls
  230. If button.Name.IndexOf("checkbox") <> -1 Then
  231. Dim b1 As RadioButton = CType(button, RadioButton)
  232. If b1.Checked = True Then
  233. tempstring = b1.Name
  234. tempstring = tempstring.Replace("checkbox", "")
  235. tempint = Convert.ToDecimal(tempstring)
  236. tempstring2 = fanartList(tempint).hdposter
  237. allok = True
  238. Exit For
  239. End If
  240. End If
  241. Next
  242. If allok = False Then
  243. MsgBox("No Fanart Is Selected")
  244. Else
  245. Try
  246. Panel1.Controls.Remove(Label1)
  247. Dim buffer(4000000) As Byte
  248. Dim size As Integer = 0
  249. Dim bytesRead As Integer = 0
  250. Dim fanartthumburl As String = tempstring2
  251. Dim req As HttpWebRequest = WebRequest.Create(fanartthumburl)
  252. Dim res As HttpWebResponse = req.GetResponse()
  253. Dim contents As Stream = res.GetResponseStream()
  254. Dim bmp As New Bitmap(contents)
  255. Dim bytesToRead As Integer = CInt(buffer.Length)
  256. While bytesToRead > 0
  257. size = contents.Read(buffer, bytesRead, bytesToRead)
  258. If size = 0 Then Exit While
  259. bytesToRead -= size
  260. bytesRead += size
  261. End While
  262. If Preferences.resizefanart = 1 Then
  263. Try
  264. Dim tempbitmap As Bitmap = bmp
  265. tempbitmap.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  266. Catch ex As Exception
  267. tempstring = ex.Message.ToString
  268. End Try
  269. ElseIf Preferences.resizefanart = 2 Then
  270. If bmp.Width > 1280 Or bmp.Height > 720 Then
  271. Dim bm_source As New Bitmap(bmp)
  272. Dim bm_dest As New Bitmap(1280, 720)
  273. Dim gr As Graphics = Graphics.FromImage(bm_dest)
  274. gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear
  275. gr.DrawImage(bm_source, 0, 0, 1280 - 1, 720 - 1)
  276. Dim tempbitmap As Bitmap = bm_dest
  277. tempbitmap.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  278. Else
  279. Threading.Thread.Sleep(30)
  280. bmp.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  281. End If
  282. ElseIf Preferences.resizefanart = 3 Then
  283. If bmp.Width > 960 Or bmp.Height > 540 Then
  284. Dim bm_source As New Bitmap(bmp)
  285. Dim bm_dest As New Bitmap(960, 540)
  286. Dim gr As Graphics = Graphics.FromImage(bm_dest)
  287. gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear
  288. gr.DrawImage(bm_source, 0, 0, 960 - 1, 540 - 1)
  289. Dim tempbitmap As Bitmap = bm_dest
  290. tempbitmap.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  291. Else
  292. Threading.Thread.Sleep(30)
  293. bmp.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  294. End If
  295. End If
  296. Dim exists As Boolean = System.IO.File.Exists(fanartpath)
  297. If exists = True Then
  298. 'mainfanart = New PictureBox
  299. Dim OriginalImage As New Bitmap(fanartpath)
  300. Dim Image2 As New Bitmap(OriginalImage)
  301. OriginalImage.Dispose()
  302. With mainfanart
  303. .Visible = True
  304. .Location = New Point(0, 0)
  305. .Width = 423
  306. .Height = 240
  307. .SizeMode = PictureBoxSizeMode.Zoom
  308. .Image = Image2
  309. .Visible = True
  310. .BorderStyle = BorderStyle.Fixed3D
  311. .BringToFront()
  312. End With
  313. Me.Panel1.Controls.Add(mainfanart)
  314. Label2.Visible = False
  315. Me.Close()
  316. Else
  317. mainfanart.Visible = False
  318. Label2.Text = "No Local Fanart Is Available"
  319. Label2.Visible = True
  320. End If
  321. Catch ex As WebException
  322. MsgBox(ex.Message)
  323. End Try
  324. End If
  325. Catch ex As Exception
  326. ExceptionHandler.LogError(ex)
  327. End Try
  328. End Sub
  329. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  330. Try
  331. Panel3.Visible = True
  332. Catch ex As Exception
  333. ExceptionHandler.LogError(ex)
  334. End Try
  335. End Sub
  336. Private Sub btncancelgetthumburl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancelgetthumburl.Click
  337. Try
  338. Panel3.Visible = False
  339. Catch ex As Exception
  340. ExceptionHandler.LogError(ex)
  341. End Try
  342. End Sub
  343. Private Sub btnthumbbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthumbbrowse.Click
  344. Try
  345. 'browse pc
  346. openFD.InitialDirectory = Form1.workingMovieDetails.fileinfo.fullpathandfilename.Replace(IO.Path.GetFileName(Form1.workingMovieDetails.fileinfo.fullpathandfilename), "")
  347. openFD.Title = "Select a jpeg image File"
  348. openFD.FileName = ""
  349. openFD.Filter = "Media Companion Image Files|*.jpg;*.tbn|All Files|*.*"
  350. openFD.FilterIndex = 0
  351. openFD.ShowDialog()
  352. TextBox5.Text = openFD.FileName
  353. Catch ex As Exception
  354. ExceptionHandler.LogError(ex)
  355. End Try
  356. End Sub
  357. Private Sub btngetthumb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngetthumb.Click
  358. Try
  359. 'set thumb
  360. Dim MyWebClient As New System.Net.WebClient
  361. Try
  362. Dim ImageInBytes() As Byte = MyWebClient.DownloadData(TextBox5.Text)
  363. Dim ImageStream As New IO.MemoryStream(ImageInBytes)
  364. mainfanart.Image = New System.Drawing.Bitmap(ImageStream)
  365. Dim tempstring As String
  366. Dim bmp As New Bitmap(ImageStream)
  367. If Preferences.resizefanart = 1 Then
  368. Try
  369. Dim tempbitmap As Bitmap = bmp
  370. tempbitmap.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  371. Catch ex As Exception
  372. tempstring = ex.Message.ToString
  373. End Try
  374. ElseIf Preferences.resizefanart = 2 Then
  375. If bmp.Width > 1280 Or bmp.Height > 720 Then
  376. Dim bm_source As New Bitmap(bmp)
  377. Dim bm_dest As New Bitmap(1280, 720)
  378. Dim gr As Graphics = Graphics.FromImage(bm_dest)
  379. gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear
  380. gr.DrawImage(bm_source, 0, 0, 1280 - 1, 720 - 1)
  381. Dim tempbitmap As Bitmap = bm_dest
  382. tempbitmap.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  383. Else
  384. Threading.Thread.Sleep(30)
  385. bmp.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  386. End If
  387. ElseIf Preferences.resizefanart = 3 Then
  388. If bmp.Width > 960 Or bmp.Height > 540 Then
  389. Dim bm_source As New Bitmap(bmp)
  390. Dim bm_dest As New Bitmap(960, 540)
  391. Dim gr As Graphics = Graphics.FromImage(bm_dest)
  392. gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear
  393. gr.DrawImage(bm_source, 0, 0, 960 - 1, 540 - 1)
  394. Dim tempbitmap As Bitmap = bm_dest
  395. tempbitmap.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  396. Else
  397. Threading.Thread.Sleep(30)
  398. bmp.Save(fanartpath, Imaging.ImageFormat.Jpeg)
  399. End If
  400. End If
  401. Me.Close()
  402. Catch ex As Exception
  403. MsgBox("Unable To Download Image")
  404. End Try
  405. Panel3.Visible = False
  406. Catch ex As Exception
  407. ExceptionHandler.LogError(ex)
  408. End Try
  409. End Sub
  410. End Class