PageRenderTime 163ms CodeModel.GetById 101ms app.highlight 57ms RepoModel.GetById 1ms app.codeStats 1ms

/Forms/frmMovieFanart.vb

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