PageRenderTime 95ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/Forms/Form1/Form1.Tv.vb

#
Visual Basic | 5202 lines | 4859 code | 206 blank | 137 comment | 11 complexity | 106a7c2f120c9004f75190cd6156e3c1 MD5 | raw file
Possible License(s): GPL-2.0
  1. Imports System.Net
  2. Imports System.IO
  3. Imports System.Text.RegularExpressions
  4. Imports System.Text
  5. Imports Media_Companion.WorkingWithNfoFiles
  6. Imports System.Xml
  7. Imports Media_Companion
  8. Imports Media_Companion.Pref
  9. Imports System.Linq
  10. Partial Public Class Form1
  11. Dim newEpisodeList As New List(Of TvEpisode)
  12. Public languageList As New List(Of Tvdb.Language)
  13. Dim listOfShows As New List(Of str_PossibleShowList)
  14. Dim tvdbposterlist As New List(Of TvBanners)
  15. Dim imdbposterlist As New List(Of TvBanners)
  16. Dim tvdbmode As Boolean = False
  17. Dim usedlist As New List(Of TvBanners)
  18. Dim tvobjects As New List(Of String)
  19. #Region "Tv Treeview Routines"
  20. Public Sub tv_ViewReset()
  21. btn_SaveTvShowOrEpisode.Enabled = True
  22. Tv_TreeViewContext_RefreshShow.Enabled = False
  23. Tv_TreeViewContext_RefreshShow.Visible = False
  24. Tv_TreeViewContext_ShowMissEps.Enabled = False
  25. Tv_TreeViewContext_ShowMissEps.Visible = False
  26. Tv_TreeViewContext_DispByAiredDate.Enabled = False
  27. Tv_TreeViewContext_DispByAiredDate.Visible = False
  28. Tv_TreeViewContext_SearchNewEp.Enabled = False
  29. Tv_TreeViewContext_SearchNewEp.Visible = False
  30. Tv_TreeViewContext_FindMissArt.Enabled = False
  31. Tv_TreeViewContext_FindMissArt.Visible = False
  32. Tv_TreeViewContext_ViewNfo.Enabled = False
  33. ExpandSelectedShowToolStripMenuItem.Enabled = False
  34. CollapseSelectedShowToolStripMenuItem.Enabled = False
  35. ExpandAllToolStripMenuItem.Enabled = False
  36. CollapseAllToolStripMenuItem.Enabled = False
  37. Tv_TreeViewContext_ReloadFromCache.Enabled = False
  38. Tv_TreeViewContext_OpenFolder.Enabled = False
  39. tb_ShPremiered.Text = ""
  40. tb_ShGenre.Text = ""
  41. tb_ShTvdbId.Text = ""
  42. tb_ShImdbId.Text = ""
  43. tb_ShRating.Text = ""
  44. tb_ShVotes.Text = ""
  45. tb_ShCert.Text = ""
  46. tb_ShRunTime.Text = ""
  47. tb_ShStudio.Text = ""
  48. cbTvActorRole.Items.Clear()
  49. cbTvActorRole.Text = ""
  50. cbTvActor.Items.Clear()
  51. cbTvActor.Text = ""
  52. PictureBox6.Image = Nothing
  53. tvdbposterlist.Clear()
  54. PictureBox6.Image = Nothing
  55. tv_PictureBoxLeft.Image = Nothing
  56. tv_PictureBoxRight.Image = Nothing
  57. tv_PictureBoxBottom.Image = Nothing
  58. tb_ShPremiered.Text = ""
  59. tb_ShGenre.Text = ""
  60. tb_ShTvdbId.Text = ""
  61. tb_ShImdbId.Text = ""
  62. tb_ShRating.Text = ""
  63. tb_ShVotes.Text = ""
  64. tb_ShCert.Text = ""
  65. tb_ShRunTime.Text = ""
  66. tb_ShStudio.Text = ""
  67. cbTvActorRole.Items.Clear()
  68. cbTvActorRole.Text = ""
  69. tb_ShPlot.Text = ""
  70. cbTvActor.Items.Clear()
  71. cbTvActor.Text = ""
  72. tb_Sh_Ep_Title.Text = ""
  73. tb_ShPremiered.Text = ""
  74. tb_ShGenre.Text = ""
  75. tb_ShTvdbId.Text = ""
  76. tb_ShImdbId.Text = ""
  77. tb_ShRating.Text = ""
  78. tb_ShVotes.Text = ""
  79. tb_ShCert.Text = ""
  80. tb_ShRunTime.Text = ""
  81. tb_ShStudio.Text = ""
  82. cbTvActorRole.Items.Clear()
  83. cbTvActorRole.Text = ""
  84. tb_ShPlot.Text = ""
  85. cbTvActor.Items.Clear()
  86. cbTvActor.Text = ""
  87. cbTvActor.Items.Clear()
  88. cbTvActor.Text = ""
  89. For i = Panel13.Controls.Count - 1 To 0 Step -1
  90. Panel13.Controls.RemoveAt(i)
  91. Next
  92. End Sub
  93. Private Sub TvTreeview_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TvTreeview.AfterSelect
  94. TvTreeview_AfterSelect_Do() 'moved this to seperate sub so we can also call this from other locations.
  95. End Sub
  96. Private Sub TvTreeview_AfterSelect_Do()
  97. Try
  98. 'chooses which sub is run to load the relavent tv data to the screen
  99. 'note: context menu items are set during TvTreeView_MouseUp event because we only need to update if right click is done which we check in the mouseup sub
  100. 'mouseup sub selects the node underneath the mouse & then this runs since its an event 'AfterSelect'
  101. If TvTreeview.SelectedNode Is Nothing Then Exit Sub
  102. If TypeOf TvTreeview.SelectedNode.Tag Is Media_Companion.TvShow Then
  103. tv_ShowLoad(TvTreeview.SelectedNode.Tag)
  104. ElseIf TypeOf TvTreeview.SelectedNode.Tag Is Media_Companion.TvSeason Then
  105. tv_SeasonSelected(TvTreeview.SelectedNode.Tag)
  106. ElseIf TypeOf TvTreeview.SelectedNode.Tag Is Media_Companion.TvEpisode Then
  107. tv_EpisodeSelected(TvTreeview.SelectedNode.Tag)
  108. Else
  109. MsgBox("None")
  110. End If
  111. 'tv_SplitContainerAutoPosition() 'auto set container splits....after we have loaded data & pictures....
  112. Catch ex As Exception
  113. ExceptionHandler.LogError(ex)
  114. End Try
  115. End Sub
  116. Private Sub TvTreeview_DragDrop(sender As Object, e As DragEventArgs) Handles TvTreeview.DragDrop
  117. Dim files() As String
  118. files = e.Data.GetData(DataFormats.FileDrop)
  119. For f = 0 To UBound(files)
  120. If IO.Directory.Exists(files(f)) Then
  121. If files(f).ToLower.Contains(".actors") Or files(f).ToLower.Contains("season") Then Continue For
  122. For each fol In Pref.tvRootFolders
  123. If fol.rpath = files(f) Then Continue For
  124. If files(f).Contains(fol.rpath) AndAlso Not fol.selected Then
  125. Dim msg As String = "The series dropped is in a root folder that has been unselected"
  126. msg &= "To avoid catastrophic failure, please re-select"
  127. msg &= "root folder: " & fol.rpath
  128. msg &= "and attempt again"
  129. MsgBox (msg)
  130. Continue For
  131. End If
  132. Next
  133. 'If Pref.tvRootFolders.Contains(files(f)) Then Continue For
  134. Dim di As New IO.DirectoryInfo(files(f))
  135. If Pref.tvFolders.Contains(files(f)) Then Continue For
  136. Dim skip As Boolean = False
  137. For Each item In droppedItems
  138. If item = files(f) Then
  139. skip = True
  140. Exit For
  141. End If
  142. Next
  143. If Not skip Then droppedItems.Add(files(f))
  144. End If
  145. Next
  146. If droppedItems.Count < 1 Then Exit Sub
  147. Dim droppedmsg As String = "You have dropped the following folders onto TV," &vbCrLf & "Are you sure you wish to add these as TvShows?" & vbCrLf
  148. For Each item In droppedItems
  149. droppedmsg &= item & vbcrlf
  150. Next
  151. Dim x = MsgBox(droppedmsg, MsgBoxStyle.YesNo)
  152. If x = MsgBoxResult.No Then
  153. droppedItems.Clear()
  154. Exit Sub
  155. End If
  156. For Each item In droppedItems
  157. Pref.tvFolders.add(item)
  158. newTvFolders.Add(item)
  159. Next
  160. droppedItems.Clear()
  161. Pref.ConfigSave()
  162. tv_ShowScrape()
  163. End Sub
  164. Private Sub TvTreeview_DragEnter(sender As Object, e As DragEventArgs) Handles TvTreeview.DragEnter
  165. Try
  166. e.Effect = DragDropEffects.Copy
  167. Catch ex As Exception
  168. ExceptionHandler.LogError(ex)
  169. End Try
  170. End Sub
  171. Private Sub TvTreeviewRebuild()
  172. TvTreeview.BeginUpdate()
  173. Try
  174. Dim shcount As Integer = 0
  175. Dim epcount As Integer = 0
  176. TvTreeview.Nodes.Clear() 'clear the treeview of old data
  177. ''Dirty work around until TvShows is repalced with TvCache.Shows universally
  178. For Each TvShow As Media_Companion.TvShow In Cache.TvCache.Shows
  179. If Not String.IsNullOrEmpty(TvShow.Hidden.Value) AndAlso TvShow.Hidden.Value = True Then Continue For
  180. 'TvShow.UpdateTreenode()
  181. shcount += 1
  182. epcount += TvShow.Episodes.Count
  183. TvTreeview.Nodes.Add(TvShow.ShowNode)
  184. TvShow.UpdateTreenode()
  185. Next
  186. If rbTvListAll.Checked Then TvTreeview.BackColor = Color.white
  187. If rbTvListEnded.Checked Then TvTreeview.BackColor = Color.lightpink
  188. If rbTvListContinuing.Checked Then TvTreeview.BackColor = Color.LightSeaGreen
  189. If rbTvListUnKnown.Checked Then TvTreeview.BackColor = Color.LightYellow
  190. TextBox_TotTVShowCount.Text = shcount.ToString 'Cache.TvCache.Shows.Count
  191. TextBox_TotEpisodeCount.Text = epcount.ToString 'Cache.TvCache.Episodes.Count
  192. TvTreeview.Sort()
  193. Finally
  194. TvTreeview.EndUpdate()
  195. End Try
  196. End Sub
  197. Private Sub Tv_TreeViewContextMenuItemsEnable() 'enable/disable right click context menu items depending on if its show/season/episode
  198. ' 'called from tv_treeview mouseup event where we check for a right click
  199. If TvTreeview.SelectedNode Is Nothing Then Return
  200. Dim WorkingTvShow As TvShow = tv_ShowSelectedCurrently(TvTreeview) 'set WORKINGTVSHOW to show obj irrelavent if we have selected show/season/episode
  201. Dim showtitle As String = WorkingTvShow.Title.Value 'set our show title
  202. 'now we set the items that have variable text in the context menu using the 'show' text set above
  203. Tv_TreeViewContext_ShowTitle.BackColor = Color.Honeydew 'SK - same color as the refresh tv show splash - comments required to see if it works or not....
  204. If TypeOf TvTreeview.SelectedNode.Tag Is Media_Companion.TvShow Then
  205. Tv_TreeViewContext_ShowTitle.Text = "'" & showtitle & "'"
  206. Tv_TreeViewContext_ShowTitle.Font = New Font("Arial", 10, FontStyle.Bold)
  207. Tv_TreeViewContext_Play_Episode.Enabled = False
  208. Tv_TreeViewContext_ViewNfo.Text = "View TVShow .nfo"
  209. Tv_TreeViewContext_RescrapeShowOrEpisode.Text = "Rescrape TVShow"
  210. Tv_TreeViewContext_WatchedShowOrEpisode.Text = "Mark This Show as Watched"
  211. Tv_TreeViewContext_UnWatchedShowOrEpisode.Text = "Mark This Show as UnWatched"
  212. Tv_TreeViewContext_OpenFolder.Enabled = True
  213. Tv_TreeViewContext_ViewNfo.Enabled = True
  214. Tv_TreeViewContext_RescrapeShowOrEpisode.Enabled = True
  215. Tv_TreeViewContext_WatchedShowOrEpisode.Enabled = True
  216. Tv_TreeViewContext_UnWatchedShowOrEpisode.Enabled = True
  217. Tv_TreeViewContext_RescrapeWizard.Enabled = True
  218. Tv_TreeViewContext_FindMissArt.Enabled = True
  219. Tv_TreeViewContext_RefreshShow.Enabled = True
  220. Tv_TreeViewContext_RefreshShow.Visible = True
  221. Tv_TreeViewContext_MissingEpThumbs.Enabled = True
  222. Tv_TreeViewContext_MissingEpThumbs.Visible = True
  223. Tv_TreeViewContext_ReloadFromCache.Enabled = True
  224. Tv_TreeViewContext_RenameEp.Enabled = rbTvListAll.Checked 'Only show if Treeview set to 'List All'
  225. Tv_TreeViewContext_ShowMissEps.Enabled = True
  226. Tv_TreeViewContext_DispByAiredDate.Enabled = True
  227. tsmiTvDelShowNfoArt.Enabled = True
  228. tsmiTvDelShowEpNfoArt.Enabled = True
  229. ElseIf TypeOf TvTreeview.SelectedNode.Tag Is Media_Companion.TvSeason Then
  230. Tv_TreeViewContext_ShowTitle.Text = "'" & showtitle & "' - " & tv_SeasonSelectedCurrently(TvTreeview).SeasonLabel
  231. Tv_TreeViewContext_ShowTitle.Font = New Font("Arial", 10, FontStyle.Bold)
  232. Tv_TreeViewContext_Play_Episode.Enabled = False
  233. Tv_TreeViewContext_ViewNfo.Text = "View Season .nfo"
  234. Tv_TreeViewContext_RescrapeShowOrEpisode.Text = "Rescrape Season"
  235. Tv_TreeViewContext_WatchedShowOrEpisode.Text = "Mark This Season as Watched"
  236. Tv_TreeViewContext_UnWatchedShowOrEpisode.Text = "Mark This Season as UnWatched"
  237. Tv_TreeViewContext_OpenFolder.Enabled = True
  238. Tv_TreeViewContext_ViewNfo.Enabled = False
  239. Tv_TreeViewContext_RescrapeShowOrEpisode.Enabled = False
  240. Tv_TreeViewContext_WatchedShowOrEpisode.Enabled = True
  241. Tv_TreeViewContext_UnWatchedShowOrEpisode.Enabled = True
  242. Tv_TreeViewContext_RescrapeWizard.Enabled = False
  243. Tv_TreeViewContext_FindMissArt.Enabled = False
  244. Tv_TreeViewContext_RefreshShow.Enabled = False
  245. Tv_TreeViewContext_RefreshShow.Visible = False
  246. Tv_TreeViewContext_MissingEpThumbs.Enabled = True
  247. Tv_TreeViewContext_MissingEpThumbs.Visible = True
  248. Tv_TreeViewContext_ReloadFromCache.Enabled = False
  249. Tv_TreeViewContext_RenameEp.Enabled = rbTvListAll.Checked 'Only show if Treeview set to 'List All'
  250. Tv_TreeViewContext_ShowMissEps.Enabled = True
  251. Tv_TreeViewContext_DispByAiredDate.Enabled = True
  252. tsmiTvDelShowNfoArt.Enabled = False
  253. tsmiTvDelShowEpNfoArt.Enabled = False
  254. ElseIf TypeOf TvTreeview.SelectedNode.Tag Is Media_Companion.TvEpisode Then
  255. Tv_TreeViewContext_ShowTitle.Text = "'" & showtitle & "' - S" & Utilities.PadNumber(ep_SelectedCurrently(TvTreeview).Season.Value, 2) & "E" & Utilities.PadNumber(ep_SelectedCurrently(TvTreeview).Episode.Value, 2) & " '" & ep_SelectedCurrently(TvTreeview).Title.Value & "'"
  256. Tv_TreeViewContext_ShowTitle.Font = New Font("Arial", 10, FontStyle.Bold)
  257. Tv_TreeViewContext_Play_Episode.Enabled = Not DirectCast(TvTreeview.SelectedNode.Tag, Media_Companion.TvEpisode).Ismissing
  258. Tv_TreeViewContext_ViewNfo.Text = "View Episode .nfo"
  259. Tv_TreeViewContext_RescrapeShowOrEpisode.Text = "Rescrape Episode"
  260. Tv_TreeViewContext_WatchedShowOrEpisode.Text = "Mark Episode as Watched"
  261. Tv_TreeViewContext_UnWatchedShowOrEpisode.Text = "Mark Episode as UnWatched"
  262. Tv_TreeViewContext_OpenFolder.Enabled = True
  263. Tv_TreeViewContext_ViewNfo.Enabled = True
  264. Tv_TreeViewContext_RescrapeShowOrEpisode.Enabled = Not DirectCast(TvTreeview.SelectedNode.Tag, Media_Companion.TvEpisode).Ismissing
  265. Tv_TreeViewContext_WatchedShowOrEpisode.Enabled = True
  266. Tv_TreeViewContext_UnWatchedShowOrEpisode.Enabled = True
  267. Tv_TreeViewContext_RescrapeWizard.Enabled = False
  268. Tv_TreeViewContext_FindMissArt.Enabled = False
  269. Tv_TreeViewContext_RefreshShow.Enabled = False
  270. Tv_TreeViewContext_RefreshShow.Visible = False
  271. Tv_TreeViewContext_MissingEpThumbs.Enabled = False
  272. Tv_TreeViewContext_MissingEpThumbs.Visible = False
  273. Tv_TreeViewContext_ReloadFromCache.Enabled = False
  274. Tv_TreeViewContext_RenameEp.Enabled = Not DirectCast(TvTreeview.SelectedNode.Tag, Media_Companion.TvEpisode).Ismissing
  275. Tv_TreeViewContext_ShowMissEps.Enabled = True
  276. Tv_TreeViewContext_DispByAiredDate.Enabled = True
  277. tsmiTvDelShowNfoArt.Enabled = False
  278. tsmiTvDelShowEpNfoArt.Enabled = False
  279. Else
  280. MsgBox("None")
  281. End If
  282. 'these are the four items at the bottom of the menu to control Expand/Colapse the tv_treeview (always shown)
  283. ExpandSelectedShowToolStripMenuItem.Enabled = True
  284. ExpandAllToolStripMenuItem.Enabled = True
  285. CollapseAllToolStripMenuItem.Enabled = True
  286. CollapseSelectedShowToolStripMenuItem.Enabled = True
  287. End Sub
  288. #End Region
  289. Sub tv_Rescrape_Show(ByVal WorkingTvShow)
  290. Dim tempint As Integer = 0
  291. Dim tempstring As String = ""
  292. tempint = MessageBox.Show("Rescraping the TV Show will Overwrite all the current details" & vbCrLf & "Do you wish to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
  293. If tempint = DialogResult.No Then
  294. Exit Sub
  295. End If
  296. Dim messbox As frmMessageBox = New frmMessageBox("The Selected TV Show is being Rescraped", "", "Please Wait")
  297. System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
  298. messbox.Show()
  299. messbox.Refresh()
  300. Application.DoEvents()
  301. Dim selectedLang As String = WorkingTvShow.Language.Value
  302. If selectedLang = "" Then selectedLang = "en"
  303. If Pref.tvshow_useXBMC_Scraper = True Then
  304. Dim TVShowNFOContent As String = XBMCScrape_TVShow_General_Info("metadata.tvdb.com", WorkingTvShow.TvdbId.Value, selectedLang, WorkingTvShow.NfoFilePath)
  305. If TVShowNFOContent <> "error" Then CreateMovieNfo(WorkingTvShow.NfoFilePath, TVShowNFOContent)
  306. Dim newshow As TvShow = nfoFunction.tvshow_NfoLoad(WorkingTvShow.NfoFilePath)
  307. newshow.ListActors.Clear()
  308. If Pref.TvdbActorScrape = 0 Or Pref.TvdbActorScrape = 3 Or NewShow.ImdbId.Value = Nothing Then
  309. TvGetActorTvdb(NewShow)
  310. ElseIf (Pref.TvdbActorScrape = 1 Or Pref.TvdbActorScrape = 2) And NewShow.ImdbId.Value <> Nothing Then
  311. TvGetActorImdb(NewShow)
  312. End If
  313. If Pref.tvdbIMDbRating Then
  314. Dim rating As String = ""
  315. Dim votes As String = ""
  316. If ep_getIMDbRating(newshow.ImdbId.Value, rating, votes) Then
  317. newshow.Rating.Value = rating
  318. newshow.Votes.Value = votes
  319. End If
  320. End If
  321. nfoFunction.tvshow_NfoSave(newshow, True)
  322. Call tv_ShowLoad(WorkingTvShow)
  323. Else
  324. For Each episode In WorkingTvShow.Episodes
  325. If Pref.displayMissingEpisodes AndAlso episode.IsMissing = True Then
  326. Cache.TvCache.Remove(episode)
  327. Else
  328. Cache.TvCache.Remove(episode)
  329. End If
  330. Next
  331. Cache.TvCache.Remove(WorkingTvShow)
  332. newTvFolders.Add(WorkingTvShow.FolderPath.Substring(0, WorkingTvShow.FolderPath.LastIndexOf("\")))
  333. Dim args As TvdbArgs = New TvdbArgs(WorkingTvShow.TvdbId.Value, selectedLang)
  334. bckgrnd_tvshowscraper.RunWorkerAsync(args)
  335. While bckgrnd_tvshowscraper.IsBusy
  336. Application.DoEvents()
  337. End While
  338. End If
  339. messbox.Close()
  340. TabControl3.SelectedIndex = 0
  341. End Sub
  342. Private Sub tv_ShowLoad(ByVal Show As Media_Companion.TvShow)
  343. Show.ListActors.Clear()
  344. 'Dim ShowTemp As TvShow = nfoFunction.tvshow_NfoLoad(Show.NfoFilePath)
  345. Show.Load()
  346. Show = nfoFunction.tvshow_NfoLoad(Show.NfoFilePath) '.Load()
  347. 'Show.UpdateTreenode()
  348. 'Fix episodeguide tag
  349. Dim lang As String = Show.EpisodeGuideUrl.Value
  350. If String.IsNullOrEmpty(lang) Then
  351. lang = "en"
  352. Else
  353. lang = lang.Substring((lang.LastIndexOf("/")+1)).Replace(".zip","")
  354. End If
  355. If Not Show.TvdbId.Value = "" Then
  356. Show.EpisodeGuideUrl.Value = ""
  357. Show.Url.Value = URLs.EpisodeGuide(Show.TvdbId.Value, lang) 'Show.Language.Value)
  358. Show.Url.Node.SetAttributeValue("cache", Show.TvdbId.Value)
  359. End If
  360. 'end fix
  361. Dim hg As New IO.DirectoryInfo(Show.FolderPath)
  362. If Not hg.Exists Then
  363. tb_ShPlot.Text = "Unable to find folder: " & Show.FolderPath
  364. tb_Sh_Ep_Title.Text = "Unable to find folder: " & Show.FolderPath
  365. Else
  366. If TabControl3.TabPages(1).Text = "Screenshot" Then
  367. TabControl3.TabPages.RemoveAt(1)
  368. End If
  369. 'load tvshow.nfo
  370. ListBox3.Items.Clear()
  371. TextBox26.Text = ""
  372. Dim todo As Boolean = False
  373. If Show.State = Media_Companion.ShowState.Locked Then
  374. btn_TvShState.Text = "Locked"
  375. btn_TvShState.BackColor = Color.Red
  376. ElseIf Show.State = Media_Companion.ShowState.Open Then
  377. btn_TvShState.Text = "Open"
  378. btn_TvShState.BackColor = Color.LawnGreen
  379. ElseIf Show.State = Media_Companion.ShowState.Unverified Then
  380. btn_TvShState.Text = "Un-Verified"
  381. btn_TvShState.BackColor = Color.Yellow
  382. Else
  383. btn_TvShState.Text = "Error"
  384. btn_TvShState.BackColor = Color.Gray
  385. End If
  386. btn_TvShState.Tag = Show
  387. If Show.Status.Value = "Ended" Then
  388. bnt_TvSeriesStatus.Text = "Ended"
  389. bnt_TvSeriesStatus.BackColor = Color.LightPink
  390. ElseIf Show.Status.Value = "Continuing" Then
  391. bnt_TvSeriesStatus.Text = "Continuing"
  392. bnt_TvSeriesStatus.BackColor = Color.LightSeaGreen
  393. Else
  394. bnt_TvSeriesStatus.Text = "Unknown"
  395. bnt_TvSeriesStatus.BackColor = Color.LightYellow
  396. End If
  397. Dim tvpbright As String = Utilities.DefaultTvPosterPath
  398. Dim tvpbbottom As String = Utilities.DefaultTvBannerPath
  399. If Pref.EdenEnabled AndAlso Not Pref.FrodoEnabled Then
  400. If Pref.postertype = "banner" Then
  401. If Utilities.IsBanner(Show.FolderPath & "folder.jpg") Then
  402. tvpbbottom = Show.FolderPath & "folder.jpg"
  403. Else
  404. tvpbright = Show.ImagePoster.path
  405. End If
  406. Else
  407. tvpbright = Show.ImagePoster.path
  408. End If
  409. End If
  410. If Pref.FrodoEnabled Then
  411. Show.ImagePoster.FileName = "poster.jpg"
  412. Show.ImageBanner.FileName = "banner.jpg"
  413. tvpbbottom = Show.ImageBanner.Path
  414. tvpbright = Show.ImagePoster.path
  415. End If
  416. util_ImageLoad(tv_PictureBoxRight, tvpbright, Utilities.DefaultTvPosterPath)
  417. util_ImageLoad(tv_PictureBoxBottom, tvpbbottom, Utilities.DefaultTvBannerPath)
  418. util_ImageLoad(tv_PictureBoxLeft, Show.ImageFanart.Path, Utilities.DefaultTvFanartPath)
  419. Panel_EpisodeInfo.Visible = False
  420. Panel_EpisodeActors.Visible = False
  421. lbl_sorttitle.Visible = True
  422. TextBox_Sorttitle.Visible = True
  423. tb_Sh_Ep_Title.BackColor = Color.White
  424. If Show.Title.Value <> Nothing Then
  425. tb_Sh_Ep_Title.Text = Show.Title.Value
  426. End If
  427. ' changed indication of an issue, setting the title means that the title is saved to the nfo if the user exits. Yellow is the same colour as the unverified Button
  428. If Show.State = ShowState.Unverified Then tb_Sh_Ep_Title.BackColor = Color.Yellow
  429. If Show.State = ShowState.Error Then tb_Sh_Ep_Title.BackColor = Color.Red
  430. tb_ShPremiered.Text = Utilities.ReplaceNothing(Show.Premiered.Value)
  431. tb_ShGenre.Text = Utilities.ReplaceNothing(Show.Genre.Value)
  432. tb_ShTvdbId.Text = Utilities.ReplaceNothing(Show.TvdbId.Value)
  433. tb_ShImdbId.Text = Utilities.ReplaceNothing(Show.ImdbId.Value)
  434. tb_ShRating.Text = Utilities.ReplaceNothing(Show.Rating.Value)
  435. tb_ShVotes.Text = Utilities.ReplaceNothing(Show.Votes.Value)
  436. tb_ShCert.Text = Utilities.ReplaceNothing(Show.Mpaa.Value)
  437. tb_ShRunTime.Text = Utilities.ReplaceNothing(Show.Runtime.Value)
  438. tb_ShStudio.Text = Utilities.ReplaceNothing(Show.Studio.Value)
  439. tb_ShPlot.Text = Utilities.ReplaceNothing(Show.Plot.Value)
  440. TextBox_Sorttitle.Text = Utilities.ReplaceNothing(If(String.IsNullOrEmpty(Show.SortTitle.Value ), Show.Title.Value, Show.SortTitle.Value))
  441. If String.IsNullOrEmpty(Show.SortOrder.Value) Then Show.SortOrder.Value = Pref.sortorder
  442. If Show.SortOrder.Value = "dvd" Then
  443. btn_TvShSortOrder.Text = "DVD"
  444. ElseIf Show.SortOrder.Value = "default" Then
  445. btn_TvShSortOrder.Text = "Default"
  446. End If
  447. '0 - all from tvdb
  448. '1 - all from imdb
  449. '2 - tv imdb, eps tvdb
  450. '3 - tv TVDB, eps IMDB
  451. If String.IsNullOrEmpty(Show.EpisodeActorSource.Value) Then
  452. If Pref.TvdbActorScrape = "0" Or Pref.TvdbActorScrape = "2" Then
  453. Show.EpisodeActorSource.Value = "tvdb"
  454. Else
  455. Show.EpisodeActorSource.Value = "imdb"
  456. End If
  457. End If
  458. Button46.Text = Show.EpisodeActorSource.Value.ToUpper
  459. If String.IsNullOrEmpty(Show.TvShowActorSource.Value) Then
  460. If Pref.TvdbActorScrape = "0" Or Pref.TvdbActorScrape = "3" Then
  461. Show.TvShowActorSource.Value = "tvdb"
  462. Else
  463. Show.TvShowActorSource.Value = "imdb"
  464. End If
  465. End If
  466. TvPanel7Update(Show.FolderPath)
  467. Button45.Text = Show.TvShowActorSource.Value.ToUpper
  468. Call tv_ActorsLoad(Show.ListActors)
  469. 'Show.UpdateTreenode()
  470. End If
  471. Panel_EpisodeInfo.Visible = False
  472. Panel_EpisodeActors.Visible = False
  473. End Sub
  474. Private Sub tb_ShGenre_MouseDown(sender As Object, e As MouseEventArgs) Handles tb_ShGenre.MouseDown
  475. If e.Button = Windows.Forms.MouseButtons.Right Then
  476. Try
  477. Dim thisshow As TvShow = tv_ShowSelectedCurrently(TvTreeview)
  478. Dim item() As String = thisshow.Genre.Value.Split("/")
  479. Dim genre As String = ""
  480. Dim listof As New List(Of str_genre)
  481. listof.Clear()
  482. For Each i In item
  483. Dim g As str_genre
  484. g.genre = i.Trim
  485. g.count = 1
  486. listof.Add(g)
  487. Next
  488. Dim frm As New frmGenreSelect
  489. frm.multicount = 1
  490. frm.SelectedGenres = listof
  491. frm.Init()
  492. If frm.ShowDialog() = Windows.Forms.DialogResult.OK Then
  493. listof.Clear()
  494. listof.AddRange(frm.SelectedGenres)
  495. For each g In listof
  496. If g.count = 0 Then Continue For
  497. If genre = "" Then
  498. genre = g.genre
  499. Else
  500. genre += " / " & g.genre
  501. End If
  502. Next
  503. thisshow.Genre.Value = genre
  504. tb_ShGenre.Text = genre
  505. nfoFunction.tvshow_NfoSave(thisshow, True) 'thisshow.Save()
  506. End If
  507. Catch
  508. End Try
  509. End If
  510. End Sub
  511. Public Sub tv_ActorsLoad(ByVal listActors As Media_Companion.ActorList)
  512. cbTvActor.Items.Clear()
  513. cbTvActorRole.Items.Clear()
  514. For Each actor In ListActors
  515. If actor.actorname <> Nothing AndAlso Not cbTvActor.Items.Contains(actor.actorname) Then
  516. cbTvActor.Items.Add(actor.actorname)
  517. Dim role As String = actor.actorrole
  518. If String.IsNullOrEmpty(role) Or role = Nothing Then role = actor.actorname
  519. cbTvActorRole.Items.Add(role)
  520. End If
  521. Next
  522. If cbTvActor.Items.Count = 0 Then
  523. actorflag = true
  524. cbTvActorRole.Items.Add("")
  525. cbTvActorRole.SelectedIndex = 0
  526. Call tv_ActorDisplay(True)
  527. Else
  528. cbTvActor.SelectedIndex = 0
  529. 'Call tv_ActorDisplay()
  530. End If
  531. End Sub
  532. Public Sub tv_ActorDisplay(Optional ByVal useDefault As Boolean = False)
  533. Dim WorkingTvShow As TvShow = tv_ShowSelectedCurrently(TvTreeview)
  534. If WorkingTvShow Is Nothing Then Exit Sub
  535. Dim imgLocation As String = Utilities.DefaultActorPath
  536. Dim eden As Boolean = Pref.EdenEnabled
  537. Dim frodo As Boolean = Pref.FrodoEnabled
  538. PictureBox6.Image = Nothing
  539. If useDefault Then
  540. imgLocation = Utilities.DefaultActorPath
  541. Else
  542. For Each actor In WorkingTvShow.ListActors
  543. If actor.actorname = cbTvActor.Text Then
  544. Dim temppath As String = Pref.GetActorPath(WorkingTvShow.NfoFilePath, actor.actorname, actor.ID.Value)
  545. If IO.File.Exists(temppath) Then
  546. imgLocation = temppath
  547. ElseIf (Not Pref.LocalActorImage) AndAlso actor.actorthumb <> Nothing AndAlso (actor.actorthumb.IndexOf("http") <> -1 OrElse IO.File.Exists(actor.actorthumb)) Then
  548. imgLocation = actor.actorthumb
  549. End If
  550. Exit For
  551. End If
  552. Next
  553. End If
  554. Try
  555. util_ImageLoad(PictureBox6, imgLocation, Utilities.DefaultActorPath)
  556. PictureBox6.SizeMode = PictureBoxSizeMode.Zoom
  557. Catch
  558. End Try
  559. End Sub
  560. Public Sub tv_ActorRoleDisplay(Optional ByVal useDefault As Boolean = False)
  561. Dim WorkingTvShow As TvShow = tv_ShowSelectedCurrently(TvTreeview)
  562. If WorkingTvShow Is Nothing Then Exit Sub
  563. Dim imgLocation As String = Utilities.DefaultActorPath
  564. Dim eden As Boolean = Pref.EdenEnabled
  565. Dim frodo As Boolean = Pref.FrodoEnabled
  566. PictureBox6.Image = Nothing
  567. If useDefault Then
  568. imgLocation = Utilities.DefaultActorPath
  569. Else
  570. For Each actor In WorkingTvShow.ListActors
  571. If actor.actorrole = cbTvActorRole.Text Then
  572. Dim temppath As String = Pref.GetActorPath(WorkingTvShow.NfoFilePath, actor.actorname, actor.ID.Value)
  573. If IO.File.Exists(temppath) Then
  574. imgLocation = temppath
  575. ElseIf (Not Pref.LocalActorImage) AndAlso actor.actorthumb <> Nothing AndAlso (actor.actorthumb.IndexOf("http") <> -1 OrElse IO.File.Exists(actor.actorthumb)) Then
  576. imgLocation = actor.actorthumb
  577. End If
  578. Exit For
  579. End If
  580. Next
  581. End If
  582. Try
  583. util_ImageLoad(PictureBox6, imgLocation, Utilities.DefaultActorPath)
  584. PictureBox6.SizeMode = PictureBoxSizeMode.Zoom
  585. Catch
  586. End Try
  587. End Sub
  588. Public Function TvCheckforExtraArt(ByVal Showpath As String) As Boolean
  589. Dim confirmedpresent As Boolean = False
  590. If Directory.Exists(Showpath) Then
  591. If File.Exists(Showpath & "clearart.png") Then tvFanlistbox.Items.Add("ClearArt") : confirmedpresent = True
  592. If File.Exists(Showpath & "logo.png") Then tvFanlistbox.Items.Add("Logo") : confirmedpresent = True
  593. If File.Exists(Showpath & "landscape.jpg") Then tvFanlistbox.Items.Add("Landscape") : confirmedpresent = True
  594. If File.Exists(Showpath & "character.png") Then tvFanlistbox.Items.Add("Character") : confirmedpresent = True
  595. End If
  596. Return confirmedpresent
  597. End Function
  598. Public Sub TvPanel7Update(ByVal TvShPath As String)
  599. tvFanlistbox.Items.Clear()
  600. Panel_TvShowExtraArtwork.Visible = TvCheckforExtraArt(TvShPath)
  601. End Sub
  602. Private Sub tvFanlistbox_Mouse(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvFanlistbox.MouseDown
  603. Dim imagepath As String = Nothing
  604. Dim item As String = Nothing
  605. If e.button = Windows.Forms.MouseButtons.Right Then
  606. Dim index As Integer = tvFanlistbox.IndexFromPoint(New Point(e.X, e.Y))
  607. If index >= 0 Then tvFanlistbox.SelectedItem = tvFanlistbox.Items(index)
  608. End If
  609. If IsNothing(tvFanlistbox.SelectedItem) Then Exit Sub
  610. item = tvFanlistbox.SelectedItem.ToString.ToLower
  611. If Not String.IsNullOrEmpty(item) Then
  612. Dim tmpsh As TvShow = tv_ShowSelectedCurrently(TvTreeview)
  613. imagepath = tmpsh.FolderPath
  614. Dim suffix As String = If((item = "clearart" or item = "logo" or item = "character"),".png", ".jpg")
  615. imagepath &= item & suffix
  616. End If
  617. If e.Button = Windows.Forms.MouseButtons.Left Then
  618. pbtvfanarttv.Visible = True
  619. If Not IsNothing(imagepath) Then util_ImageLoad(pbtvfanarttv, imagepath, "")
  620. ElseIf e.button = Windows.Forms.MouseButtons.Right Then
  621. Dim tempint = MessageBox.show("Do you wish to delete this image from" & vbCrLf & "this Tv Show?", "Fanart.Tv Artwork Delete", MessageBoxButtons.YesNoCancel)
  622. If tempint = Windows.Forms.DialogResult.No or tempint = DialogResult.Cancel Then Exit Sub
  623. If tempint = Windows.Forms.DialogResult.Yes Then
  624. Utilities.SafeDeleteFile(imagepath)
  625. TvPanel7Update(tv_ShowSelectedCurrently(TvTreeview).FolderPath)
  626. End If
  627. End If
  628. End Sub
  629. Private Sub tvFanlistbox_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tvFanlistbox.MouseLeave
  630. tvFanlistbox.ClearSelected()
  631. pbtvfanarttv.Image = Nothing
  632. pbtvfanarttv.Visible = False
  633. End Sub
  634. Public Sub tv_SeasonSelected(ByRef SelectedSeason As Media_Companion.TvSeason)
  635. SelectedSeason.ShowObj.ListActors.Clear()
  636. SelectedSeason.ShowObj.Load()
  637. Panel_TvShowExtraArtwork.Visible = False
  638. Dim Show As Media_Companion.TvShow
  639. If SelectedSeason.SeasonNode.Parent.Tag IsNot Nothing Then
  640. Show = SelectedSeason.SeasonNode.Parent.Tag
  641. Else
  642. MsgBox("Show tag not set")
  643. Exit Sub
  644. End If
  645. tb_Sh_Ep_Title.BackColor = Color.White
  646. If Show.Title.Value <> Nothing Then
  647. If SelectedSeason.SeasonNumber = 0 Then
  648. tb_Sh_Ep_Title.Text = Utilities.ReplaceNothing(Show.Title.Value) & " - Specials"
  649. Else
  650. tb_Sh_Ep_Title.Text = Utilities.ReplaceNothing(Show.Title.Value) & " - " & Utilities.ReplaceNothing(SelectedSeason.SeasonNode.Text)
  651. End If
  652. End If
  653. If TabControl3.TabPages(1).Text = "Screenshot" Then
  654. TabControl3.TabPages.RemoveAt(1)
  655. End If
  656. ' changed indication of an issue, setting the title means that the title is saved to the nfo if the user exits. Yellow is the same colour as the unverified Button
  657. If Show.State = ShowState.Unverified Then tb_Sh_Ep_Title.BackColor = Color.Yellow
  658. If Show.State = ShowState.Error Then tb_Sh_Ep_Title.BackColor = Color.Red
  659. tb_ShPremiered.Text = Utilities.ReplaceNothing(Show.Premiered.Value)
  660. tb_ShGenre.Text = Utilities.ReplaceNothing(Show.Genre.Value)
  661. tb_ShTvdbId.Text = Utilities.ReplaceNothing(Show.TvdbId.Value)
  662. tb_ShImdbId.Text = Utilities.ReplaceNothing(Show.ImdbId.Value)
  663. tb_ShRating.Text = Utilities.ReplaceNothing(Show.Rating.Value)
  664. tb_ShVotes.Text = Utilities.ReplaceNothing(Show.Votes.Value)
  665. tb_ShCert.Text = Utilities.ReplaceNothing(Show.Mpaa.Value)
  666. tb_ShRunTime.Text = Utilities.ReplaceNothing(Show.Runtime.Value)
  667. tb_ShStudio.Text = Utilities.ReplaceNothing(Show.Studio.Value)
  668. tb_ShPlot.Text = Utilities.ReplaceNothing(Show.Plot.Value)
  669. Panel_EpisodeInfo.Visible = False
  670. Panel_EpisodeActors.Visible = False
  671. lbl_sorttitle.Visible = True
  672. TextBox_Sorttitle.Visible = True
  673. TextBox_Sorttitle.Text = Utilities.ReplaceNothing(If(String.IsNullOrEmpty(Show.SortTitle.Value ), Show.Title.Value, Show.SortTitle.Value))
  674. ExpandSelectedShowToolStripMenuItem.Enabled = True
  675. ExpandAllToolStripMenuItem.Enabled = True
  676. CollapseAllToolStripMenuItem.Enabled = True
  677. CollapseSelectedShowToolStripMenuItem.Enabled = True
  678. Tv_TreeViewContext_RenameEp.Enabled = True
  679. Tv_TreeViewContext_RenameEp.Visible = True
  680. 'MsgBox("Season")
  681. Dim season As String = SelectedSeason.SeasonLabel
  682. Dim trueseason As Integer = SelectedSeason.SeasonNumber
  683. Dim PaddedSeason As String = Utilities.PadNumber(SelectedSeason.SeasonNumber, 2)
  684. Dim tvpbright As String = Utilities.DefaultTvPosterPath
  685. Dim tvpbbottom As String = Utilities.DefaultTvBannerPath
  686. If trueseason = -1 Then
  687. If SelectedSeason.Poster.Image IsNot Nothing Then
  688. tvpbright = SelectedSeason.Poster.Path
  689. Else
  690. If Pref.postertype = "banner" Then
  691. tvpbright = Show.ImagePoster.Path
  692. Else
  693. tvpbbottom = Show.ImageBanner.Path
  694. End If
  695. End If
  696. ElseIf trueseason = 0 Then 'Specials
  697. If Pref.EdenEnabled AndAlso Not Pref.FrodoEnabled Then
  698. tvpbright = Show.FolderPath & "season-specials.tbn"
  699. If Not File.Exists(tvpbright) Then tvpbright = Show.FolderPath & "folder.jpg"
  700. End If
  701. If Pref.FrodoEnabled Then
  702. tvpbright = Show.FolderPath & "season-specials-poster.jpg"
  703. If Not File.Exists(tvpbright) Then tvpbright = Show.FolderPath & "folder.jpg"
  704. tvpbbottom = Show.FolderPath & "season-specials-banner.jpg"
  705. If Not File.Exists(tvpbbottom) Then tvpbbottom = Show.FolderPath & "banner.jpg"
  706. End If
  707. Else 'Season01 & up
  708. tvpbright = SelectedSeason.Poster.Path
  709. If Pref.FrodoEnabled Then tvpbbottom = SelectedSeason.Banner.Path
  710. End If
  711. util_ImageLoad(tv_PictureBoxRight, tvpbright, Utilities.DefaultTvPosterPath)
  712. util_ImageLoad(tv_PictureBoxBottom, tvpbbottom, Utilities.DefaultTvBannerPath)
  713. If Show.NfoFilePath <> Nothing Then util_ImageLoad(tv_PictureBoxLeft, Show.FolderPath & "fanart.jpg", Utilities.DefaultTvFanartPath)
  714. Call tv_ActorsLoad(Show.ListActors)
  715. Show.UpdateTreenode()
  716. End Sub
  717. Public Sub tv_EpisodeSelected(ByRef SelectedEpisode As Media_Companion.TvEpisode, Optional ByVal Force As Boolean = False)
  718. If TabControl3.TabPages(1).Text <> "Screenshot" Then
  719. If screenshotTab IsNot Nothing Then
  720. TabControl3.TabPages.Insert(1, screenshotTab)
  721. TabControl3.Refresh()
  722. End If
  723. End If
  724. Panel_EpisodeInfo.Visible = True
  725. Panel_EpisodeActors.Visible = True 'set ep actor panel visible, we'll hide later if no actor's in episode.
  726. cmbxEpActor.Items.Clear()
  727. tbEpRole.Text = ""
  728. Dim Show As TvShow = tv_ShowSelectedCurrently(TvTreeview)
  729. Dim season As Integer = SelectedEpisode.Season.Value
  730. Dim episode As Integer = SelectedEpisode.Episode.Value
  731. Dim SeasonObj As New Media_Companion.TvSeason
  732. If SelectedEpisode.EpisodeNode.Parent IsNot Nothing Then
  733. SeasonObj = SelectedEpisode.EpisodeNode.Parent.Tag
  734. If season = -1 Then season = SeasonObj.SeasonLabel
  735. End If
  736. Call ep_Load(SeasonObj, SelectedEpisode, Force)
  737. lbl_sorttitle.Visible = False
  738. TextBox_Sorttitle.Visible = false
  739. Tv_TreeViewContext_ViewNfo.Enabled = True
  740. ExpandSelectedShowToolStripMenuItem.Enabled = True
  741. ExpandAllToolStripMenuItem.Enabled = True
  742. CollapseAllToolStripMenuItem.Enabled = True
  743. CollapseSelectedShowToolStripMenuItem.Enabled = True
  744. Tv_TreeViewContext_ReloadFromCache.Enabled = True
  745. Tv_TreeViewContext_OpenFolder.Enabled = True
  746. If SelectedEpisode.ListActors.Count < 1 Then 'If episode actors, don't load show's actors. (save some time)
  747. If SeasonObj.ShowObj.ListActors.Count = 0 Then Show.Load()
  748. Call tv_ActorsLoad(Show.ListActors)
  749. End If
  750. End Sub
  751. Private Function TestForMultiepisode(ByVal path As String)
  752. Dim multiepisode As Boolean = False
  753. Try
  754. Dim firstline As String = ""
  755. If IO.File.Exists(path) Then
  756. Dim listText As New List(Of String)
  757. Dim objLine As String = ""
  758. Using objReader As StreamReader = New StreamReader(path)
  759. Do
  760. objLine = objReader.ReadLine()
  761. If objLine.IndexOf("<multiepisodenfo>") <> -1 Then
  762. multiepisode = True
  763. Exit Do
  764. ElseIf objLine.IndexOf("<episodedetails>") <> -1 Then
  765. multiepisode = False
  766. Exit Do
  767. End If
  768. Loop Until objLine Is Nothing
  769. End Using
  770. End If
  771. Catch
  772. End Try
  773. Return multiepisode
  774. End Function
  775. Private Sub ep_Load(ByRef Season As Media_Companion.TvSeason, ByRef Episode As Media_Companion.TvEpisode, Optional ByVal epupdate As Boolean = False)
  776. Panel_TvShowExtraArtwork.Visible = False
  777. 'test if already loaded nfo into treeview, if so, then no need to reload
  778. 'If IsNothing(Episode.Plot.Value) OrElse epupdate Then
  779. Episode.ListActors.Clear()
  780. Dim episodelist As New List(Of TvEpisode)
  781. episodelist = WorkingWithNfoFiles.ep_NfoLoad(Episode.NfoFilePath)
  782. 'test for multiepisodenfo
  783. If episodelist.Count = 1 Then
  784. Episode.AbsorbTvEpisode(episodelist(0))
  785. Else
  786. For Each Ep In episodelist
  787. If Ep.Season.Value = Episode.Season.Value AndAlso Ep.Episode.Value = Episode.Episode.Value Then
  788. Episode.AbsorbTvEpisode(Ep) 'update treenode
  789. Exit For
  790. End If
  791. Next
  792. End If
  793. 'End If
  794. Dim tempstring As String = ""
  795. lb_EpDetails.Items.Clear()
  796. cmbxEpActor.Items.Clear()
  797. tb_EpFilename.Text = Utilities.ReplaceNothing(IO.Path.GetFileName(Episode.NfoFilePath))
  798. tb_EpPath.Text = Utilities.ReplaceNothing(Episode.FolderPath)
  799. If Not IO.File.Exists(Episode.NfoFilePath) Then
  800. tb_Sh_Ep_Title.Text = "Unable to find episode: " & Episode.NfoFilePath
  801. Panel_EpisodeInfo.Visible = True
  802. Panel_EpisodeActors.Visible = True
  803. cmbxEpActor.Items.Clear()
  804. tbEpRole.Text = ""
  805. Episode.EpisodeNode.BackColor = Color.Red
  806. Exit Sub
  807. Else
  808. Episode.EpisodeNode.BackColor = Color.Transparent 'i.e. back to normal
  809. End If
  810. tb_Sh_Ep_Title.Text ="'" & Utilities.ReplaceNothing(Episode.Title.Value, "?") & "'"
  811. tb_EpRating.Text = Utilities.ReplaceNothing(Episode.Rating.Value)
  812. tb_EpVotes.Text = Utilities.ReplaceNothing(Episode.Votes.Value)
  813. tb_EpPlot.Text = Utilities.ReplaceNothing(Episode.Plot.Value)
  814. tb_EpDirector.Text = Utilities.ReplaceNothing(Episode.Director.Value)
  815. tb_EpCredits.Text = Utilities.ReplaceNothing(Episode.Credits.Value)
  816. tb_EpAired.Text = Utilities.ReplaceNothing(Episode.Aired.Value)
  817. For f = 0 To cbTvSource.Items.Count - 1
  818. If cbTvSource.Items(f) = Episode.Source.value Then
  819. cbTvSource.SelectedIndex = f
  820. Exit For
  821. End If
  822. Next
  823. If Episode.Season.Value = "0" Then
  824. lbl_EpAirBefore.Visible = True
  825. lbl_EpAirSeason.Visible = True
  826. lbl_EPAirEpisode.Visible = True
  827. tb_EpAirEpisode.Visible = True
  828. tb_EpAirSeason.Visible = True
  829. tb_EpAirSeason.Text = Episode.DisplaySeason.Value
  830. tb_EpAirEpisode.Text = Episode.DisplayEpisode.Value
  831. Else
  832. lbl_EpAirBefore.Visible = False
  833. lbl_EpAirSeason.Visible = False
  834. lbl_EPAirEpisode.Visible = False
  835. tb_EpAirEpisode.Visible = False
  836. tb_EpAirSeason.Visible = False
  837. tb_EpAirEpisode.Text = ""
  838. tb_EpAirSeason.Text = ""
  839. End If
  840. util_EpisodeSetWatched(Episode.PlayCount.Value)
  841. Dim epdetails As String = ""
  842. epdetails += "Video: " & Utilities.ReplaceNothing(Episode.Details.StreamDetails.Video.Width.Value, "?") & "x" & Utilities.ReplaceNothing(Episode.Details.StreamDetails.Video.Height.Value, "?")
  843. epdetails += ", (" & Utilities.ReplaceNothing(Episode.Details.StreamDetails.Video.Aspect.Value, "?") & ")"
  844. lb_EpDetails.Items.Add(epdetails)
  845. epdetails = " :- " & Utilities.ReplaceNothing(Episode.Details.StreamDetails.Video.Codec.Value, "?")
  846. epdetails += ", @ " & Utilities.ReplaceNothing(Episode.Details.StreamDetails.Video.Bitrate.Value, "?")
  847. lb_EpDetails.Items.Add(epdetails)
  848. If Episode.Details.StreamDetails.Audio.Count > 0 Then
  849. epdetails = "Audio: " & Utilities.ReplaceNothing(Episode.Details.StreamDetails.Audio(0).Codec.Value, "?")
  850. lb_EpDetails.Items.Add(epdetails)
  851. epdetails = Utilities.ReplaceNothing(Episode.Details.StreamDetails.Audio(0).Bitrate.Value, "?")
  852. epdetails += ", " & Utilities.ReplaceNothing(Episode.Details.StreamDetails.Audio(0).Channels.Value, "?") & " Ch"
  853. lb_EpDetails.Items.Add(epdetails)
  854. End If
  855. Dim aActor As Boolean = False
  856. For Each actor In Episode.ListActors
  857. If Not String.IsNullOrEmpty(actor.actorname) Then
  858. cmbxEpActor.Items.Add(Utilities.ReplaceNothing(actor.actorname))
  859. aActor = True
  860. End If
  861. Next
  862. If aActor Then
  863. cmbxEpActor.SelectedIndex = 0
  864. Else
  865. cmbxEpActor.Items.Clear()
  866. cmbxEpActor.Items.Add("")
  867. cmbxEpActor.SelectedIndex = 0
  868. Panel_EpisodeActors.Visible = False
  869. End If
  870. If (Episode IsNot Nothing AndAlso Episode.Thumbnail IsNot Nothing) Then
  871. Dim eptvleft As String = Episode.Thumbnail.Path
  872. If Pref.FrodoEnabled Then eptvleft = Episode.Thumbnail.Path.Replace(".tbn", "-thumb.jpg")
  873. util_ImageLoad(tv_PictureBoxLeft, eptvleft, Utilities.DefaultTvFanartPath)
  874. End If
  875. If (Season IsNot Nothing AndAlso Season.Poster IsNot Nothing) Then
  876. util_ImageLoad(tv_PictureBoxRight, Season.Poster.Path, Utilities.DefaultTvPosterPath)
  877. If Pref.FrodoEnabled Then
  878. util_ImageLoad(tv_PictureBoxBottom, Season.Banner.Path, Utilities.DefaultTvBannerPath)
  879. End If
  880. End If
  881. Dim video_flags = GetEpMediaFlags()
  882. movieGraphicInfo.OverlayInfo(tv_PictureBoxLeft, tb_EpRating.Text, video_flags)
  883. Panel_EpisodeInfo.Visible = True
  884. End Sub
  885. Public Function ep_Get(ByVal tvdbid As String, ByVal sortorder As String, ByRef seasonno As String, ByRef episodeno As String, ByVal language As String, ByVal aired As String)
  886. Dim episodestring As String = ""
  887. Dim episodeurl As String = ""
  888. Dim episodeurl2 As String = ""
  889. Dim xmlfile As String = ""
  890. If language.ToLower.IndexOf(".xml") = -1 Then
  891. language = language & ".xml"
  892. End If
  893. episodeurl2 = "http://thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/" & sortorder & "/" & seasonno & "/" & episodeno & "/" & language
  894. If aired = Nothing Then
  895. episodeurl = "http://thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/" & sortorder & "/" & seasonno & "/" & episodeno & "/" & language
  896. Else
  897. episodeurl = String.Format("http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey=6E82FED600783400&seriesid={0}&airdate={1}&language={2}", tvdbid, aired, language)
  898. End If
  899. 'First try seriesxml data
  900. 'check if present, download if not
  901. Dim gotseriesxml As Boolean = False
  902. Dim url As String = "http://www.thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/all/" & language
  903. Dim xmlfile2 As String = SeriesXmlPath & tvdbid & ".xml"
  904. Dim SeriesInfo As New Tvdb.ShowData
  905. If Not File.Exists(SeriesXmlPath & tvdbid & ".xml") Then
  906. gotseriesxml = DownloadCache.Savexmltopath(url, SeriesXmlPath, tvdbid & ".xml", True)
  907. Else
  908. 'Check series xml isn't older than Five days. If so, re-download it.
  909. Dim dtCreationDate As DateTime = File.GetLastWriteTime(xmlfile2)
  910. Dim datenow As DateTime = Date.Now()
  911. Dim dif As Long = DateDiff(DateInterval.Day, dtCreationDate, datenow)
  912. If dif > If(aired <> Nothing, 1, 5) Then
  913. gotseriesxml = DownloadCache.Savexmltopath(url, SeriesXmlPath, tvdbid & ".xml", True)
  914. Else
  915. gotseriesxml = True
  916. End If
  917. End If
  918. If Not gotseriesxml then
  919. xmlfile = Utilities.DownloadTextFiles(episodeurl)
  920. If xmlfile.Contains("No Results from SP") AndAlso (seasonno <> "-1" And episodeno <> "-1") Then
  921. xmlfile = Utilities.DownloadTextFiles(episodeurl2)
  922. End If
  923. Else
  924. SeriesInfo.Load(xmlfile2)
  925. Dim gotEpxml As Boolean = False
  926. 'check episode is present in seriesxml file, else, re-download it (update to latest)
  927. If aired <> Nothing Then
  928. For Each NewEpisode As Tvdb.Episode In SeriesInfo.Episodes
  929. If NewEpisode.FirstAired.Value = aired Then
  930. xmlfile = NewEpisode.Node.ToString
  931. xmlfile = "<Data>" & xmlfile & "</Data>"
  932. gotEpxml = True
  933. Exit For
  934. End If
  935. Next
  936. End If
  937. If Not gotEpxml AndAlso (seasonno <> "-1" And episodeno <> "-1") Then
  938. If sortorder = "default" Then
  939. For Each NewEpisode As Tvdb.Episode In SeriesInfo.Episodes
  940. If NewEpisode.EpisodeNumber.Value = episodeno AndAlso NewEpisode.SeasonNumber.Value = seasonno Then
  941. xmlfile = NewEpisode.Node.ToString
  942. xmlfile = "<Data>" & xmlfile & "</Data>"
  943. gotEpxml = True
  944. Exit For
  945. End If
  946. Next
  947. ElseIf sortorder = "dvd" Then
  948. For Each NewEpisode As Tvdb.Episode In SeriesInfo.Episodes
  949. If NewEpisode.DvdEpisodeNumber.value = (episodeno & ".0") AndAlso NewEpisode.DvdSeason.Value = seasonno Then
  950. xmlfile = NewEpisode.Node.ToString
  951. xmlfile = "<Data>" & xmlfile & "</Data>"
  952. gotEpxml = True
  953. Exit For
  954. End If
  955. Next
  956. End If
  957. End If
  958. ' Finally, if not in seriesxml file, go old-school
  959. If Not gotEpxml Then
  960. xmlfile = Utilities.DownloadTextFiles(episodeurl)
  961. If xmlfile.Contains("No Results from SP") AndAlso (seasonno <> "-1" And episodeno <> "-1") Then
  962. xmlfile = Utilities.DownloadTextFiles(episodeurl2)
  963. End If
  964. End If
  965. End If
  966. If xmlfile.Contains("Could not connect") OrElse xmlfile.Contains("No Results from SP") Then Return xmlfile ' Added check if TVDB is unavailable.
  967. Dim xmlOK As Boolean = Utilities.CheckForXMLIllegalChars(xmlfile)
  968. If xmlOK Then
  969. episodestring = "<episodedetails>"
  970. episodestring = episodestring & "<url>" & If(IsNothing(aired), episodeurl, episodeurl2) & "</url>"
  971. Dim mirrorslist As New XmlDocument
  972. mirrorslist.LoadXml(xmlfile)
  973. Dim thisresult As XmlNode = Nothing
  974. For Each thisresult In mirrorslist("Data")
  975. Select Case thisresult.Name
  976. Case "Episode"
  977. Dim mirrorselection As XmlNode = Nothing
  978. For Each mirrorselection In thisresult.ChildNodes
  979. Select Case mirrorselection.Name
  980. Case "EpisodeName"
  981. episodestring = episodestring & "<title>" & mirrorselection.InnerXml & "</title>"
  982. Case "FirstAired"
  983. episodestring = episodestring & "<premiered>" & mirrorselection.InnerXml & "</premiered>"
  984. Case "GuestStars"
  985. Dim gueststars() As String = mirrorselection.InnerXml.Split("|")
  986. For Each guest In gueststars
  987. If Not String.IsNullOrEmpty(guest) Then
  988. episodestring = episodestring & "<actor><name>" & guest & "</name></actor>"
  989. End If
  990. Next
  991. Case "Director"
  992. Dim tempstring As String = mirrorselection.InnerXml
  993. tempstring = tempstring.Trim("|")
  994. episodestring = episodestring & "<director>" & tempstring & "</director>"
  995. Case "Writer"
  996. Dim tempstring As String = mirrorselection.InnerXml
  997. tempstring = tempstring.Trim("|")
  998. episodestring = episodestring & "<credits>" & tempstring & "</credits>"
  999. Case "Overview"
  1000. episodestring = episodestring & "<plot>" & mirrorselection.InnerXml & "</plot>"
  1001. Case "Rating"
  1002. episodestring = episodestring & "<rating>" & mirrorselection.InnerXml & "</rating>"
  1003. Case "RatingCount"
  1004. episodestring = episodestring & "<ratingcount>" & mirrorselection.InnerXml & "</ratingcount>"
  1005. Case "IMDB_ID"
  1006. episodestring = episodestring & "<imdbid>" & mirrorselection.InnerXml & "</imdbid>"
  1007. Case "id"
  1008. episodestring = episodestring & "<uniqueid>" & mirrorselection.InnerXml & "</uniqueid>"
  1009. Case "seriesid"
  1010. episodestring = episodestring & "<showid>" & mirrorselection.InnerXml & "</showid>"
  1011. Case "filename"
  1012. episodestring = episodestring & "<thumb>http://www.thetvdb.com/banners/" & mirrorselection.InnerXml & "</thumb>"
  1013. Case "airsbefore_episode"
  1014. episodestring = episodestring & "<displayepisode>" & mirrorselection.InnerXml & "</displayepisode>"
  1015. Case "airsbefore_season"
  1016. episodestring = episodestring & "<displayseason>" & mirrorselection.InnerXml & "</displayseason>"
  1017. Case "SeasonNumber"
  1018. If sortorder = "default" Then seasonno = mirrorselection.InnerText
  1019. Case "EpisodeNumber"
  1020. If sortorder = "default" Then episodeno = mirrorselection.InnerText
  1021. Case "DVD_season"
  1022. If sortorder = "dvd" Then seasonno = mirrorselection.InnerText
  1023. Case "DVD_episodenumber"
  1024. If sortorder = "dvd" Then episodeno = mirrorselection.InnerText.Substring(0, mirrorselection.InnerText.IndexOf("."))
  1025. End Select
  1026. Next
  1027. End Select
  1028. Next
  1029. episodestring = episodestring & "</episodedetails>"
  1030. Else
  1031. If CheckBoxDebugShowTVDBReturnedXML.Checked = True Then MsgBox(xmlfile, MsgBoxStyle.OkOnly, "FORM1 getepisode - TVDB returned.....")
  1032. episodestring = "Error"
  1033. End If
  1034. Return episodestring
  1035. End Function
  1036. Private Function ep_add(ByVal alleps As List(Of TvEpisode), ByVal path As String, ByVal show As String)
  1037. tvScraperLog = tvScraperLog & "!!! Saving episode" & vbCrLf
  1038. WorkingWithNfoFiles.ep_NfoSave(alleps, path)
  1039. tvScraperLog &= tv_EpisodeFanartGet(alleps(0), Pref.autoepisodescreenshot) & vbcrlf
  1040. If Pref.autorenameepisodes = True Then
  1041. Dim eps As New List(Of String)
  1042. eps.Clear()
  1043. For Each ep In alleps
  1044. eps.Add(ep.Episode.Value)
  1045. Next
  1046. Dim tempspath As String = TVShows.episodeRename(path, alleps(0).Season.Value, eps, show, alleps(0).Title.Value, Pref.TvRenameReplaceSpace, Pref.TvRenameReplaceSpaceDot)
  1047. If tempspath <> "false" Then
  1048. path = tempspath
  1049. End If
  1050. End If
  1051. Return path
  1052. End Function
  1053. Private Function ep_getIMDbRating(ByVal epid As String, ByRef rating As String, ByRef votes As String) As Boolean
  1054. Dim aok As Boolean = True
  1055. If String.IsNullOrEmpty(epid) Then Return False
  1056. Dim url As String = String.Format("http://akas.imdb.com/title/{0}/", epid)
  1057. Dim IMDbpage As String = Utilities.DownloadTextFiles(url, True)
  1058. Dim m As Match
  1059. m = Regex.Match(IMDbpage, "<span itemprop=""ratingValue"">(.*?)</span>")
  1060. If m.Success Then rating = m.Groups(1).Value
  1061. Dim n As Match
  1062. n = Regex.Match(IMDbpage, "itemprop=""ratingCount"">(.*?)</span")
  1063. If n.Success Then votes = n.Groups(1).Value
  1064. Return rating <> ""
  1065. End Function
  1066. Public Sub ep_VideoSourcePopulate()
  1067. Try
  1068. cbTvSource.Items.Clear()
  1069. cbTvSource.Items.Add("")
  1070. For Each mset In Pref.releaseformat
  1071. cbTvSource.Items.Add(mset)
  1072. Next
  1073. cbTvSource.SelectedIndex = 0
  1074. Catch ex As Exception
  1075. #If SilentErrorScream Then
  1076. Throw ex
  1077. #End If
  1078. End Try
  1079. End Sub
  1080. ' We need to load images in this way so that they remain unlocked by the OS so we can update the fanart/poster files as needed
  1081. Public Shared Function util_ImageLoad(ByVal PicBox As PictureBox, ByVal ImagePath As String, ByVal DefaultPic As String) As Boolean
  1082. Dim PathToUse As String = DefaultPic
  1083. Dim cachename As String = ""
  1084. PicBox.Tag = Nothing
  1085. If Utilities.UrlIsValid(ImagePath) Then
  1086. cachename = Utilities.Download2Cache(ImagePath)
  1087. If cachename <> "" Then PathToUse = cachename
  1088. ElseIf File.Exists(ImagePath) Then
  1089. PathToUse = ImagePath
  1090. End If
  1091. If PathToUse = "" Then
  1092. PicBox.Image = Nothing
  1093. Exit Function
  1094. End If
  1095. Try
  1096. Using fs As New System.IO.FileStream(PathToUse, System.IO.FileMode.Open, System.IO.FileAccess.Read), ms As System.IO.MemoryStream = New System.IO.MemoryStream()
  1097. fs.CopyTo(ms)
  1098. ms.Seek(0, System.IO.SeekOrigin.Begin)
  1099. If ms.Length = 0 Then Throw New Exception()
  1100. PicBox.Image = Image.FromStream(ms)
  1101. End Using
  1102. PicBox.Tag = PathToUse
  1103. Catch
  1104. 'Image is invalid e.g. not downloaded correctly -> Delete it
  1105. Try
  1106. File.Delete(PathToUse)
  1107. Catch
  1108. End Try
  1109. Try
  1110. Using fs As New System.IO.FileStream(DefaultPic, System.IO.FileMode.Open, System.IO.FileAccess.Read), ms As System.IO.MemoryStream = New System.IO.MemoryStream()
  1111. fs.CopyTo(ms)
  1112. ms.Seek(0, System.IO.SeekOrigin.Begin)
  1113. PicBox.Image = Image.FromStream(ms)
  1114. End Using
  1115. PicBox.ImageLocation = DefaultPic
  1116. Catch
  1117. Return False
  1118. End Try
  1119. Return True
  1120. End Try
  1121. Return True
  1122. End Function
  1123. #Region "Tv Cache Routines"
  1124. Public Sub tv_CacheLoad()
  1125. Cache.TvCache.TvCachePath = Pref.workingProfile.TvCache
  1126. Cache.TvCache.Load()
  1127. TvTreeview.BeginUpdate()
  1128. Try
  1129. TvTreeview.Nodes.Clear() 'clear the treeview of old data
  1130. ''Dirty work around until TvShows is repalced with TvCache.Shows universally
  1131. For Each TvShow As Media_Companion.TvShow In Cache.TvCache.Shows
  1132. 'TvShow.UpdateTreenode()
  1133. TvTreeview.Nodes.Add(TvShow.ShowNode)
  1134. TvShow.UpdateTreenode()
  1135. Next
  1136. Finally
  1137. TvTreeview.EndUpdate()
  1138. End Try
  1139. TextBox_TotTVShowCount.Text = Cache.TvCache.Shows.Count
  1140. TextBox_TotEpisodeCount.Text = Cache.TvCache.Episodes.Count
  1141. 'TvTreeview.Sort()
  1142. End Sub
  1143. Private Sub tv_CacheRefreshSelected(ByVal Show As TvShow)
  1144. tv_CacheRefresh(Show)
  1145. End Sub
  1146. Public Function Tv_CacheSave() As Boolean
  1147. Cache.TvCache.TvCachePath = Pref.workingProfile.TvCache
  1148. Cache.TvCache.Save()
  1149. Return False
  1150. End Function
  1151. Private Sub tv_CacheRefresh(Optional ByVal TvShowSelected As TvShow = Nothing) 'refresh = clear & recreate cache from nfo's
  1152. Dim nfoclass As New WorkingWithNfoFiles
  1153. frmSplash2.Text = "Refresh TV Shows..."
  1154. frmSplash2.Label1.Text = "Searching TV Folders....."
  1155. frmSplash2.Label1.Visible = True
  1156. frmSplash2.Label2.Visible = True
  1157. frmSplash2.ProgressBar1.Visible = True
  1158. frmSplash2.ProgressBar1.Maximum = Pref.tvFolders.Count ' - 1
  1159. If Pref.MultiMonitoEnabled Then
  1160. frmSplash2.Bounds = Screen.AllScreens(Form1.CurrentScreen).Bounds
  1161. frmSplash2.StartPosition = FormStartPosition.Manual
  1162. End If
  1163. If frmSplash.Visible Then frmSplash2.BringToFront
  1164. frmSplash2.Show()
  1165. Application.DoEvents()
  1166. Dim fulltvshowlist As New List(Of TvShow)
  1167. Dim fullepisodelist As New List(Of TvEpisode)
  1168. tv_RefreshLog("Starting TV Show Refresh" & vbCrLf & vbCrLf, , True)
  1169. TextBox_TotTVShowCount.Text = ""
  1170. TextBox_TotEpisodeCount.Text = ""
  1171. Me.Enabled = False
  1172. Dim nofolder As New List(Of String)
  1173. Dim prgCount As Integer = 0
  1174. Dim FolderList As New List(Of String)
  1175. If TvShowSelected IsNot Nothing Then ' if we have provided a tv show, then add just this show to the list, else scan through all of the folders
  1176. FolderList.Add(TvShowSelected.FolderPath) 'add the single show to our list
  1177. Cache.TvCache.Remove(TvShowSelected)
  1178. For Each episode In TvShowSelected.Episodes
  1179. If Pref.displayMissingEpisodes AndAlso episode.IsMissing = True Then
  1180. fullepisodelist.Add(episode)
  1181. Cache.TvCache.Remove(episode)
  1182. Else
  1183. Cache.TvCache.Remove(episode)
  1184. End If
  1185. Next
  1186. For Each showitem In Cache.TvCache.Shows
  1187. fulltvshowlist.Add(showitem)
  1188. Next
  1189. For Each episodeitem In Cache.TvCache.Episodes
  1190. fullepisodelist.Add(episodeitem)
  1191. Next
  1192. Else
  1193. For Each ep In Cache.TvCache.Episodes
  1194. If Pref.displayMissingEpisodes AndAlso ep.IsMissing = True Then
  1195. fullepisodelist.Add(ep)
  1196. End If
  1197. Next
  1198. FolderList = Pref.tvFolders ' add all folders to list to scan
  1199. Cache.TvCache.Clear() 'Full rescan means clear all old data
  1200. TvTreeview.Nodes.Clear()
  1201. realTvPaths.Clear()
  1202. End If
  1203. For Each tvfolder In FolderList
  1204. frmSplash2.Label2.Text = "(" & prgCount + 1 & "/" & Pref.tvFolders.Count & ") " & tvfolder
  1205. frmSplash2.ProgressBar1.Value = prgCount
  1206. If Not Directory.Exists(tvfolder) OrElse Not File.Exists(tvfolder & "\tvshow.nfo") Then
  1207. nofolder.Add(tvfolder)
  1208. Continue For
  1209. End If
  1210. prgCount += 1
  1211. Application.DoEvents()
  1212. Dim newtvshownfo As New TvShow
  1213. newtvshownfo.NfoFilePath = IO.Path.Combine(tvfolder, "tvshow.nfo")
  1214. newtvshownfo = nfoFunction.tvshow_NfoLoad(newtvshownfo.NfoFilePath) '.Load()
  1215. If (IsNothing(newtvshownfo.Year.Value) OrElse newtvshownfo.Year.Value.ToInt = 0) Then
  1216. If Not String.IsNullOrEmpty(newtvshownfo.Premiered.Value) AndAlso newtvshownfo.Premiered.Value.Length = 10 Then
  1217. newtvshownfo.Year.Value = newtvshownfo.Premiered.Value.Substring(0,4)
  1218. nfoclass.tvshow_NfoSave(newtvshownfo, True)
  1219. End If
  1220. End If
  1221. fulltvshowlist.Add(newtvshownfo)
  1222. Dim episodelist As New List(Of TvEpisode)
  1223. episodelist = loadepisodes(newtvshownfo, episodelist)
  1224. For Each ep In episodelist
  1225. ep.ShowId.Value = newtvshownfo.TvdbId.Value
  1226. If Pref.displayMissingEpisodes Then
  1227. For i = 0 to fullepisodelist.Count-1 'check to remove missing episode if valid episode now exists.
  1228. Dim fulep = fullepisodelist.Item(i)
  1229. If fulep.ShowObj Is Nothing Then
  1230. fullepisodelist.RemoveAt(i)
  1231. Exit For
  1232. End If
  1233. If fulep.ShowObj.Title.Value = ep.ShowObj.Title.Value AndAlso fulep.Season.Value = ep.Season.Value Then
  1234. If fulep.Episode.Value = ep.Episode.Value Then
  1235. fullepisodelist.RemoveAt(i)
  1236. Exit For
  1237. End If
  1238. End If
  1239. Next
  1240. End If
  1241. fullepisodelist.Add(ep)
  1242. Next
  1243. Next
  1244. If nofolder.Count > 0 Then
  1245. Dim mymsg As String
  1246. mymsg = (nofolder.Count).ToString + " folder/s missing or no tvshow.nfo:" + vbCrLf + vbCrLf
  1247. For Each item In nofolder
  1248. mymsg = mymsg + item + vbCrLf
  1249. Next
  1250. mymsg = mymsg + vbCrLf + "Do you wish to remove these folders" + vbCrLf + "from your list of TV Folders?" + vbCrLf
  1251. If frmSplash.Visible Then frmSplash.SendToBack()
  1252. If MsgBox(mymsg, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
  1253. tv_Showremovedfromlist(listbox6, True, nofolder)
  1254. End If
  1255. End If
  1256. frmSplash2.Label2.Visible = False
  1257. frmSplash2.Label1.Text = "Saving Cache..."
  1258. Windows.Forms.Application.DoEvents()
  1259. Tv_RefreshCacheSave(fulltvshowlist, fullepisodelist) 'save the cache file
  1260. frmSplash2.Label1.Text = "Loading Cache..."
  1261. Windows.Forms.Application.DoEvents()
  1262. tv_CacheLoad() 'reload the cache file to update the treeview
  1263. 'If Pref.fixnfoid Then cbTv_fixNFOid.CheckState = CheckState.Unchecked
  1264. Me.Enabled = True
  1265. TextBox_TotTVShowCount.Text = Cache.TvCache.Shows.Count
  1266. TextBox_TotEpisodeCount.Text = Cache.TvCache.Episodes.Count
  1267. frmSplash2.Hide()
  1268. If Not tv_IMDbID_warned And tv_IMDbID_detected Then
  1269. MessageBox.Show(tv_IMDbID_detectedMsg, "TV Show ID", MessageBoxButtons.OK, MessageBoxIcon.Information)
  1270. tv_IMDbID_warned = True
  1271. End If
  1272. tv_Filter()
  1273. BlinkTaskBar()
  1274. End Sub
  1275. Private Sub Tv_RefreshCacheSave(ByVal tvshowlist As List(Of TvShow), ByVal episodeelist As List(Of TvEpisode))
  1276. Dim tvcachepath As String = Pref.workingProfile.TvCache
  1277. Dim document As New XmlDocument
  1278. Dim root As XmlElement
  1279. Dim child As XmlElement
  1280. Dim childchild As XmlElement
  1281. Dim xmlproc As XmlDeclaration
  1282. xmlproc = document.CreateXmlDeclaration("1.0", "UTF-8", "yes")
  1283. document.AppendChild(xmlproc)
  1284. root = document.CreateElement("tvcache")
  1285. root.SetAttribute("ver", "3.5")
  1286. For Each item In tvshowlist
  1287. child = document.CreateElement("tvshow")
  1288. child.SetAttribute("NfoPath", item.NfoFilePath)
  1289. childchild = document.CreateElement("state")
  1290. childchild.InnerText = item.State '"0"
  1291. child.AppendChild(childchild)
  1292. childchild = document.CreateElement("title")
  1293. childchild.InnerText = item.Title.Value
  1294. child.AppendChild(childchild)
  1295. childchild = document.CreateElement("id")
  1296. childchild.InnerText = item.TvdbId.Value
  1297. child.AppendChild(childchild)
  1298. childchild = document.CreateElement("status")
  1299. childchild.InnerText = item.Status.Value
  1300. child.AppendChild(childchild)
  1301. childchild = document.CreateElement("plot")
  1302. childchild.InnerText = item.Plot.Value
  1303. child.AppendChild(childchild)
  1304. childchild = document.CreateElement("sortorder")
  1305. childchild.InnerText = item.SortOrder.Value
  1306. child.AppendChild(childchild)
  1307. childchild = document.CreateElement("language")
  1308. childchild.InnerText = item.Language.Value
  1309. child.AppendChild(childchild)
  1310. childchild = document.CreateElement("episodeactorsource")
  1311. childchild.InnerText = item.EpisodeActorSource.Value
  1312. child.AppendChild(childchild)
  1313. childchild = document.CreateElement("imdbid")
  1314. childchild.InnerText = item.ImdbId.Value
  1315. child.AppendChild(childchild)
  1316. childchild = document.CreateElement("playcount")
  1317. childchild.InnerText = item.Playcount.Value
  1318. child.AppendChild(childchild)
  1319. childchild = document.CreateElement("hidden")
  1320. childchild.InnerText = item.Hidden.Value
  1321. child.AppendChild(childchild)
  1322. root.AppendChild(child)
  1323. Next
  1324. For Each item In episodeelist
  1325. child = document.CreateElement("episodedetails")
  1326. child.SetAttribute("NfoPath", item.NfoFilePath)
  1327. childchild = document.CreateElement("missing")
  1328. childchild.InnerText = item.IsMissing
  1329. child.AppendChild(childchild)
  1330. childchild = document.CreateElement("title")
  1331. childchild.InnerText = item.Title.Value
  1332. child.AppendChild(childchild)
  1333. childchild = document.CreateElement("season")
  1334. childchild.InnerText = item.Season.Value
  1335. child.AppendChild(childchild)
  1336. childchild = document.CreateElement("episode")
  1337. childchild.InnerText = item.Episode.Value
  1338. child.AppendChild(childchild)
  1339. childchild = document.CreateElement("aired")
  1340. childchild.InnerText = item.Aired.Value
  1341. child.AppendChild(childchild)
  1342. childchild = document.CreateElement("showid")
  1343. childchild.InnerText = item.ShowId.Value
  1344. child.AppendChild(childchild)
  1345. childchild = document.CreateElement("uniqueid")
  1346. childchild.InnerText = item.UniqueId.Value
  1347. child.AppendChild(childchild)
  1348. childchild = document.CreateElement("epextn")
  1349. childchild.InnerText = item.EpExtn.Value
  1350. child.AppendChild(childchild)
  1351. childchild = document.CreateElement("playcount")
  1352. childchild.InnerText = item.PlayCount.Value
  1353. child.AppendChild(childchild)
  1354. root.AppendChild(child)
  1355. Next
  1356. document.AppendChild(root)
  1357. Dim output As New XmlTextWriter(tvcachepath, System.Text.Encoding.UTF8)
  1358. output.Formatting = Formatting.Indented
  1359. document.WriteTo(output)
  1360. output.Close()
  1361. End Sub
  1362. Private Function loadepisodes(ByVal newtvshownfo As TvShow, ByRef episodelist As List(Of TvEpisode))
  1363. Dim missingeppath As String = Utilities.MissingPath
  1364. Dim newlist As New List(Of String)
  1365. newlist.Clear()
  1366. newlist = Utilities.EnumerateFolders(newtvshownfo.FolderPath) 'TODO: Restore loging functions
  1367. newlist.Add(newtvshownfo.FolderPath)
  1368. For Each folder In newlist
  1369. If folder = "long_path" Then
  1370. Continue For
  1371. End If
  1372. Dim dir_info As New System.IO.DirectoryInfo(folder)
  1373. Dim fs_infos() As System.IO.FileInfo = dir_info.GetFiles("*.NFO", SearchOption.TopDirectoryOnly)
  1374. For Each fs_info As System.IO.FileInfo In fs_infos
  1375. If IO.Path.GetFileName(fs_info.FullName.ToLower) <> "tvshow.nfo" And fs_info.ToString.Substring(0, 2) <> "._" Then
  1376. Dim EpNfoPath As String = fs_info.FullName
  1377. If ep_NfoValidate(EpNfoPath) Then
  1378. Dim multiepisodelist As New List(Of TvEpisode)
  1379. Dim need2resave As Boolean = False
  1380. multiepisodelist = ep_NfoLoad(EpNfoPath)
  1381. For Each Ep In multiepisodelist
  1382. If Ep.ShowId.Value <> newtvshownfo.TvdbId.Value AndAlso newtvshownfo.TvdbId.Value <> "" Then need2resave = True
  1383. Ep.ShowObj = newtvshownfo
  1384. Dim missingNfoPath As String = missingeppath & newtvshownfo.TvdbId.Value & "." & Ep.Season.Value & "." & Ep.Episode.Value & ".nfo"
  1385. If IO.File.Exists(missingNfoPath) Then Utilities.SafeDeleteFile(missingNfoPath)
  1386. episodelist.Add(Ep)
  1387. Next
  1388. If need2resave Then ep_NfoSave(multiepisodelist, EpNfoPath) 'If new ShowID stored, resave episode nfo.
  1389. End If
  1390. End If
  1391. Next fs_info
  1392. Next
  1393. Return episodelist
  1394. End Function
  1395. Private Sub tv_ShowListLoad()
  1396. If TextBox26.Text <> "" Then
  1397. messbox = New frmMessageBox("Please wait,", "", "Getting possible TV Shows from TVDB")
  1398. System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
  1399. messbox.Show()
  1400. Me.Refresh()
  1401. messbox.Refresh()
  1402. Try
  1403. Dim tvdbstuff As New TVDBScraper
  1404. Dim mirror As List(Of String) = tvdbstuff.getmirrors()
  1405. Dim showslist As String = tvdbstuff.findshows(TextBox26.Text, mirror(0))
  1406. listOfShows.Clear()
  1407. If showslist = "error" Then
  1408. messbox.Close()
  1409. MsgBox("TVDB seems to have an error with the xml for this search")
  1410. Exit Sub
  1411. End If
  1412. If showslist <> "none" Then
  1413. Dim showlist As New XmlDocument
  1414. showlist.LoadXml(showslist)
  1415. For Each thisresult As XmlNode In showlist("allshows")
  1416. Select Case thisresult.Name
  1417. Case "show"
  1418. Dim results As XmlNode = Nothing
  1419. Dim lan As New str_PossibleShowList(SetDefaults)
  1420. For Each results In thisresult.ChildNodes
  1421. Select Case results.Name
  1422. Case "showid"
  1423. lan.showid = results.InnerText
  1424. Case "showtitle"
  1425. lan.showtitle = results.InnerText
  1426. Case "showbanner"
  1427. lan.showbanner = results.InnerText
  1428. End Select
  1429. Next
  1430. Dim exists As Boolean = False
  1431. For Each item In listOfShows
  1432. If item.showid = lan.showid Then
  1433. exists = True
  1434. Exit For
  1435. End If
  1436. Next
  1437. If exists = False Then listOfShows.Add(lan)
  1438. End Select
  1439. Next
  1440. Else
  1441. Dim lan As New str_PossibleShowList(SetDefaults)
  1442. lan.showid = "none"
  1443. lan.showtitle = "TVDB Search Returned Zero Results"
  1444. lan.showbanner = Nothing
  1445. listOfShows.Add(lan)
  1446. lan.showid = "none"
  1447. lan.showtitle = "Adjust the TV Shows Title & search again"
  1448. lan.showbanner = Nothing
  1449. listOfShows.Add(lan)
  1450. End If
  1451. ListBox3.Items.Clear()
  1452. For Each item In listOfShows
  1453. ListBox3.Items.Add(item.showtitle)
  1454. Next
  1455. ListBox3.SelectedIndex = 0
  1456. If listOfShows(0).showbanner <> Nothing Then
  1457. Try
  1458. util_ImageLoad(PictureBox9, listOfShows(0).showbanner, Utilities.DefaultTvBannerPath)
  1459. Catch ex As Exception
  1460. PictureBox9.Image = Nothing
  1461. End Try
  1462. End If
  1463. Call util_LanguageCheck()
  1464. messbox.Close()
  1465. Catch
  1466. If Not IsNothing(messbox) Then messbox.Close()
  1467. Throw New Exception()
  1468. End Try
  1469. Else
  1470. MsgBox("Please Enter a Search Term")
  1471. End If
  1472. End Sub
  1473. Private Sub Tv_CacheCheckDuplicates()
  1474. Dim progress As String = "" '"Duplicates Found in:" & vbCrLf & vbcrlf
  1475. Dim Showfound As String = ""
  1476. Dim Episodesfound As String = ""
  1477. Dim Count As Integer = 0
  1478. Dim lasttestedseason As String = ""
  1479. Dim lasttestedepisode As String = ""
  1480. For Each sh In Cache.TvCache.shows
  1481. If Not String.IsNullOrEmpty(sh.TvdbId.Value) Then
  1482. Dim unique As Integer = 0
  1483. Dim shid As Integer = 0
  1484. Showfound = sh.Title.Value
  1485. For Each episo In sh.episodes
  1486. If String.IsNullOrEmpty(episo.ShowId.Value) Then shid +=1
  1487. If String.IsNullOrEmpty(episo.UniqueId.Value) Then unique +=1
  1488. If Not String.IsNullOrEmpty(episo.ShowId.Value) Then
  1489. Dim Thisseason As String = episo.Season.Value
  1490. Dim Thisepisode As String = episo.Episode.Value
  1491. If Thisseason = lasttestedseason AndAlso Thisepisode = lasttestedepisode Then Continue For
  1492. Dim testShow As String = episo.ShowId.Value
  1493. For Each testep In sh.episodes
  1494. If Not String.IsNullOrEmpty(testep.ShowId.Value) AndAlso testep.ShowId.Value = testShow Then
  1495. If testep.Season.Value = Thisseason Then
  1496. If testep.Episode.Value = Thisepisode Then
  1497. Count += 1
  1498. Episodesfound &= testep.NfoFilePath & vbcrlf
  1499. End If
  1500. End If
  1501. End If
  1502. Next
  1503. If Count > 1 Then
  1504. progress &= "Duplicates Found in:" & vbCrLf & vbcrlf
  1505. progress &= Showfound & vbCrLf & Episodesfound & vbCrLf & vbcrlf
  1506. End If
  1507. Count = 0
  1508. Episodesfound = ""
  1509. lasttestedseason = Thisseason
  1510. lasttestedepisode = Thisepisode
  1511. End If
  1512. Next
  1513. If shid > 0 Then
  1514. progress &= "Show:- " & sh.Title.Value & vbCrLf & "contains: - """ & shid & """ episodes without valid Tvdb Id!" & vbcrlf & vbcrlf
  1515. End If
  1516. If unique > 0 Then
  1517. progress &= "Show:- " & sh.Title.Value & vbCrLf & "contains: - """ & unique & """ episodes without valid <uniqueid> Tag!" & vbcrlf & vbcrlf
  1518. End If
  1519. Else
  1520. progress &= "Show:- " & sh.Title.Value & vbCrLf & "does not have a TVDB ID. Skipped for checking Duplicates" & vbcrlf & vbcrlf
  1521. End If
  1522. Showfound = ""
  1523. Next
  1524. If Not progress = "" Then
  1525. Dim MyFormObject As New frmoutputlog(progress, True, True)
  1526. MyFormObject.ShowDialog()
  1527. Else
  1528. MsgBox ("No Duplicates found")
  1529. End If
  1530. End Sub
  1531. #End Region
  1532. Private Sub bckgrnd_tvshowscraper_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bckgrnd_tvshowscraper.DoWork
  1533. Try
  1534. Statusstrip_Enable()
  1535. Dim nfoFunction As New WorkingWithNfoFiles
  1536. Dim args As TvdbArgs = e.Argument
  1537. Dim searchTVDbID As String = If(IsNothing(args), "", args.tvdbid)
  1538. Dim searchLanguage As String = If(IsNothing(args), Pref.TvdbLanguageCode, args.lang)
  1539. Dim haveTVDbID As Boolean = Not String.IsNullOrEmpty(searchTVDbID)
  1540. Dim success As Boolean = False
  1541. Dim i As Integer = 0
  1542. Dim x As String = newTvFolders.Count.ToString
  1543. Do While newTvFolders.Count > 0
  1544. tvprogresstxt = ""
  1545. i += 1
  1546. Dim NewShow As New TvShow
  1547. NewShow.NfoFilePath = IO.Path.Combine(newTvFolders(0), "tvshow.nfo")
  1548. NewShow.TvdbId.Value = searchTVDbID
  1549. NewShow.State = Media_Companion.ShowState.Unverified
  1550. tvprogresstxt &= "Scraping Show " & i.ToString & " of " & x & " : "
  1551. bckgrnd_tvshowscraper.ReportProgress(0, tvprogresstxt)
  1552. If Not haveTVDbID And NewShow.FileContainsReadableXml Then
  1553. Dim validcheck As Boolean = nfoFunction.tv_NfoLoadCheck(NewShow.NfoFilePath)
  1554. If validcheck Then
  1555. NewShow = nfoFunction.tvshow_NfoLoad(NewShow.NfoFilePath) '.Load()
  1556. End If
  1557. Else
  1558. If haveTVDbID Then
  1559. NewShow.State = Media_Companion.ShowState.Open
  1560. Else
  1561. 'Resolve show name from folder
  1562. Dim FolderName As String = Utilities.GetLastFolder(newTvFolders(0) & "\")
  1563. If FolderName.ToLower.Contains(excludefromshowfoldername.ToLower) Then
  1564. Dim indx As Integer = FolderName.ToLower.IndexOf(excludefromshowfoldername.ToLower)
  1565. Dim excludearticle As String = FolderName.Substring(indx-1, excludefromshowfoldername.Length+1)
  1566. FolderName = FolderName.Replace(excludearticle, "")
  1567. End If
  1568. FolderName = FolderName.Replace(excludefromshowfoldername, "")
  1569. Dim M As Match
  1570. M = Regex.Match(FolderName, "\s*[\(\{\[](?<date>[\d]{4})[\)\}\]]")
  1571. If M.Success = True Then
  1572. FolderName = String.Format("{0} ({1})", FolderName.Substring(0, M.Index), M.Groups("date").Value)
  1573. End If
  1574. NewShow.Title.Value = FolderName
  1575. If NewShow.PossibleShowList IsNot Nothing Then
  1576. Dim TempSeries As New Tvdb.Series
  1577. TempSeries = Tvdb.FindBestPossibleShow(NewShow.PossibleShowList, NewShow.Title.Value, searchLanguage)
  1578. If TempSeries.Similarity > 0.9 AndAlso TempSeries.Language.Value = searchLanguage Then
  1579. NewShow.State = Media_Companion.ShowState.Open
  1580. End If
  1581. searchTVDbID = TempSeries.Id.Value
  1582. End If
  1583. End If
  1584. If Not String.IsNullOrEmpty(searchTVDbID) Then
  1585. Dim tvdbstuff As New TVDBScraper
  1586. Dim SeriesInfo As Tvdb.ShowData = tvdbstuff.GetShow(searchTVDbID, searchLanguage, SeriesXmlPath)
  1587. searchTVDbID = ""
  1588. If SeriesInfo.FailedLoad Then
  1589. MsgBox("Please adjust the TV Show title and try again", _
  1590. MsgBoxStyle.OkOnly, _
  1591. String.Format("'{0}' - No Show Returned", NewShow.Title.Value))
  1592. bckgrnd_tvshowscraper.ReportProgress(1, NewShow)
  1593. newTvFolders.RemoveAt(0)
  1594. Continue Do
  1595. End If
  1596. tvprogresstxt &= "Show Title: " & SeriesInfo.Series(0).SeriesName.Value & " "
  1597. bckgrnd_tvshowscraper.ReportProgress(0, tvprogresstxt)
  1598. NewShow.AbsorbTvdbSeries(SeriesInfo.Series(0))
  1599. NewShow.Language.Value = searchLanguage
  1600. If Pref.tvdbIMDbRating Then
  1601. Dim ratingdone As Boolean = False
  1602. Dim rating As String = ""
  1603. Dim votes As String = ""
  1604. If ep_getIMDbRating(NewShow.ImdbId.Value, rating, votes) Then
  1605. If rating <> "" Then
  1606. ratingdone = True
  1607. NewShow.Rating.Value = rating
  1608. NewShow.Votes.Value = votes
  1609. End If
  1610. End If
  1611. If Not ratingdone Then
  1612. NewShow.Rating.Value = SeriesInfo.Series(0).Rating.Value
  1613. NewShow.Votes.Value = SeriesInfo.Series(0).RatingCount.Value
  1614. End If
  1615. End If
  1616. tvprogresstxt &= " - Getting Actors"
  1617. bckgrnd_tvshowscraper.ReportProgress(0, tvprogresstxt)
  1618. If Pref.TvdbActorScrape = 0 Or Pref.TvdbActorScrape = 3 Or NewShow.ImdbId.Value = Nothing Then
  1619. success = TvGetActorTvdb(NewShow)
  1620. End If
  1621. If (Pref.TvdbActorScrape = 1 Or Pref.TvdbActorScrape = 2) And NewShow.ImdbId.Value <> Nothing Then
  1622. success = TvGetActorImdb(NewShow)
  1623. End If
  1624. If success Then
  1625. tvprogresstxt &= ": -OK!"
  1626. Else
  1627. tvprogresstxt &= ": -error!!"
  1628. End If
  1629. If Pref.TvFanartTvFirst Then
  1630. If Pref.TvDlFanartTvArt OrElse Pref.TvChgShowDlFanartTvArt Then
  1631. tvprogresstxt &= " - Getting FanartTv Artwork"
  1632. bckgrnd_tvshowscraper.ReportProgress(0, tvprogresstxt)
  1633. TvFanartTvArt(NewShow, False)
  1634. End If
  1635. If Pref.tvdlfanart Or Pref.tvdlposter or Pref.tvdlseasonthumbs Then
  1636. tvprogresstxt &= " - Getting TVDB artwork"
  1637. bckgrnd_tvshowscraper.ReportProgress(0, tvprogresstxt)
  1638. success = TvGetArtwork(NewShow, True, True, True, Pref.dlTVxtrafanart, langu:=searchLanguage)
  1639. If success Then
  1640. tvprogresstxt &= ": OK!"
  1641. Else
  1642. tvprogresstxt &= ": error!!"
  1643. End If
  1644. End If
  1645. Else
  1646. If Pref.tvdlfanart Or Pref.tvdlposter or Pref.tvdlseasonthumbs Then
  1647. tvprogresstxt &= " - Getting TVDB artwork"
  1648. bckgrnd_tvshowscraper.ReportProgress(0, tvprogresstxt)
  1649. success = TvGetArtwork(NewShow, True, True, True, Pref.dlTVxtrafanart, langu:=searchLanguage)
  1650. If success Then
  1651. tvprogresstxt &= ": OK!"
  1652. Else
  1653. tvprogresstxt &= ": error!!"
  1654. End If
  1655. End If
  1656. If Pref.TvDlFanartTvArt OrElse Pref.TvChgShowDlFanartTvArt Then
  1657. tvprogresstxt &= " - Getting FanartTv Artwork"
  1658. bckgrnd_tvshowscraper.ReportProgress(0, tvprogresstxt)
  1659. TvFanartTvArt(NewShow, Pref.TvChgShowDlFanartTvArt)
  1660. End If
  1661. End If
  1662. tvprogresstxt &= " - Completed. Saving Show."
  1663. bckgrnd_tvshowscraper.ReportProgress(0, tvprogresstxt)
  1664. If Pref.TvdbActorScrape = 0 Or Pref.TvdbActorScrape = 2 Then
  1665. NewShow.EpisodeActorSource.Value = "tvdb"
  1666. Else
  1667. NewShow.EpisodeActorSource.Value = "imdb"
  1668. End If
  1669. If Pref.TvdbActorScrape = 0 Or Pref.TvdbActorScrape = 3 Then
  1670. NewShow.TvShowActorSource.Value = "tvdb"
  1671. Else
  1672. NewShow.TvShowActorSource.Value = "imdb"
  1673. End If
  1674. NewShow.SortOrder.Value = Pref.sortorder
  1675. nfoFunction.tvshow_NfoSave(NewShow, True)
  1676. 'NewShow.Save()
  1677. End If
  1678. End If
  1679. Cache.TvCache.Add(NewShow)
  1680. If Not NewShow.FailedLoad Then 'If show fails to scrape, do not add episodes to cache.
  1681. Dim episodelist As New List(Of TvEpisode)
  1682. episodelist = loadepisodes(NewShow, episodelist)
  1683. For Each ep In episodelist
  1684. NewShow.AddEpisode(ep)
  1685. Next
  1686. TvCheckfolderjpgart(NewShow)
  1687. Else 'If failed, save nfo so users can change Series.
  1688. 'nfoFunction.tvshow_NfoSave(NewShow, True)
  1689. End If
  1690. If newTvFolders.Count > 0 AndAlso Not Pref.tvFolders.Contains(newTvFolders(0)) Then
  1691. Pref.tvFolders.Add(newTvFolders(0))
  1692. End If
  1693. bckgrnd_tvshowscraper.ReportProgress(1, NewShow)
  1694. If newTvFolders.Count > 0 Then newTvFolders.RemoveAt(0)
  1695. Loop
  1696. Catch ex As Exception
  1697. ExceptionHandler.LogError(ex)
  1698. End Try
  1699. End Sub
  1700. Private Sub bckgrnd_tvshowscraper_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bckgrnd_tvshowscraper.RunWorkerCompleted
  1701. Try
  1702. ToolStripStatusLabel5.Text = "Saving data"
  1703. Tv_CacheSave()
  1704. tv_CacheLoad()
  1705. tv_Filter()
  1706. 'ToolStripStatusLabel5.Text = "Populating shows"
  1707. 'tv_CacheRefresh()
  1708. ToolStripStatusLabel5.Visible = False
  1709. Statusstrip_Enable(False)
  1710. BlinkTaskBar
  1711. GC.Collect()
  1712. Catch ex As Exception
  1713. ExceptionHandler.LogError(ex)
  1714. End Try
  1715. End Sub
  1716. Private Sub bckgrnd_tvshowscraper_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bckgrnd_tvshowscraper.ProgressChanged
  1717. Try
  1718. If e.ProgressPercentage = 0 Then
  1719. ToolStripStatusLabel5.Text = e.UserState
  1720. ToolStripStatusLabel5.Visible = True
  1721. Else
  1722. Dim NewShow As TvShow = e.UserState
  1723. ToolStripStatusLabel5.Text = "Scraping TV Shows, " & newTvFolders.Count & " remaining"
  1724. ToolStripStatusLabel5.Visible = True
  1725. realTvPaths.Add(NewShow.FolderPath)
  1726. TvTreeview.Nodes.Add(NewShow.ShowNode)
  1727. NewShow.UpdateTreenode()
  1728. TextBox_TotTVShowCount.Text = Cache.TvCache.Shows.Count
  1729. TextBox_TotEpisodeCount.Text = Cache.TvCache.Episodes.Count
  1730. 'Me.BringToFront()
  1731. 'Me.Activate()
  1732. End If
  1733. Catch ex As Exception
  1734. ExceptionHandler.LogError(ex)
  1735. End Try
  1736. End Sub
  1737. Private Sub tvbckrescrapewizard_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles tvbckrescrapewizard.DoWork
  1738. Try
  1739. 'Statusstrip_Enable()
  1740. 'ToolStripStatusLabel8.Visible = True
  1741. 'ToolStripProgressBar7.Visible = True
  1742. 'Application.DoEvents()
  1743. Dim showprocesscount As Integer = 0
  1744. Dim progresstext As String = ""
  1745. Dim progress As Integer = 0
  1746. Dim progcount As Integer = 0
  1747. 'Dim singleshnum As Integer = 0
  1748. Dim shcachecount As Integer = Cache.TvCache.Shows.Count
  1749. Dim done As Integer = 0
  1750. 'Dim SelectedShow As TvShow
  1751. If singleshow Then
  1752. showslist = tv_ShowSelectedCurrently(TvTreeview)
  1753. For x = Cache.TvCache.Shows.Count - 1 To 0 Step -1
  1754. If Cache.TvCache.Shows(x).Title.Value = showslist.Title.Value Then
  1755. shcachecount = x + 1
  1756. Exit For
  1757. End If
  1758. Next
  1759. End If
  1760. For f = shcachecount - 1 To 0 Step -1
  1761. If Cache.TvCache.Shows(f).State = Media_Companion.ShowState.Open Or Cache.TvCache.Shows(f).State = -1 Or tvBatchList.includeLocked = True Then
  1762. If tvBatchList.doEpisodes = True Then
  1763. showprocesscount += (Cache.TvCache.Shows(f).Episodes.Count - Cache.TvCache.Shows(f).MissingEpisodes.Count)
  1764. showprocesscount += 1
  1765. progcount += 1
  1766. Else
  1767. showprocesscount += 1
  1768. progcount += 1
  1769. End If
  1770. End If
  1771. If singleshow Then Exit For
  1772. Next
  1773. Dim showsdone As Integer = 0
  1774. Dim showcounter As Integer = 0
  1775. For f = shcachecount - 1 To 0 Step -1
  1776. If tvBatchList.RewriteAllNFOs Then
  1777. If Cache.TvCache.Shows(f).State = 0 Or tvBatchList.includeLocked = True Then
  1778. Dim SelectedSeries As New TvShow
  1779. SelectedSeries = nfoFunction.tvshow_NfoLoad(Cache.TvCache.Shows(f).NfoFilePath)
  1780. Call FixTvActorsNfo(SelectedSeries)
  1781. Call nfoFunction.tvshow_NfoSave(SelectedSeries, True)
  1782. For g = Cache.TvCache.Shows(f).Episodes.Count - 1 To 0 Step -1
  1783. Dim epcount As Integer = Cache.TvCache.Shows(f).Episodes.Count
  1784. progresstext = "Rewriting nfo's of Show: " & Cache.TvCache.Shows(f).Title.Value & ", Episode: " & epcount - g & " of " & epcount & ", Episode: " & Cache.TvCache.Shows(f).Episodes(g).Season.Value & "x" & Cache.TvCache.Shows(f).Episodes(g).Episode.Value & " - " & Cache.TvCache.Shows(f).Episodes(g).Title.Value
  1785. If done > 0 Then
  1786. progress = (100 / showprocesscount) * done
  1787. Else
  1788. progress = 0
  1789. End If
  1790. If Cache.TvCache.Shows(f).Episodes(g).IsMissing Then
  1791. progresstext &= "Skip Missing episode"
  1792. Continue For
  1793. End If
  1794. tvbckrescrapewizard.ReportProgress(progress, progresstext)
  1795. Dim listofepisodes As New List(Of TvEpisode)
  1796. listofepisodes.Clear()
  1797. listofepisodes = WorkingWithNfoFiles.ep_NfoLoad(Cache.TvCache.Shows(f).Episodes(g).NfoFilePath)
  1798. WorkingWithNfoFiles.ep_NfoSave(listofepisodes, listofepisodes(0).NfoFilePath)
  1799. Next
  1800. End If
  1801. If singleshow Then Exit For
  1802. Continue For
  1803. End If
  1804. If Cache.TvCache.Shows(f).State = Media_Companion.ShowState.Open OrElse Cache.TvCache.Shows(f).State = -1 OrElse tvBatchList.includeLocked = True Then
  1805. showcounter += 1
  1806. progresstext = "Working on Show: " & showcounter.ToString & " of " & progcount
  1807. If done > 0 Then
  1808. progress = (100 / showprocesscount) * done
  1809. Else
  1810. progress = 0
  1811. End If
  1812. tvbckrescrapewizard.ReportProgress(progress, progresstext)
  1813. Dim editshow As New TvShow
  1814. editshow = nfoFunction.tv_NfoLoadFull(Cache.TvCache.Shows(f).NfoFilePath)
  1815. If tvBatchList.doShowActors Then
  1816. editshow.ListActors.Clear()
  1817. End If
  1818. Dim tvdbstuff As New TVDBScraper
  1819. Dim tvseriesdata As New Tvdb.ShowData
  1820. Dim language As String = editshow.Language.Value
  1821. If language = "" Then language = "en"
  1822. If tvBatchList.shSeries Then
  1823. Dim aok As Boolean = tvdbstuff.GetSeriesXml(editshow.TvdbId.Value, language, SeriesXmlPath)
  1824. If aok Then
  1825. progresstext &= "Updated Series.xml data"
  1826. Else
  1827. progresstext &= "Failed to update xml data"
  1828. End If
  1829. tvbckrescrapewizard.ReportProgress(progress, progresstext)
  1830. If singleshow Then Exit For
  1831. Continue For
  1832. End If
  1833. tvseriesdata = tvdbstuff.GetShow(editshow.TvdbId.Value, language, SeriesXmlPath)
  1834. If tvseriesdata.FailedLoad Then
  1835. progresstext &= "Failed to load xml data"
  1836. tvbckrescrapewizard.ReportProgress(progress, progresstext)
  1837. Continue For
  1838. End If
  1839. If tvBatchList.doShows = True Then
  1840. If tvBatchList.doShowBody = True Or tvBatchList.doShowActors = True Then
  1841. Try
  1842. editshow.ImdbId.Value = tvseriesdata.Series(0).ImdbId.Value
  1843. If tvBatchList.shMpaa Then editshow.Mpaa.Value = tvseriesdata.Series(0).ContentRating.Value
  1844. If tvBatchList.shYear Then
  1845. editshow.Premiered.Value = tvseriesdata.Series(0).FirstAired.Value
  1846. If Not String.IsNullOrEmpty(editshow.Premiered.Value) Then editshow.Year.Value = editshow.Premiered.Value.Substring(0,4)
  1847. End If
  1848. If tvBatchList.shGenre Then
  1849. Dim newstring As String
  1850. newstring = tvseriesdata.Series(0).Genre.Value
  1851. newstring = newstring.TrimEnd("|")
  1852. newstring = newstring.TrimStart("|")
  1853. Dim strsplt() As String = newstring.Split("|")
  1854. Dim counter As Integer = 0
  1855. newstring = ""
  1856. For i = 0 To strsplt.Count-1
  1857. If i = Pref.TvMaxGenres Then Exit For
  1858. If newstring = "" Then
  1859. newstring = strsplt(i)
  1860. Else
  1861. newstring &= " / " & strsplt(i)
  1862. End If
  1863. Next
  1864. 'newstring = newstring.Replace("|", " / ")
  1865. editshow.Genre.Value = newstring
  1866. End If
  1867. If tvBatchList.shStudio Then editshow.Studio.Value = tvseriesdata.Series(0).Network.Value
  1868. If tvBatchList.shPlot Then editshow.Plot.Value = tvseriesdata.Series(0).Overview.Value
  1869. 'If tvBatchList.shRating Then editshow.Rating.Value = tvseriesdata.Series(0).Rating.Value
  1870. If tvBatchList.shRuntime Then editshow.Runtime.Value = tvseriesdata.Series(0).RunTime.Value
  1871. If tvBatchList.shStatus Then editshow.Status.Value = tvseriesdata.Series(0).Status.Value
  1872. Dim episodeguideurl As String = "http://www.thetvdb.com/api/6E82FED600783400/series/" & editshow.TvdbId.Value & "/all/" & language & ".zip"
  1873. editshow.EpisodeGuideUrl.Value = ""
  1874. editshow.Url.Value = episodeguideurl
  1875. editshow.Url.Node.SetAttributeValue("cache", editshow.TvdbId.Value)
  1876. editshow.Url.AttachToParentNode(editshow.EpisodeGuideUrl.Node)
  1877. If tvBatchList.shRating Then
  1878. Dim ratingdone As Boolean = False
  1879. If Pref.tvdbIMDbRating Then
  1880. Dim rating As String = ""
  1881. Dim votes As String = ""
  1882. If ep_getIMDbRating(editshow.ImdbId.Value, rating, votes) Then
  1883. If rating <> "" Then
  1884. ratingdone = True
  1885. editshow.Rating.Value = rating
  1886. editshow.Votes.Value = votes
  1887. End If
  1888. End If
  1889. End If
  1890. If Not ratingdone Then
  1891. editshow.Rating.Value = tvseriesdata.Series(0).Rating.Value
  1892. editshow.Votes.Value = tvseriesdata.Series(0).RatingCount.Value
  1893. End If
  1894. End If
  1895. If tvBatchList.doShowActors = True Then
  1896. If editshow.TvShowActorSource.Value = Nothing Then
  1897. If Pref.TvdbActorScrape = 0 Or Pref.TvdbActorScrape = 3 Then
  1898. editshow.TvShowActorSource.Value = "tvdb"
  1899. Else
  1900. editshow.TvShowActorSource.Value = "imdb"
  1901. End If
  1902. End If
  1903. If editshow.TvShowActorSource.Value = "tvdb" Then TvGetActorTvdb(editshow)
  1904. If editshow.TvShowActorSource.Value = "imdb" Then TvGetActorImdb(editshow)
  1905. End If
  1906. Catch ex As Exception
  1907. #If SilentErrorScream Then
  1908. Throw ex
  1909. #End If
  1910. End Try
  1911. Call nfoFunction.tvshow_NfoSave(editshow, True)
  1912. 'editshow.IsCache = True 'this doesn't stick so I had to remove the test in show.load
  1913. End If
  1914. 'Posters, Fanart and Season art
  1915. If tvBatchList.doShowArt = True Then
  1916. If tvBatchList.shDelArtwork Then TvDeleteShowArt(Cache.TvCache.Shows(f), False)
  1917. If tvBatchList.shFanart orElse tvBatchList.shPosters OrElse tvBatchList.shSeason OrElse tvBatchList.shXtraFanart Then
  1918. TvGetArtwork(Cache.TvCache.Shows(f), tvBatchList.shFanart, tvBatchList.shPosters, tvBatchList.shSeason, tvBatchList.shXtraFanart, force:= False)
  1919. End If
  1920. If tvBatchList.shFanartTvArt Then TvFanartTvArt(Cache.TvCache.Shows(f), False) 'We're only looking for missing art from Fanart.Tv
  1921. 'If selected, copy Series banner to season banner if no season banner downloaded.
  1922. If tvBatchList.shBannerMain AndAlso Pref.FrodoEnabled Then
  1923. Dim mainbanner As String = Cache.TvCache.Shows(f).ImageBanner.Path
  1924. If File.Exists(mainbanner) Then
  1925. For each seas As TvSeason In Cache.TvCache.Shows(f).Seasons.values
  1926. Dim SeasonNo As String = seas.SeasonNode.Text.Replace("Season ", "")
  1927. If SeasonNo.ToLower = "specials" Then SeasonNo = "-" & SeasonNo.ToLower
  1928. Dim SeasonBanner As String = Cache.TvCache.Shows(f).FolderPath & "season" & SeasonNo & "-banner.jpg"
  1929. If Not File.Exists(SeasonBanner) Then
  1930. Utilities.SafeCopyFile(mainbanner, SeasonBanner)
  1931. End If
  1932. Next
  1933. End If
  1934. End If
  1935. End If
  1936. End If
  1937. If tvBatchList.doEpisodes = True Then
  1938. Dim i As Integer = 0
  1939. Dim TotalEpisodes As Integer = Cache.TvCache.Shows(f).Episodes.Count - Cache.TvCache.Shows(f).MissingEpisodes.count
  1940. For g = Cache.TvCache.Shows(f).Episodes.Count - 1 To 0 Step -1
  1941. If Cache.TvCache.Shows(f).Episodes(g).IsMissing Then Continue For
  1942. i += 1
  1943. progresstext = "Working on Show: " & Cache.TvCache.Shows(f).Title.Value & " Episode: " & i & " of " & TotalEpisodes & ", Episode: " & Cache.TvCache.Shows(f).Episodes(g).Season.Value & "x" & Cache.TvCache.Shows(f).Episodes(g).Episode.Value & " - " & Cache.TvCache.Shows(f).Episodes(g).Title.Value
  1944. If done > 0 Then
  1945. progress = (100 / showprocesscount) * done
  1946. Else
  1947. progress = 0
  1948. End If
  1949. tvbckrescrapewizard.ReportProgress(progress, progresstext)
  1950. Dim actorsource As String = Cache.TvCache.Shows(f).EpisodeActorSource.Value
  1951. If actorsource = "" Then actorsource = "tvdb"
  1952. Dim Episodedata As New Tvdb.Episode
  1953. Dim epfound As Boolean = False
  1954. For Each NewEpisode As Tvdb.Episode In tvseriesdata.Episodes
  1955. If NewEpisode.SeasonNumber.Value = Cache.TvCache.Shows(f).Episodes(g).Season.Value
  1956. If NewEpisode.EpisodeNumber.Value = Cache.TvCache.Shows(f).Episodes(g).Episode.Value
  1957. Episodedata = NewEpisode
  1958. Episodedata.ThumbNail.Value = "http://www.thetvdb.com/banners/" & NewEpisode.ThumbNail.value
  1959. epfound = True
  1960. Exit For
  1961. End If
  1962. End If
  1963. Next
  1964. If Not epfound Then
  1965. Dim sortorder As String = Cache.TvCache.Shows(f).SortOrder.Value
  1966. If sortorder = "" Then sortorder = "default"
  1967. Dim tvdbid As String = Cache.TvCache.Shows(f).TvdbId.Value
  1968. Dim imdbid As String = Cache.TvCache.Shows(f).ImdbId.Value
  1969. Dim seasonno As String = Cache.TvCache.Shows(f).Episodes(g).Season.Value
  1970. Dim episodeno As String = Cache.TvCache.Shows(f).Episodes(g).Episode.Value
  1971. Episodedata = tvdbstuff.getepisodefromxml(tvdbid, sortorder, seasonno, episodeno, language, True)
  1972. If Episodedata.FailedLoad Then
  1973. progresstext = "tvdb was unable to process the following show episode." & vbCrLf & Cache.TvCache.Shows(f).Title.Value & " - S" & Utilities.PadNumber(Cache.TvCache.Shows(f).Episodes(g).Season.Value, 2) & "E" & Utilities.PadNumber(Cache.TvCache.Shows(f).Episodes(g).Episode.Value, 2) & " " & Cache.TvCache.Shows(f).Episodes(g).Title.Value
  1974. tvbckrescrapewizard.ReportProgress(progress, progresstext)
  1975. Continue For
  1976. End If
  1977. End If
  1978. If tvBatchList.doEpisodeBody Or (tvBatchList.doEpisodeActors And Cache.TvCache.Shows(f).EpisodeActorSource.Value <> "") Or (tvBatchList.doEpisodeArt) Then
  1979. Dim listofnewepisodes As New List(Of TvEpisode)
  1980. listofnewepisodes.Clear()
  1981. listofnewepisodes = WorkingWithNfoFiles.ep_NfoLoad(Cache.TvCache.Shows(f).Episodes(g).NfoFilePath) 'Generic(Cache.TvCache.Shows(f).Episodes(g).NfoFilePath)
  1982. For h = listofnewepisodes.Count - 1 To 0 Step -1
  1983. If listofnewepisodes(h).Season.Value = Cache.TvCache.Shows(f).Episodes(g).Season.Value And listofnewepisodes(h).Episode.Value = Cache.TvCache.Shows(f).Episodes(g).Episode.Value Then
  1984. Dim newactors As New List(Of str_MovieActors)
  1985. newactors.Clear()
  1986. 'its an episode
  1987. Dim episodescreenurl As String = ""
  1988. Try
  1989. listofnewepisodes(h).ImdbId.Value = Episodedata.ImdbId.Value
  1990. If tvBatchList.epAired Then listofnewepisodes(h).Aired.Value = Episodedata.FirstAired.Value
  1991. If tvBatchList.epPlot Then listofnewepisodes(h).Plot.Value = Episodedata.Overview.Value
  1992. If tvBatchList.epDirector Then listofnewepisodes(h).Director.Value = Utilities.Cleanbraced(Episodedata.Director.Value)
  1993. If tvBatchList.epCredits Then listofnewepisodes(h).Credits.Value = Utilities.Cleanbraced(Episodedata.Writer.Value)
  1994. Dim ratingdone As Boolean = False
  1995. If tvBatchList.epRating Then
  1996. If Pref.tvdbIMDbRating Then
  1997. Dim rating As String = ""
  1998. Dim votes As String = ""
  1999. If ep_getIMDbRating(listofnewepisodes(h).ImdbId.Value, rating, votes) Then
  2000. If rating <> "" Then
  2001. ratingdone = True
  2002. listofnewepisodes(h).Rating.Value = rating
  2003. listofnewepisodes(h).Votes.Value = votes
  2004. End If
  2005. End If
  2006. End If
  2007. If Not ratingdone Then
  2008. listofnewepisodes(h).Rating.Value = Episodedata.Rating.Value
  2009. listofnewepisodes(h).Votes.Value = Episodedata.Votes.Value
  2010. End If
  2011. End If
  2012. 'If tvBatchList.epRating Then listofnewepisodes(h).Rating.Value = Episodedata.Rating.Value
  2013. 'If tvBatchList.epRating Then listofnewepisodes(h).Votes.Value = Episodedata.Votes.Value
  2014. If tvBatchList.epTitle Then listofnewepisodes(h).Title.Value = Episodedata.EpisodeName.Value
  2015. listofnewepisodes(h).UniqueId.Value = Episodedata.Id.Value
  2016. listofnewepisodes(h).ShowId.Value = Episodedata.SeriesId.Value
  2017. If tvBatchList.epActor Then
  2018. If actorsource = "tvdb" Then
  2019. listofnewepisodes(h).ListActors.Clear()
  2020. Dim tempstr As String = Episodedata.GuestStars.Value
  2021. tempstr = tempstr.TrimStart("|")
  2022. tempstr = tempstr.TrimEnd("|")
  2023. Dim Tmp() As String
  2024. Tmp = tempstr.Split("|")
  2025. For Each act In Tmp
  2026. Dim newactor As New str_MovieActors
  2027. newactor.actorname = act
  2028. listofnewepisodes(h).ListActors.Add(newactor)
  2029. Next
  2030. ElseIf actorsource = "imdb" Then
  2031. Dim epid As String = GetEpImdbId(Cache.TvCache.Shows(f).ImdbId.Value, listofnewepisodes(h).Season.Value, listofnewepisodes(h).Episode.Value)
  2032. If epid.Contains("tt") Then
  2033. Dim scraperfunction As New Classimdb
  2034. Dim actorlist As List(Of str_MovieActors) = scraperfunction.GetImdbActorsList(Pref.imdbmirror, epid, Pref.maxactors)
  2035. If actorlist.Count > 0 Then
  2036. listofnewepisodes(h).ListActors.Clear()
  2037. For Each act In actorlist
  2038. listofnewepisodes(h).ListActors.Add(act)
  2039. Next
  2040. End If
  2041. End If
  2042. End If
  2043. End If
  2044. If tvBatchList.doEpisodeArt AndAlso tvBatchList.epScreenshot Then
  2045. listofnewepisodes(h).Thumbnail.FileName = Episodedata.ThumbNail.Value
  2046. progresstext = tv_EpisodeFanartGet(listofnewepisodes(h), tvBatchList.epCreateScreenshot).Replace("!!! ","")
  2047. End If
  2048. Catch ex As Exception
  2049. #If SilentErrorScream Then
  2050. Throw ex
  2051. #End If
  2052. 'MsgBox("hekp")
  2053. End Try
  2054. WorkingWithNfoFiles.ep_NfoSave(listofnewepisodes, listofnewepisodes(0).NfoFilePath)
  2055. listofnewepisodes(h).UpdateTreenode()
  2056. Exit For
  2057. End If
  2058. Next
  2059. End If
  2060. If tvBatchList.doEpisodeMediaTags = True Then
  2061. Dim listofnewepisodes As New List(Of TvEpisode)
  2062. listofnewepisodes.Clear()
  2063. listofnewepisodes = WorkingWithNfoFiles.ep_NfoLoad(Cache.TvCache.Shows(f).Episodes(g).NfoFilePath) 'Generic(Cache.TvCache.Shows(f).Episodes(g).NfoFilePath)
  2064. For h = listofnewepisodes.Count - 1 To 0 Step -1
  2065. listofnewepisodes(h).GetFileDetails()
  2066. If Not String.IsNullOrEmpty(listofnewepisodes(h).Details.StreamDetails.Video.DurationInSeconds.Value) Then
  2067. Try
  2068. Dim tempstring As String
  2069. tempstring = listofnewepisodes(h).Details.StreamDetails.Video.DurationInSeconds.Value
  2070. If Pref.intruntime Then
  2071. listofnewepisodes(h).Runtime.Value = Math.Round(tempstring / 60).ToString
  2072. Else
  2073. listofnewepisodes(h).Runtime.Value = Math.Round(tempstring / 60).ToString & " min"
  2074. End If
  2075. Catch
  2076. End Try
  2077. WorkingWithNfoFiles.ep_NfoSave(listofnewepisodes, listofnewepisodes(0).NfoFilePath)
  2078. End If
  2079. Next
  2080. End If
  2081. done += 1
  2082. Next
  2083. End If
  2084. done += 1
  2085. If singleshow Then Exit For
  2086. End If
  2087. Next
  2088. singleshow = False
  2089. Catch ex As Exception
  2090. ExceptionHandler.LogError(ex)
  2091. End Try
  2092. End Sub
  2093. Private Sub tvbckrescrapewizard_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles tvbckrescrapewizard.ProgressChanged
  2094. Try
  2095. If e.ProgressPercentage = 999999 Then
  2096. ToolStripStatusLabel8.Text = e.UserState
  2097. Else
  2098. ToolStripStatusLabel8.Text = e.UserState
  2099. ToolStripProgressBar7.Value = e.ProgressPercentage
  2100. ToolStripProgressBar7.ProgressBar.Refresh()
  2101. ToolStripProgressBar7.ProgressBar.PerformStep()
  2102. End If
  2103. Catch ex As Exception
  2104. ExceptionHandler.LogError(ex)
  2105. End Try
  2106. End Sub
  2107. Private Sub tvbckrescrapewizard_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles tvbckrescrapewizard.RunWorkerCompleted
  2108. Try
  2109. ToolStripStatusLabel8.Visible = False
  2110. ToolStripProgressBar7.Visible = False
  2111. Statusstrip_Enable(False)
  2112. TvTreeview_AfterSelect_Do()
  2113. GC.Collect()
  2114. Catch ex As Exception
  2115. ExceptionHandler.LogError(ex)
  2116. End Try
  2117. End Sub
  2118. Private Sub TV_EpisodeScraper(ByVal ListOfShows As List(Of TvShow), ByVal manual As Boolean)
  2119. Dim stage As String = "0"
  2120. Try
  2121. Dim tempstring As String = ""
  2122. Dim tempint As Integer
  2123. Dim errorcounter As Integer = 0
  2124. newEpisodeList.Clear()
  2125. Dim newtvfolders As New List(Of String)
  2126. Dim progress As Integer
  2127. progress = 0
  2128. Dim progresstext As String = String.Empty
  2129. Pref.tvScraperLog = ""
  2130. Dim ShowsScanned As Integer = 0
  2131. Dim FoldersScanned As Integer = 0
  2132. Dim ShowsLocked As Integer = 0
  2133. Dim dirpath As String = String.Empty
  2134. Dim moviepattern As String = String.Empty
  2135. If bckgroundscanepisodes.CancellationPending Then
  2136. Pref.tvScraperLog &= vbCrLf & "!!! Operation cancelled by user"
  2137. Exit Sub
  2138. End If
  2139. If Pref.tvshow_useXBMC_Scraper = True Then
  2140. Pref.tvScraperLog &= "---Using XBMC TVDB Scraper---" & vbCrLf
  2141. Else
  2142. Pref.tvScraperLog &= "---Using MC TVDB Scraper---" & vbCrLf
  2143. End If
  2144. progresstext = String.Concat("Scanning TV Folders For New Episodes...")
  2145. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2146. Pref.tvScraperLog &= "Starting Folder Scan" & vbCrLf & vbCrLf
  2147. Dim TvFolder As String
  2148. For Each TvShow As Media_Companion.TvShow In ListOfShows
  2149. TvFolder = IO.Path.GetDirectoryName(TvShow.FolderPath)
  2150. Dim Add As Boolean = True
  2151. If TvShow.State <> Media_Companion.ShowState.Open Then
  2152. If manual = False Then
  2153. Add = False
  2154. End If
  2155. End If
  2156. If Add = True Then
  2157. ShowsScanned += 1
  2158. progresstext = String.Concat("Stage 1 of 3 : Found " & newtvfolders.Count & " : Creating List of Folders From Roots : Searching - '" & TvFolder & "'")
  2159. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2160. If bckgroundscanepisodes.CancellationPending Then
  2161. Pref.tvScraperLog &= vbCrLf & "!!! Operation cancelled by user"
  2162. Exit Sub
  2163. End If
  2164. tempstring = "" 'tvfolder
  2165. Dim hg As New IO.DirectoryInfo(TvFolder)
  2166. If hg.Exists Then
  2167. scraperLog = scraperLog & "Found " & hg.FullName.ToString & vbCrLf
  2168. newtvfolders.Add(TvFolder)
  2169. scraperLog = scraperLog & "Checking for subfolders" & vbCrLf
  2170. Dim ExtraFolder As List(Of String) = Utilities.EnumerateFolders(TvFolder, 3)
  2171. For Each Item As String In ExtraFolder
  2172. If Pref.ExcludeFolders.Match(Item) Then Continue For
  2173. newtvfolders.Add(Item)
  2174. FoldersScanned += 1
  2175. Next
  2176. End If
  2177. Else
  2178. ShowsLocked += 1
  2179. End If
  2180. Next
  2181. scraperLog = scraperLog & vbCrLf
  2182. Dim mediacounter As Integer = newEpisodeList.Count
  2183. newtvfolders.Sort()
  2184. For g = 0 To newtvfolders.Count - 1
  2185. If bckgroundscanepisodes.CancellationPending Then
  2186. Pref.tvScraperLog &= vbCrLf & "!!! Operation cancelled by user"
  2187. Exit Sub
  2188. End If
  2189. progresstext = String.Concat("Stage 2 of 3 : Found " & newEpisodeList.Count & " : Searching for New Episodes in Folders " & g + 1 & " of " & newtvfolders.Count & " - '" & newtvfolders(g) & "'")
  2190. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2191. For Each f In Utilities.VideoExtensions
  2192. dirpath = newtvfolders(g)
  2193. Dim dir_info As New System.IO.DirectoryInfo(dirpath)
  2194. tv_NewFind(dirpath, f)
  2195. Next f
  2196. tempint = newEpisodeList.Count - mediacounter
  2197. mediacounter = newEpisodeList.Count
  2198. Next g
  2199. 'report so far
  2200. Pref.tvScraperLog &= "!!! Scanned """ & ShowsScanned.ToString & """ Shows." & vbCrLf
  2201. If ShowsLocked > 0 Then Pref.tvScraperLog &= "!!! Skipped """ & ShowsLocked.ToString & " Locked Shows." & vbCrLf
  2202. Pref.tvScraperLog &= "!!! Scanned """ & (ShowsScanned + FoldersScanned).ToString & """ folders (includes Show and subfolders)." & vbCrLf & vbCrLf
  2203. If newEpisodeList.Count <= 0 Then
  2204. Pref.tvScraperLog &= "!!! No new episodes found, exiting scraper." & vbCrLf
  2205. Exit Sub
  2206. Else
  2207. Pref.tvScraperLog &= "!!! """ & newEpisodeList.Count.ToString & """ Episodes found." & vbCrLf & vbCrLf
  2208. End If
  2209. Dim S As String = ""
  2210. For Each newepisode In newEpisodeList
  2211. S = ""
  2212. If bckgroundscanepisodes.CancellationPending Then
  2213. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2214. Exit Sub
  2215. End If
  2216. For Each Shows In Cache.TvCache.Shows
  2217. If bckgroundscanepisodes.CancellationPending Then
  2218. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2219. Exit Sub
  2220. End If
  2221. If newepisode.FolderPath.Contains(Shows.FolderPath) Then
  2222. If Shows.ImdbId.Value Is Nothing OrElse String.IsNullOrEmpty(Shows.Premiered.Value) Then
  2223. Shows = nfoFunction.tvshow_NfoLoad(Shows.NfoFilePath) '.Load()
  2224. End If
  2225. newepisode.ShowLang.Value = Shows.Language.Value
  2226. newepisode.sortorder.Value = Shows.SortOrder.Value
  2227. newepisode.Showtvdbid.Value = Shows.TvdbId.Value
  2228. newepisode.Showimdbid.Value = Shows.ImdbId.Value
  2229. newepisode.ShowTitle.Value = Shows.Title.Value
  2230. newepisode.ShowYear.Value = Shows.Year.Value
  2231. newepisode.ShowObj = Shows
  2232. If String.IsNullOrEmpty(newepisode.ShowYear.Value) Then
  2233. If Not String.IsNullOrEmpty(Shows.Premiered.Value) Then
  2234. Dim yr As String = Shows.Premiered.Value.Substring(0,4)
  2235. If yr.Length = 4 Then newepisode.ShowYear.Value = yr
  2236. End If
  2237. End If
  2238. newepisode.actorsource.Value = Shows.EpisodeActorSource.Value
  2239. Exit For
  2240. End If
  2241. Next
  2242. Dim episode As New TvEpisode
  2243. Dim airedgot As Boolean = False
  2244. For Each Regexs In tv_RegexScraper
  2245. S = newepisode.VideoFilePath '.ToLower
  2246. stage = "1"
  2247. Dim i As Integer 'sacrificial variable to appease the TryParseosaurus Checks
  2248. If Not String.IsNullOrEmpty(newepisode.ShowTitle.Value) AndAlso Integer.TryParse(newepisode.ShowTitle.Value, i) <> -1 Then S = S.Replace(newepisode.ShowTitle.Value, "")
  2249. stage = "2"
  2250. If Not String.IsNullOrEmpty(newepisode.ShowYear.Value) AndAlso (newepisode.ShowYear.Value.ToInt <> 0) Then
  2251. If S.Contains(newepisode.ShowYear.Value) AndAlso Not S.ToLower.Contains("s" & newepisode.ShowYear.Value) Then
  2252. S = S.Replace(newepisode.ShowYear.Value, "")
  2253. End If
  2254. End If
  2255. stage = "3"
  2256. S = S.Replace("x265" , "")
  2257. S = S.Replace("x264" , "")
  2258. S = S.Replace("720p" , "")
  2259. S = S.Replace("720i" , "")
  2260. S = S.Replace("1080p" , "")
  2261. S = S.Replace("1080i" , "")
  2262. S = S.Replace("X265" , "")
  2263. S = S.Replace("X264" , "")
  2264. S = S.Replace("720P" , "")
  2265. S = S.Replace("720I" , "")
  2266. S = S.Replace("1080P" , "")
  2267. S = S.Replace("1080I" , "")
  2268. stage = "4"
  2269. Dim N As Match
  2270. stage = "5" 'Do date test first.
  2271. N = Regex.Match(S, tv_EpRegexDate)
  2272. If N.Success Then
  2273. If Not airedgot Then
  2274. Dim aired As String = N.Groups(0).Value.Replace(".", "-").Replace("_", "-")
  2275. newepisode.Aired.Value = aired
  2276. airedgot = True
  2277. End If
  2278. If airedgot Then S = S.Replace(N.Groups(0).Value, "")
  2279. 'Exit For
  2280. End If
  2281. If Not N.Success OrElse airedgot Then
  2282. Dim M As Match
  2283. M = Regex.Match(S, Regexs)
  2284. If M.Success = True Then
  2285. Try
  2286. newepisode.Season.Value = M.Groups(1).Value.ToString
  2287. newepisode.Episode.Value = M.Groups(2).Value.ToString
  2288. Try
  2289. Dim matchvalue As String = M.Value
  2290. newepisode.Thumbnail.FileName = S.Substring(S.LastIndexOf(matchvalue)+matchvalue.Length, S.Length - (S.LastIndexOf(matchvalue) + (matchvalue.Length)))
  2291. 'newepisode.Thumbnail.FileName = S.Substring(M.Groups(2).Index + M.Groups(2).Value.Length, S.Length - (M.Groups(2).Index + M.Groups(2).Value.Length))
  2292. Catch ex As Exception
  2293. #If SilentErrorScream Then
  2294. Throw ex
  2295. #End If
  2296. End Try
  2297. Exit For
  2298. Catch
  2299. newepisode.Season.Value = "-1"
  2300. newepisode.Episode.Value = "-1"
  2301. End Try
  2302. End If
  2303. End If
  2304. Next
  2305. If newepisode.Season.Value = Nothing Then newepisode.Season.Value = "-1"
  2306. If newepisode.Episode.Value = Nothing Then newepisode.Episode.Value = "-1"
  2307. If newepisode.Season.Value <> "-1" AndAlso newepisode.Episode.Value <> "-1" Then newepisode.Aired.Value = "" 'Clear Aired value if got valid Ep and Season values.
  2308. Next
  2309. Dim savepath As String = ""
  2310. Dim scrapedok As Boolean
  2311. Dim epscount As Integer = 0
  2312. For Each eps In newEpisodeList
  2313. Dim showtitle As String = eps.ShowTitle.Value
  2314. epscount += 1
  2315. Pref.tvScraperLog &= "!!! With File : " & eps.VideoFilePath & vbCrLf
  2316. If eps.Aired.Value <> Nothing Then
  2317. Pref.tvScraperLog &= "!!! Detected : Aired Date: " & eps.Aired.Value & vbCrLf
  2318. Else
  2319. Pref.tvScraperLog &= "!!! Detected : Season : " & eps.Season.Value & " Episode : " & eps.Episode.Value & vbCrLf
  2320. End If
  2321. If eps.Season.Value = "-1" And eps.Episode.Value = "-1" AndAlso eps.Aired.Value = Nothing Then
  2322. Pref.tvScraperLog &= "!!! WARNING: Can't extract Season and Episode details from this filename, file not added!" & vbCrLf
  2323. Pref.tvScraperLog &= "!!!" & vbCrLf
  2324. Continue For 'if we can't get season or episode then skip to next episode
  2325. End If
  2326. Dim episodearray As New List(Of TvEpisode)
  2327. episodearray.Clear()
  2328. episodearray.Add(eps)
  2329. If bckgroundscanepisodes.CancellationPending Then
  2330. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2331. Exit Sub
  2332. End If
  2333. Dim WhichScraper As String = ""
  2334. If Pref.tvshow_useXBMC_Scraper = True Then
  2335. WhichScraper = "XBMC TVDB"
  2336. Else
  2337. WhichScraper = "MC TVDB"
  2338. End If
  2339. progresstext = String.Concat("ESC to Cancel : Stage 3 of 3 : Scraping New Episodes : Using " & WhichScraper & "Scraper : Scraping " & epscount & " of " & newEpisodeList.Count & " - '" & IO.Path.GetFileName(eps.VideoFilePath) & "'")
  2340. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2341. Dim removal As String = ""
  2342. If (eps.Season.Value = "-1" Or eps.Episode.Value = "-1") AndAlso eps.Aired.Value = Nothing Then
  2343. eps.Title.Value = Utilities.GetFileName(eps.VideoFilePath)
  2344. eps.Rating.Value = "0"
  2345. eps.Votes.Value = "0"
  2346. eps.PlayCount.Value = "0"
  2347. eps.Genre.Value = "Unknown Episode Season and/or Episode Number"
  2348. eps.GetFileDetails()
  2349. episodearray.Add(eps)
  2350. savepath = episodearray(0).NfoFilePath
  2351. Else
  2352. Dim temppath As String = eps.NfoFilePath
  2353. 'check for multiepisode files
  2354. Dim M2 As Match
  2355. Dim epcount As Integer = 0
  2356. Dim allepisodes(100) As Integer
  2357. stage = "5"
  2358. If Not String.IsNullOrEmpty(eps.Thumbnail.FileName) Then
  2359. S = Regex.Replace(eps.Thumbnail.FileName, "\(.*?\)", "") 'Remove anything from filename in brackets like resolution ie: (1920x1080) that may give false episode number
  2360. S = Regex.Replace(S, "\[.*?\]", "")
  2361. End If
  2362. stage = "6"
  2363. eps.Thumbnail.FileName = ""
  2364. Do
  2365. If eps.Aired.Value <> Nothing Then Exit Do
  2366. '<tvregex>[Ss]([\d]{1,2}).?[Ee]([\d]{3})</tvregex>
  2367. M2 = Regex.Match(S, "(([EeXx])([\d]{1,4}))")
  2368. If M2.Success = True Then
  2369. Dim skip As Boolean = False
  2370. For Each epso In episodearray
  2371. If epso.Episode.Value = M2.Groups(3).Value Then skip = True
  2372. Next
  2373. If skip = False Then
  2374. Dim multieps As New TvEpisode
  2375. multieps.Season.Value = eps.Season.Value
  2376. multieps.Episode.Value = M2.Groups(3).Value
  2377. multieps.VideoFilePath = eps.VideoFilePath
  2378. multieps.MediaExtension = eps.MediaExtension
  2379. multieps.ShowObj = eps.ShowObj
  2380. episodearray.Add(multieps)
  2381. allepisodes(epcount) = Convert.ToDecimal(M2.Groups(3).Value)
  2382. End If
  2383. Try
  2384. S = S.Substring(M2.Groups(3).Index + M2.Groups(3).Value.Length, S.Length - (M2.Groups(3).Index + M2.Groups(3).Value.Length))
  2385. Catch ex As Exception
  2386. #If SilentErrorScream Then
  2387. Throw ex
  2388. #End If
  2389. End Try
  2390. End If
  2391. If bckgroundscanepisodes.CancellationPending Then
  2392. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2393. Exit Sub
  2394. End If
  2395. Loop Until M2.Success = False
  2396. stage = "7"
  2397. Dim language As String = eps.ShowLang.Value
  2398. Dim sortorder As String = eps.sortorder.Value
  2399. Dim tvdbid As String = eps.Showtvdbid.Value
  2400. Dim imdbid As String = eps.Showimdbid.Value
  2401. Dim actorsource As String = eps.actorsource.Value
  2402. stage = "8"
  2403. savepath = episodearray(0).NfoFilePath
  2404. stage = "9"
  2405. If episodearray.Count > 1 Then
  2406. For I = 1 To episodearray.Count - 1
  2407. episodearray(I).MakeSecondaryTo(episodearray(0))
  2408. Next
  2409. Pref.tvScraperLog &= "Multipart episode found: " & vbCrLf
  2410. Pref.tvScraperLog &= "Season: " & episodearray(0).Season.Value & " Episodes, "
  2411. For Each ep In episodearray
  2412. Pref.tvScraperLog &= ep.Episode.Value & ", "
  2413. Next
  2414. Pref.tvScraperLog &= vbCrLf
  2415. End If
  2416. stage = "10"
  2417. Dim Firstep As Boolean = True
  2418. For Each singleepisode In episodearray
  2419. If bckgroundscanepisodes.CancellationPending Then
  2420. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2421. Exit Sub
  2422. End If
  2423. If singleepisode.Season.Value.Length > 0 Or singleepisode.Season.Value.IndexOf("0") = 0 Then
  2424. Do Until singleepisode.Season.Value.IndexOf("0") <> 0 Or singleepisode.Season.Value.Length = 1
  2425. singleepisode.Season.Value = singleepisode.Season.Value.Substring(1, singleepisode.Season.Value.Length - 1)
  2426. Loop
  2427. If singleepisode.Episode.Value = "00" Then
  2428. singleepisode.Episode.Value = "0"
  2429. End If
  2430. If singleepisode.Episode.Value <> "0" Then
  2431. Do Until singleepisode.Episode.Value.IndexOf("0") <> 0
  2432. singleepisode.Episode.Value = singleepisode.Episode.Value.Substring(1, singleepisode.Episode.Value.Length - 1)
  2433. Loop
  2434. End If
  2435. End If
  2436. stage = "11"
  2437. Dim episodescraper As New TVDBScraper
  2438. If sortorder = "" Then sortorder = "default"
  2439. Dim tempsortorder As String = sortorder
  2440. If language = "" Then language = "en"
  2441. If actorsource = "" Then actorsource = "tvdb"
  2442. Pref.tvScraperLog &= "Using Settings: TVdbID: " & tvdbid & " SortOrder: " & sortorder & " Language: " & language & " Actor Source: " & actorsource & vbCrLf
  2443. stage = "12"
  2444. If tvdbid <> "" Then
  2445. progresstext &= " - Scraping..."
  2446. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2447. Dim episodeurl As String = "http://thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/" & sortorder & "/" & singleepisode.Season.Value & "/" & singleepisode.Episode.Value & "/" & language & ".xml"
  2448. If eps.Aired.Value <> Nothing Then
  2449. episodeurl = String.Format("http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey=6E82FED600783400&seriesid={0}&airdate={1}&language={2}", tvdbid, singleepisode.Aired.Value, language & ".xml")
  2450. End If
  2451. stage = "12a"
  2452. Dim tmpaok As Boolean = False
  2453. If Not Utilities.UrlIsValid(episodeurl) Then
  2454. If sortorder.ToLower = "dvd" Then
  2455. tempsortorder = "default"
  2456. Pref.tvScraperLog &= "!!! WARNING: This episode could not be found on TVDB using DVD sort order" & vbCrLf
  2457. Pref.tvScraperLog &= "!!! Attempting to find using default sort order" & vbCrLf
  2458. episodeurl = "http://thetvdb.com/api/6E82FED600783400/series/" & tvdbid & "/default/" & singleepisode.Season.Value & "/" & singleepisode.Episode.Value & "/" & language & ".xml"
  2459. Pref.tvScraperLog &= "Now Trying Episode URL: " & episodeurl & vbCrLf
  2460. End If
  2461. Else
  2462. tmpaok = True
  2463. End If
  2464. stage = "12b"
  2465. If tmpaok OrElse Utilities.UrlIsValid(episodeurl) Then
  2466. IF singleepisode.Aired.Value = Nothing AndAlso Pref.tvshow_useXBMC_Scraper = True Then
  2467. Dim FinalResult As String = ""
  2468. stage = "12b1"
  2469. episodearray = XBMCScrape_TVShow_EpisodeDetails(tvdbid, tempsortorder, episodearray, language)
  2470. episodearray(0).NfoFilePath = savepath
  2471. stage = "12b2"
  2472. If episodearray.Count >= 1 Then
  2473. For x As Integer = 0 To episodearray.Count - 1
  2474. episodearray(x).ShowObj = singleepisode.ShowObj
  2475. Pref.tvScraperLog &= "Scraping body of episode: " & episodearray(x).Episode.Value & " - OK" & vbCrLf
  2476. Next
  2477. scrapedok = True
  2478. Else
  2479. Pref.tvScraperLog &= "!!! WARNING: Could not locate this episode on TVDB, or TVDB may be unavailable" & vbCrLf
  2480. scrapedok = False
  2481. End If
  2482. Exit For
  2483. End If
  2484. stage = "12b3"
  2485. Dim tempepisode As String = ep_Get(tvdbid, tempsortorder, singleepisode.Season.Value, singleepisode.Episode.Value, language, singleepisode.Aired.Value)
  2486. stage = "12b4"
  2487. scrapedok = True
  2488. If tempepisode = Nothing Or tempepisode = "Error" Then
  2489. scrapedok = False
  2490. singleepisode.Title.Value = tempepisode
  2491. Pref.tvScraperLog &= "!!! WARNING: This episode: " & singleepisode.Episode.Value & " - could not be found on TVDB" & vbCrLf
  2492. ElseIf tempepisode.Contains("Could not connect") Then 'If TVDB unavailable, advise user to try again later
  2493. scrapedok = False
  2494. Pref.tvScraperLog &= "!!! Issue at TheTVDb, Episode could not be retrieve. Try again later" & vbCrLf
  2495. ElseIf tempepisode.Contains("No Results from SP") Then
  2496. scrapedok = False
  2497. Pref.tvScraperLog &= "!!! Scraping using AirDate found in Filename failed. Check Episode Filename AiredDate is correct." & vbCrLf
  2498. End If
  2499. stage = "12b5"
  2500. If scrapedok = True Then
  2501. progresstext &= "OK."
  2502. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2503. Dim scrapedepisode As New XmlDocument
  2504. Pref.tvScraperLog &= "Scraping body of episode: " & singleepisode.Episode.Value & vbCrLf
  2505. stage = "12b5a"
  2506. scrapedepisode.LoadXml(tempepisode)
  2507. For Each thisresult As XmlNode In scrapedepisode("episodedetails")
  2508. Select Case thisresult.Name
  2509. Case "title"
  2510. stage = "12b5a1"
  2511. singleepisode.Title.Value = thisresult.InnerText
  2512. Case "premiered"
  2513. stage = "12b5a2"
  2514. singleepisode.Aired.Value = thisresult.InnerText
  2515. Case "plot"
  2516. stage = "12b5a3"
  2517. singleepisode.Plot.Value = thisresult.InnerText
  2518. Case "director"
  2519. stage = "12b5a4"
  2520. Dim newstring As String
  2521. newstring = thisresult.InnerText
  2522. newstring = newstring.TrimEnd("|")
  2523. newstring = newstring.TrimStart("|")
  2524. newstring = newstring.Replace("|", " / ")
  2525. singleepisode.Director.Value = newstring
  2526. Case "credits"
  2527. stage = "12b5a5"
  2528. Dim newstring As String
  2529. newstring = thisresult.InnerText
  2530. newstring = newstring.TrimEnd("|")
  2531. newstring = newstring.TrimStart("|")
  2532. newstring = newstring.Replace("|", " / ")
  2533. singleepisode.Credits.Value = newstring
  2534. Case "rating"
  2535. stage = "12b5a6"
  2536. singleepisode.Rating.Value = thisresult.InnerText
  2537. Case "ratingcount"
  2538. stage = "12b5a6a"
  2539. singleepisode.Votes.Value = thisresult.InnerText
  2540. Case "uniqueid"
  2541. stage = "12b5a7"
  2542. singleepisode.UniqueId.Value = thisresult.InnerText
  2543. Case "showid"
  2544. stage = "12b5a8"
  2545. singleepisode.ShowId.Value = thisresult.InnerText
  2546. Case "imdbid"
  2547. stage = "12b5a9"
  2548. singleepisode.ImdbId.Value = thisresult.InnerText
  2549. Case "displayseason"
  2550. stage = "12b5a10"
  2551. singleepisode.DisplaySeason.Value = thisresult.InnerXml
  2552. Case "displayepisode"
  2553. stage = "12b5a11"
  2554. singleepisode.DisplayEpisode.Value = thisresult.InnerXml
  2555. Case "thumb"
  2556. stage = "12b5a11"
  2557. singleepisode.Thumbnail.FileName = thisresult.InnerText
  2558. Case "actor"
  2559. stage = "12b5a12"
  2560. For Each actorl As XmlNode In thisresult.ChildNodes
  2561. Select Case actorl.Name
  2562. Case "name"
  2563. stage = "12b5a12a"
  2564. Dim newactor As New str_MovieActors(SetDefaults)
  2565. If actorl.InnerText <> "" Then
  2566. newactor.actorname = actorl.InnerText
  2567. stage = "12b5a12b"
  2568. singleepisode.ListActors.Add(newactor)
  2569. End If
  2570. End Select
  2571. Next
  2572. End Select
  2573. Next
  2574. If Pref.tvdbIMDbRating Then
  2575. Dim rating As String = ""
  2576. Dim votes As String = ""
  2577. If ep_getIMDbRating(singleepisode.ImdbId.Value, rating, votes) Then
  2578. If rating <> "" Then
  2579. singleepisode.Rating.Value = rating
  2580. singleepisode.Votes.Value = votes
  2581. End If
  2582. End If
  2583. End If
  2584. stage = "12b5b"
  2585. singleepisode.PlayCount.Value = "0"
  2586. singleepisode.ShowId.Value = tvdbid
  2587. stage = "12b5c"
  2588. 'check file name for Episode source
  2589. Dim searchtitle As String = singleepisode.NfoFilePath
  2590. If searchtitle <> "" Then
  2591. For i = 0 To Pref.releaseformat.Length - 1
  2592. If searchtitle.ToLower.Contains(Pref.releaseformat(i).ToLower) Then
  2593. singleepisode.Source.Value = Pref.releaseformat(i)
  2594. Exit For
  2595. End If
  2596. Next
  2597. End If
  2598. Pref.tvScraperLog &= "Scrape body of episode: " & singleepisode.Episode.Value & " - OK" & vbCrLf
  2599. stage = "12b5d"
  2600. progresstext &= " : Scraped Title - '" & singleepisode.Title.Value & "'"
  2601. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2602. stage = "12b5e"
  2603. If actorsource = "imdb" And (imdbid <> "" OrElse singleepisode.ImdbId.Value <> "") Then
  2604. Pref.tvScraperLog &= "Scraping actors from IMDB" & vbCrLf
  2605. progresstext &= " : Actors..."
  2606. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2607. stage = "12b5e1"
  2608. Dim epid As String = ""
  2609. If singleepisode.ImdbId.Value <> "" Then
  2610. epid = singleepisode.ImdbId.Value
  2611. Else
  2612. stage = "12b5e2"
  2613. 'url = "http://www.imdb.com/title/" & imdbid & "/episodes?season=" & singleepisode.Season.Value
  2614. epid = GetEpImdbId(imdbid, singleepisode.Season.Value, singleepisode.Episode.Value)
  2615. End If
  2616. stage = "12b5e3"
  2617. If epid.contains("tt") Then
  2618. Dim scraperfunction As New Classimdb
  2619. stage = "12b5e3a"
  2620. Dim tempactorlist As List(Of str_MovieActors) = scraperfunction.GetImdbActorsList(Pref.imdbmirror, epid, Pref.maxactors)
  2621. If bckgroundscanepisodes.CancellationPending Then
  2622. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2623. Exit Sub
  2624. End If
  2625. stage = "12b5e3b"
  2626. If tempactorlist.Count > 0 Then
  2627. Pref.tvScraperLog &= "Actors scraped from IMDB OK" & vbCrLf
  2628. progresstext &= "OK."
  2629. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2630. stage = "12b5e3c"
  2631. While tempactorlist.Count > Pref.maxactors
  2632. tempactorlist.RemoveAt(tempactorlist.Count - 1)
  2633. End While
  2634. stage = "12b5e3d"
  2635. singleepisode.ListActors.Clear()
  2636. For Each actor In tempactorlist
  2637. singleepisode.ListActors.Add(actor)
  2638. Next
  2639. stage = "12b5e3e"
  2640. tempactorlist.Clear()
  2641. Else
  2642. Pref.tvScraperLog &= "!!! WARNING: Actors not scraped from IMDB, reverting to TVDB actorlist" & vbCrLf
  2643. End If
  2644. If bckgroundscanepisodes.CancellationPending Then
  2645. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2646. Exit Sub
  2647. End If
  2648. Else
  2649. tvScraperLog = tvScraperLog & "Unable To Get Actors From IMDB" & vbCrLf
  2650. End If
  2651. stage = "12b5e4"
  2652. End If
  2653. If imdbid = "" Then
  2654. Pref.tvScraperLog &= "Failed Scraping Actors from IMDB!!! No IMDB Id for Show: " & showtitle & vbCrLf
  2655. End If
  2656. If Pref.copytvactorthumbs AndAlso singleepisode.ListActors.Count = 0 AndAlso Not IsNothing(singleepisode.ShowObj) Then
  2657. For each act In singleepisode.ShowObj.ListActors
  2658. singleepisode.ListActors.Add(act)
  2659. Next
  2660. End If
  2661. stage = "12b5f"
  2662. If Pref.enabletvhdtags = True Then
  2663. progresstext &= " : HD Tags..."
  2664. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2665. stage = "12b5f1"
  2666. Dim fileStreamDetails As FullFileDetails = Pref.Get_HdTags(Utilities.GetFileName(singleepisode.VideoFilePath))
  2667. stage = "12b5f2"
  2668. If Not IsNothing(fileStreamDetails) Then
  2669. singleepisode.Details.StreamDetails.Video = fileStreamDetails.filedetails_video
  2670. stage = "12b5f3"
  2671. For Each audioStream In fileStreamDetails.filedetails_audio
  2672. singleepisode.Details.StreamDetails.Audio.Add(audioStream)
  2673. Next
  2674. For Each substrm In fileStreamDetails.filedetails_subtitles
  2675. singleepisode.Details.StreamDetails.Subtitles.Add(substrm)
  2676. Next
  2677. stage = "12b5f4"
  2678. If Not String.IsNullOrEmpty(singleepisode.Details.StreamDetails.Video.DurationInSeconds.Value) Then
  2679. tempstring = singleepisode.Details.StreamDetails.Video.DurationInSeconds.Value
  2680. If Pref.intruntime Then
  2681. singleepisode.Runtime.Value = Math.Round(tempstring / 60).ToString
  2682. Else
  2683. singleepisode.Runtime.Value = Math.Round(tempstring / 60).ToString & " min"
  2684. End If
  2685. progresstext &= "OK."
  2686. bckgroundscanepisodes.ReportProgress(progress, progresstext)
  2687. End If
  2688. stage = "12b5f5"
  2689. End If
  2690. End If
  2691. stage = "12b5g"
  2692. End If
  2693. Else
  2694. Pref.tvScraperLog &= "!!! WARNING: Could not locate this episode on TVDB, or TVDB may be unavailable" & vbCrLf
  2695. scrapedok = False
  2696. End If
  2697. Else
  2698. Pref.tvScraperLog &= "!!! WARNING: No TVDB ID is available for this show, please scrape the show using the ""TV Show Selector"" TAB" & vbCrLf
  2699. scrapedok = False
  2700. End If
  2701. stage = "12c"
  2702. Firstep = False
  2703. Next
  2704. If Not scrapedok AndAlso Not Firstep Then
  2705. For i = episodearray.Count-1 To 0 Step -1
  2706. If episodearray(i).Title.Value = "Error" Then
  2707. Pref.tvScraperLog &= "!!! WARNING: MultiEpisode No: " & episodearray(i).Episode.Value & " Not Found! Please check file: " & episodearray(i).VideoFilePath & vbCrLf
  2708. episodearray.RemoveAt(i)
  2709. scrapedok = True
  2710. ScraperErrorDetected = True
  2711. End If
  2712. Next
  2713. End If
  2714. stage = "13"
  2715. End If
  2716. stage = "14"
  2717. If savepath <> "" And scrapedok = True Then
  2718. If bckgroundscanepisodes.CancellationPending Then
  2719. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2720. Exit Sub
  2721. End If
  2722. Dim newnamepath As String = ""
  2723. stage = "14a"
  2724. newnamepath = ep_add(episodearray, savepath, showtitle)
  2725. stage = "14b"
  2726. For Each ep In episodearray
  2727. ep.NfoFilePath = newnamepath
  2728. Next
  2729. stage = "14c"
  2730. If bckgroundscanepisodes.CancellationPending Then
  2731. Pref.tvScraperLog &= vbCrLf & "!!! Operation Cancelled by user" & vbCrLf
  2732. Exit Sub
  2733. End If
  2734. stage = "14d"
  2735. 'For Each Shows In Cache.TvCache.Shows
  2736. stage = "14d1"
  2737. If episodearray(0).NfoFilePath.IndexOf(episodearray(0).ShowObj.NfoFilePath.Replace("\tvshow.nfo", "")) <> -1 Then
  2738. stage = "14d1a"
  2739. Dim epseason As String = episodearray(0).Season.Value
  2740. Dim Seasonxx As String = episodearray(0).ShowObj.FolderPath + "season" + (If(epseason.ToInt < 10, "0" + epseason, epseason)) + (If(Pref.FrodoEnabled, "-poster.jpg", ".tbn"))
  2741. stage = "14d1b"
  2742. If epseason = "0" Then Seasonxx = episodearray(0).ShowObj.FolderPath & "season-specials" & (If(Pref.FrodoEnabled, "-poster.jpg", ".tbn"))
  2743. stage = "14d1c"
  2744. If Not IO.File.Exists(Seasonxx) Then
  2745. TvGetArtwork(episodearray(0).ShowObj, False, False, True, False)
  2746. End If
  2747. stage = "14d1d"
  2748. If Pref.seasonfolderjpg AndAlso episodearray(0).ShowObj.FolderPath <> episodearray(0).FolderPath AndAlso (Not File.Exists(episodearray(0).FolderPath & "folder.jpg")) Then
  2749. If File.Exists(Seasonxx) Then Utilities.SafeCopyFile(Seasonxx, (episodearray(0).FolderPath & "folder.jpg"))
  2750. End If
  2751. stage = "14d1e"
  2752. For Each ep In episodearray
  2753. 'Dim newwp As New TvEpisode
  2754. 'newwp = ep 'added this kline becuase plot + others were not being dispolay after a new ep was found
  2755. 'newwp.NfoFilePath = newnamepath 'left these as they were....
  2756. 'newwp.PlayCount.Value = "0" '
  2757. 'newwp.ShowObj = Shows
  2758. bckgroundscanepisodes.ReportProgress(1, ep)
  2759. Next
  2760. stage = "14d1f"
  2761. tv_EpisodesMissingUpdate(episodearray)
  2762. stage = "14d1g"
  2763. 'Exit For
  2764. End If
  2765. stage = "14d2"
  2766. 'Next
  2767. stage = "15"
  2768. End If
  2769. If Not scrapedok Then ScraperErrorDetected = True
  2770. Pref.tvScraperLog &= "!!!" & vbCrLf
  2771. stage = "16"
  2772. Next
  2773. stage = "17"
  2774. 'newEpisodeList
  2775. bckgroundscanepisodes.ReportProgress(0, progresstext)
  2776. stage = "18"
  2777. Catch ex As Exception
  2778. stage = "stage: " & stage
  2779. ExceptionHandler.LogError(ex, stage)
  2780. End Try
  2781. End Sub
  2782. Sub tv_Rescrape_Episode(ByRef WorkingTvShow, ByRef WorkingEpisode)
  2783. Dim tempint As Integer = 0
  2784. Dim tempstring As String = ""
  2785. If WorkingEpisode.IsMissing Then
  2786. MsgBox("This is a Missing Episode, and can not be rescraped!")
  2787. Exit Sub
  2788. End If
  2789. If Utilities.GetTvEpExtension(WorkingEpisode.NfoFilePath) = "error" Then
  2790. tempint = MessageBox.Show("Video file for this episode does not exist." & vbCrLf & "Please Delete this episode's nfo, and refresh the Show for the selected episode.", "Warning", MessageBoxButtons.OK , MessageBoxIcon.Warning)
  2791. Exit Sub
  2792. End If
  2793. tempint = MessageBox.Show("Rescraping the Episode will Overwrite all the current details" & vbCrLf & "Do you wish to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
  2794. If tempint = DialogResult.No Then
  2795. Exit Sub
  2796. End If
  2797. Dim messbox As frmMessageBox = New frmMessageBox("The Selected Episode is being Rescraped", "", "Please Wait")
  2798. System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
  2799. messbox.Show()
  2800. messbox.Refresh()
  2801. Application.DoEvents()
  2802. Dim newepisode As New TvEpisode
  2803. Dim sortorder As String = WorkingTvShow.SortOrder.Value
  2804. Dim language As String = WorkingTvShow.Language.Value
  2805. Dim actorsource As String = WorkingTvShow.EpisodeActorSource.Value
  2806. Dim tvdbid As String = WorkingTvShow.TvdbId.Value
  2807. Dim imdbid As String = WorkingTvShow.ImdbId.Value
  2808. Dim seasonno As String = WorkingEpisode.Season.Value
  2809. Dim episodeno As String = WorkingEpisode.Episode.Value
  2810. newepisode.NfoFilePath = WorkingEpisode.NfoFilePath
  2811. newepisode.Season.Value = WorkingEpisode.Season.Value
  2812. newepisode.Episode.Value = WorkingEpisode.Episode.Value
  2813. newepisode.ShowId.Value = WorkingTvShow.TvdbId.Value
  2814. Dim episodescraper As New TVDBScraper
  2815. If sortorder = "" Then sortorder = "default"
  2816. If language = "" Then language = "en"
  2817. If actorsource = "" Then actorsource = "tvdb"
  2818. If tvdbid.IndexOf("tt").Equals(0) Then tv_IMDbID_detected = True
  2819. Dim tempepisode As String = episodescraper.getepisode(tvdbid, sortorder, seasonno, episodeno, language, True)
  2820. If tempepisode.Contains("ERROR") Then
  2821. Dim chunkSize As Integer = 40
  2822. Dim chunkSize2 As Integer = 1
  2823. Dim loops As Integer = Math.Round(tempepisode.Length / chunkSize)
  2824. Dim finalString As String = ""
  2825. For i = 0 To loops
  2826. If i * chunkSize + chunkSize > tempepisode.Length Then
  2827. chunkSize2 = tempepisode.Length - i * chunkSize
  2828. Else
  2829. chunkSize2 = chunkSize
  2830. End If
  2831. finalString += tempepisode.Substring(i * chunkSize, chunkSize2) & vbCrLf
  2832. Next
  2833. MsgBox("TVDB reported the following error" & vbCrLf & finalString, MsgBoxStyle.OkOnly, "ERROR!")
  2834. messbox.Close()
  2835. Exit Sub
  2836. End If
  2837. Dim scrapedepisode As New XmlDocument
  2838. Try
  2839. scrapedepisode.LoadXml(tempepisode)
  2840. Dim thisresult As XmlNode = Nothing
  2841. For Each thisresult In scrapedepisode("episodedetails")
  2842. Select Case thisresult.Name
  2843. Case "title"
  2844. newepisode.Title.Value = thisresult.InnerText
  2845. Case "premiered"
  2846. newepisode.Aired.Value = thisresult.InnerText
  2847. Case "plot"
  2848. newepisode.Plot.Value = thisresult.InnerText
  2849. Case "director"
  2850. newepisode.Director.Value = thisresult.InnerText
  2851. newepisode.Director.Value = newepisode.Director.Value.TrimStart("|")
  2852. newepisode.Director.Value = newepisode.Director.Value.TrimEnd("|")
  2853. newepisode.Director.Value = newepisode.Director.Value.Replace("|", " / ")
  2854. Case "credits"
  2855. newepisode.Credits.Value = thisresult.InnerText
  2856. newepisode.Credits.Value = newepisode.Credits.Value.TrimStart("|")
  2857. newepisode.Credits.Value = newepisode.Credits.Value.TrimEnd("|")
  2858. newepisode.Credits.Value = newepisode.Credits.Value.Replace("|", " / ")
  2859. Case "rating"
  2860. newepisode.Rating.Value = thisresult.InnerText
  2861. Case "ratingcount"
  2862. newepisode.Votes.Value = thisresult.InnerText
  2863. Case "thumb"
  2864. newepisode.Thumbnail.FileName = thisresult.InnerText
  2865. Case "genre"
  2866. newepisode.Genre.Value = thisresult.InnerText
  2867. Case "imdbid"
  2868. newepisode.ImdbId.Value = thisresult.InnerText
  2869. Case "displayseason"
  2870. newepisode.DisplaySeason.Value = thisresult.InnerXml
  2871. Case "displayepisode"
  2872. newepisode.DisplayEpisode.Value = thisresult.InnerXml
  2873. Case "uniqueid"
  2874. newepisode.UniqueId.Value = thisresult.InnerText
  2875. Case "actor"
  2876. Dim actors As XmlNode = Nothing
  2877. For Each actorl In thisresult.ChildNodes
  2878. Select Case actorl.name
  2879. Case "name"
  2880. Dim newactor As New str_MovieActors(SetDefaults)
  2881. newactor.actorname = actorl.innertext
  2882. newepisode.ListActors.Add(newactor)
  2883. End Select
  2884. Next
  2885. End Select
  2886. Next
  2887. If Pref.tvdbIMDbRating Then
  2888. Dim rating As String = ""
  2889. Dim votes As String = ""
  2890. If ep_getIMDbRating(newepisode.ImdbId.Value, rating, votes) Then
  2891. If rating <> "" Then
  2892. newepisode.Rating.Value = rating
  2893. newepisode.Votes.Value = votes
  2894. End If
  2895. End If
  2896. End If
  2897. newepisode.PlayCount.Value = "0"
  2898. Catch ex As Exception
  2899. End Try
  2900. If actorsource = "imdb" Then
  2901. If imdbid <> "" OrElse newepisode.ImdbId.Value <> "" Then
  2902. tvScraperLog = tvScraperLog & "Scraping actors from IMDB" & vbCrLf
  2903. Dim epid As String = ""
  2904. If newepisode.ImdbId.Value <> Nothing AndAlso newepisode.ImdbId.Value.Contains("tt") Then
  2905. epid = newepisode.ImdbId.Value
  2906. Else
  2907. epid = GetEpImdbId(imdbid, newepisode.Season.Value, newepisode.Episode.Value)
  2908. End If
  2909. If bckgroundscanepisodes.CancellationPending Then
  2910. tvScraperLog = tvScraperLog & vbCrLf & "Operation Cancelled by user" & vbCrLf
  2911. Exit Sub
  2912. End If
  2913. If epid.Contains("tt") Then
  2914. Dim scraperfunction As New Classimdb
  2915. Dim actorlist As List(Of str_MovieActors) = scraperfunction.GetImdbActorsList(Pref.imdbmirror, epid, Pref.maxactors)
  2916. If actorlist.Count > 0 Then
  2917. newepisode.ListActors.Clear()
  2918. For Each act In actorlist
  2919. newepisode.ListActors.Add(act)
  2920. Next
  2921. End If
  2922. Else
  2923. End If
  2924. End If
  2925. End If
  2926. If Pref.enablehdtags = True Then
  2927. Dim fileStreamDetails As FullFileDetails = Pref.Get_HdTags(Utilities.GetFileName(WorkingEpisode.VideoFilePath))
  2928. newepisode.Details.StreamDetails.Video = fileStreamDetails.filedetails_video
  2929. For Each audioStream In fileStreamDetails.filedetails_audio
  2930. newepisode.Details.StreamDetails.Audio.Add(audioStream)
  2931. Next
  2932. If Not String.IsNullOrEmpty(newepisode.Details.StreamDetails.Video.DurationInSeconds.Value) Then
  2933. Try
  2934. tempstring = newepisode.Details.StreamDetails.Video.DurationInSeconds.Value
  2935. If Pref.intruntime Then
  2936. newepisode.Runtime.Value = Math.Round(tempstring/60).ToString
  2937. Else
  2938. newepisode.Runtime.Value = Math.Round(tempstring/60).ToString & " min"
  2939. End If
  2940. Catch ex As Exception
  2941. #If SilentErrorScream Then
  2942. Throw ex
  2943. #End If
  2944. End Try
  2945. End If
  2946. End If
  2947. Dim eps As New List(Of Media_Companion.TvEpisode)
  2948. eps.Add(newepisode)
  2949. Dim multiepisode As Boolean = TestForMultiepisode(newepisode.NfoFilePath)
  2950. If multiepisode = False Then
  2951. 'Call nfoFunction.saveepisodenfo(eps, newepisode.NfoFilePath)
  2952. WorkingWithNfoFiles.ep_NfoSave(eps, newepisode.NfoFilePath)
  2953. Else
  2954. Dim episodelist As New List(Of TvEpisode)
  2955. episodelist = WorkingWithNfoFiles.ep_NfoLoad(newepisode.NfoFilePath)
  2956. For Each ep In episodelist
  2957. If newepisode.Season.Value = ep.Season.Value And newepisode.Episode.Value = ep.Episode.Value Then
  2958. episodelist.Remove(ep)
  2959. episodelist.Add(newepisode)
  2960. WorkingWithNfoFiles.ep_NfoSave(episodelist, newepisode.NfoFilePath)
  2961. Exit For
  2962. End If
  2963. Next
  2964. End If
  2965. '''''Get Episode Fanart
  2966. tvScraperLog &= tv_EpisodeFanartGet(newepisode, Pref.autoepisodescreenshot) & vbcrlf
  2967. '''''Call LoadTvEpisode(WorkingEpisode)
  2968. tv_EpisodeSelected(TvTreeview.SelectedNode.Tag, True) 'reload the episode after it has been rescraped
  2969. messbox.Close()
  2970. End Sub
  2971. Public Function tv_EpisodeFanartGet(ByVal episode As TvEpisode, ByVal doScreenShot As Boolean) As String
  2972. Dim result As String = "!!! *** Unable to download Episode Thumb ***"
  2973. Dim fpath As String = episode.NfoFilePath.Replace(".nfo", ".tbn")
  2974. Dim paths As New List(Of String)
  2975. If Pref.EdenEnabled AndAlso (Pref.overwritethumbs Or Not File.Exists(fpath)) Then paths.Add(fpath)
  2976. fpath = fpath.Replace(".tbn", "-thumb.jpg")
  2977. If Pref.FrodoEnabled AndAlso (Pref.overwritethumbs Or Not File.Exists(fpath)) Then paths.Add(fpath)
  2978. If paths.Count > 0 Then
  2979. Dim downloadok As Boolean = False
  2980. If episode.Thumbnail.FileName = Nothing Then
  2981. Dim tvdbstuff As New TVDBScraper
  2982. Dim tempepisode As Tvdb.Episode = tvdbstuff.getepisodefromxml(episode.ShowId.Value, episode.sortorder.Value, episode.Season.value, episode.Episode.Value, episode.ShowLang.Value, True)
  2983. If tempepisode.ThumbNail.Value <> Nothing Then episode.Thumbnail.FileName = tempepisode.ThumbNail.Value
  2984. End If
  2985. If episode.Thumbnail.FileName <> Nothing AndAlso episode.Thumbnail.FileName <> "http://www.thetvdb.com/banners/" Then
  2986. Dim url As String = episode.Thumbnail.FileName
  2987. If Not url.IndexOf("http") = 0 And url.IndexOf(".jpg") <> -1 Then
  2988. url = episode.Thumbnail.Url
  2989. End If
  2990. If url <> Nothing AndAlso url.IndexOf("http") = 0 AndAlso url.IndexOf(".jpg") <> -1 Then
  2991. downloadok = DownloadCache.SaveImageToCacheAndPaths(url, paths, True, , ,Pref.overwritethumbs)
  2992. Else
  2993. result = "!!! No thumbnail to download"
  2994. End If
  2995. If downloadok Then result = "!!! Episode Thumb downloaded"
  2996. Else
  2997. result = "!!! No thumbnail to download"
  2998. End If
  2999. If Not downloadok AndAlso doScreenShot Then
  3000. Dim cachepathandfilename As String = Utilities.CreateScrnShotToCache(episode.VideoFilePath, paths(0), Pref.ScrShtDelay)
  3001. If Not cachepathandfilename = "" Then
  3002. Dim imagearr() As Integer = GetAspect(episode)
  3003. If Pref.tvscrnshtTVDBResize AndAlso Not imagearr(0) = 0 Then
  3004. DownloadCache.CopyAndDownSizeImage(cachepathandfilename, paths(0), imagearr(0), imagearr(1))
  3005. Else
  3006. File.Copy(cachepathandfilename, paths(0), Pref.overwritethumbs)
  3007. End If
  3008. If paths.Count > 1 Then
  3009. File.Copy(paths(0), paths(1), Pref.overwritethumbs)
  3010. End If
  3011. result = "!!! No Episode thumb to download, Screenshot saved"
  3012. Else
  3013. result = "!!! No Episode thumb to download, Screenshot Could not be saved!"
  3014. End If
  3015. End If
  3016. ElseIf paths.Count = 0 Then
  3017. result = "!!! Episode Thumb(s) already exist and are not set to overwrite"
  3018. End If
  3019. Return result
  3020. End Function
  3021. Public Function tv_ShowSelectedCurrently(ByRef tree As TreeView) As Media_Companion.TvShow
  3022. 'TvTreeview.Focus()
  3023. If tree.SelectedNode Is Nothing Then
  3024. If tree.Nodes.Count = 0 Then Return Nothing
  3025. tree.SelectedNode = tree.TopNode
  3026. End If
  3027. If tree.SelectedNode Is Nothing Then
  3028. tree.SelectedNode = tree.Nodes(0)
  3029. End If
  3030. Dim Show As Media_Companion.TvShow = Nothing
  3031. Dim Season As Media_Companion.TvSeason = Nothing
  3032. Dim Episode As Media_Companion.TvEpisode = Nothing
  3033. If TypeOf tree.SelectedNode.Tag Is Media_Companion.TvShow Then
  3034. Show = tree.SelectedNode.Tag
  3035. ElseIf TypeOf tree.SelectedNode.Tag Is Media_Companion.TvSeason Then
  3036. Season = tree.SelectedNode.Tag
  3037. Show = Season.GetParentShow
  3038. ElseIf TypeOf tree.SelectedNode.Tag Is Media_Companion.TvEpisode Then
  3039. Episode = tree.SelectedNode.Tag
  3040. Season = Episode.SeasonObj
  3041. Show = Episode.ShowObj
  3042. End If
  3043. Return Show
  3044. End Function
  3045. Public Function tv_SeasonSelectedCurrently(ByRef tree As TreeView) As Media_Companion.TvSeason
  3046. If tree.SelectedNode Is Nothing Then Return Nothing
  3047. Dim Show As Media_Companion.TvShow = Nothing
  3048. Dim Season As Media_Companion.TvSeason = Nothing
  3049. Dim Episode As Media_Companion.TvEpisode = Nothing
  3050. If TypeOf tree.SelectedNode.Tag Is Media_Companion.TvShow Then
  3051. Show = tree.SelectedNode.Tag
  3052. ElseIf TypeOf tree.SelectedNode.Tag Is Media_Companion.TvSeason Then
  3053. Season = tree.SelectedNode.Tag
  3054. Show = Season.GetParentShow
  3055. ElseIf TypeOf tree.SelectedNode.Tag Is Media_Companion.TvEpisode Then
  3056. Episode = tree.SelectedNode.Tag
  3057. Season = Episode.SeasonObj
  3058. Show = Episode.ShowObj
  3059. End If
  3060. Return Season
  3061. End Function
  3062. Public Function ep_SelectedCurrently(ByRef tree As TreeView) As Media_Companion.TvEpisode
  3063. If tree.SelectedNode Is Nothing Then Return Nothing
  3064. Dim Show As Media_Companion.TvShow = Nothing
  3065. Dim Season As Media_Companion.TvSeason = Nothing
  3066. Dim Episode As Media_Companion.TvEpisode = Nothing
  3067. If TypeOf tree.SelectedNode.Tag Is Media_Companion.TvShow Then
  3068. Show = tree.SelectedNode.Tag
  3069. ElseIf TypeOf tree.SelectedNode.Tag Is Media_Companion.TvSeason Then
  3070. Season = tree.SelectedNode.Tag
  3071. Show = Season.GetParentShow
  3072. ElseIf TypeOf tree.SelectedNode.Tag Is Media_Companion.TvEpisode Then
  3073. Episode = tree.SelectedNode.Tag
  3074. Season = Episode.SeasonObj
  3075. Show = Episode.ShowObj
  3076. End If
  3077. Return Episode
  3078. End Function
  3079. Private Sub tv_Filter()
  3080. tv_Filter(Nothing)
  3081. End Sub
  3082. Private Sub tv_Filter(ByVal overrideShowIsMissing As String) 'ByVal butt As String)
  3083. Dim butt As String = ""
  3084. Dim ThisDate As Date = If(Pref.TvMissingEpOffset, Now.AddDays(-1), Now)
  3085. Dim eden As Boolean = Pref.EdenEnabled
  3086. Dim frodo As Boolean = Pref.FrodoEnabled
  3087. Dim overrideIsMissing As Boolean = overrideShowIsMissing IsNot Nothing
  3088. If rbTvListAll.Checked Then butt = "all"
  3089. If rbTvMissingFanart.Checked Then butt = "fanart"
  3090. If rbTvMissingPoster.Checked Then butt = "posters"
  3091. If rbTvMissingThumb.Checked Then butt = "screenshot"
  3092. If rbTvMissingEpisodes.Checked Then butt = "missingeps"
  3093. If rbTvMissingAiredEp.Checked Then butt = "airedmissingeps"
  3094. If rbTvDisplayWatched.Checked Then butt = "watched"
  3095. If rbTvDisplayUnWatched.Checked Then butt = "unwatched"
  3096. If rbTvListContinuing.Checked Then butt = "continuing"
  3097. If rbTvListEnded.Checked Then butt = "ended"
  3098. If rbTvListUnKnown.Checked Then butt = "unknown"
  3099. If startup = True Then butt = "all"
  3100. If butt = "missingeps" Then
  3101. If Pref.displayMissingEpisodes Then
  3102. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3103. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3104. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3105. If Not episode.IsMissing Then
  3106. episode.Visible = False
  3107. Else
  3108. If String.IsNullOrEmpty(episode.Aired.Value) Then ' Change the colour to gray
  3109. episode.EpisodeNode.ForeColor = Color.Gray
  3110. Else
  3111. Try
  3112. If Convert.ToDateTime(episode.Aired.Value) > ThisDate Then ' Is the episode in the future?
  3113. episode.EpisodeNode.ForeColor = Color.Red ' Yes, so change its colour to Red
  3114. Else
  3115. episode.EpisodeNode.ForeColor = Drawing.Color.Blue
  3116. End If
  3117. Catch ex As Exception
  3118. episode.EpisodeNode.ForeColor = Drawing.Color.Blue ' Set the colour to the missing colour
  3119. End Try
  3120. End If
  3121. episode.Visible = True
  3122. episode.EpisodeNode.EnsureVisible()
  3123. End If
  3124. Next
  3125. Season.Visible = Season.VisibleEpisodeCount > 0
  3126. Next
  3127. item.Visible = item.VisibleSeasonCount > 0
  3128. Next
  3129. Else
  3130. MsgBox("Enable Display Missing Episodes")
  3131. End If
  3132. ElseIf butt.Contains("watched") Then
  3133. Dim playcount As Integer = If(butt = "watched", 1, 0)
  3134. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3135. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3136. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3137. If episode.PlayCount.Value = playcount.ToString Then
  3138. episode.Visible = True
  3139. Else
  3140. episode.Visible = False
  3141. End If
  3142. Next
  3143. Season.Visible = Season.VisibleEpisodeCount > 0
  3144. Next
  3145. item.Visible = item.VisibleSeasonCount > 0
  3146. item.Hidden.Value = Not item.Visible
  3147. Next
  3148. ElseIf butt.Contains("unwatched") Then
  3149. Dim playcount As Integer = If(butt = "watched", 1, 0)
  3150. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3151. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3152. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3153. If episode.PlayCount.Value = playcount.ToString Then
  3154. episode.Visible = True
  3155. Else
  3156. episode.Visible = False
  3157. End If
  3158. Next
  3159. Season.Visible = Season.VisibleEpisodeCount > 0
  3160. Next
  3161. item.Visible = item.VisibleSeasonCount > 0
  3162. item.Hidden.Value = Not item.Visible
  3163. Next
  3164. ElseIf butt = "airedmissingeps" Then
  3165. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3166. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3167. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3168. If Not episode.IsMissing Then
  3169. episode.Visible = False
  3170. Else
  3171. If String.IsNullOrEmpty(episode.Aired.Value) Then
  3172. episode.Visible = False
  3173. Else
  3174. Try ' Has the episode been aired yet?
  3175. If Convert.ToDateTime(episode.Aired.Value) <= ThisDate Then
  3176. episode.Visible = True
  3177. episode.EpisodeNode.EnsureVisible()
  3178. Else
  3179. episode.Visible = False
  3180. End If
  3181. Catch ex As Exception
  3182. episode.Visible = False ' We failed to convert the aired date to a date, therefore don't show the episode
  3183. End Try
  3184. End If
  3185. End If
  3186. Next
  3187. Season.Visible = Season.VisibleEpisodeCount > 0
  3188. Next
  3189. item.Visible = item.VisibleSeasonCount > 0
  3190. Next
  3191. ElseIf butt = "screenshot" Then
  3192. Dim edenart As String = ""
  3193. Dim frodoart As String = ""
  3194. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3195. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3196. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3197. If episode.IsMissing Then
  3198. episode.Visible = False
  3199. Continue For
  3200. End If
  3201. edenart = episode.Thumbnail.Path
  3202. frodoart = episode.Thumbnail.Path.Replace(".tbn", "-thumb.jpg")
  3203. If (Not String.IsNullOrEmpty(episode.Thumbnail.FileName)) Then
  3204. If ((eden And Not frodo) AndAlso IO.File.Exists(edenart)) Or ((frodo And Not eden) AndAlso IO.File.Exists(frodoart)) Or ((frodo And eden) And (IO.File.Exists(edenart) And IO.File.Exists(frodoart))) Then
  3205. episode.Visible = False
  3206. Else
  3207. episode.Visible = True
  3208. episode.EpisodeNode.EnsureVisible()
  3209. End If
  3210. End If
  3211. Next
  3212. Season.Visible = Season.VisibleEpisodeCount > 0
  3213. Next
  3214. item.Visible = item.VisibleSeasonCount > 0
  3215. Next
  3216. ElseIf butt = "all" Then
  3217. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3218. item.Visible = True
  3219. item.Hidden.Value = False.ToString
  3220. Dim containsVisibleSeason As Boolean = False
  3221. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3222. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3223. If episode.IsMissing AndAlso Not (Pref.displayMissingEpisodes Or (overrideIsMissing AndAlso episode.ShowObj.ToString = overrideShowIsMissing)) Then
  3224. episode.Visible = False
  3225. Else
  3226. Try
  3227. If episode.IsMissing Then
  3228. If episode.Aired.Value <> "" Then
  3229. If Convert.ToDateTime(episode.Aired.Value) > ThisDate Then
  3230. episode.EpisodeNode.ForeColor = Color.Red ' Yes, so change its colour to Red
  3231. Else
  3232. episode.EpisodeNode.ForeColor = Drawing.Color.Blue
  3233. End If
  3234. Else
  3235. episode.EpisodeNode.ForeColor = Drawing.Color.gray
  3236. End If
  3237. End If
  3238. Catch
  3239. episode.EpisodeNode.ForeColor = Color.Red
  3240. End Try
  3241. episode.Visible = True
  3242. End If
  3243. Next
  3244. Season.Visible = Season.VisibleEpisodeCount > 0
  3245. Next
  3246. item.Visible = item.VisibleSeasonCount > 0
  3247. Next
  3248. ElseIf butt = "continuing" Then
  3249. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3250. Dim visible As Boolean = item.Status.Value = "Continuing"
  3251. item.Hidden.Value = Not visible
  3252. 'item.Visible = If(item.Status.Value = "Continuing", True, False)
  3253. 'If Not item.Visible Then Continue For
  3254. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3255. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3256. episode.Visible = visible
  3257. Next
  3258. Season.Visible = Season.VisibleEpisodeCount > 0
  3259. Next
  3260. item.Visible = True
  3261. Next
  3262. ElseIf butt = "ended" Then
  3263. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3264. Dim visible As Boolean = item.Status.Value = "Ended"
  3265. item.Hidden.Value = Not visible
  3266. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3267. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3268. episode.Visible = visible
  3269. Next
  3270. Season.Visible = Season.VisibleEpisodeCount > 0
  3271. Next
  3272. item.Visible = True
  3273. Next
  3274. ElseIf butt = "unknown" Then
  3275. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3276. Dim visible As Boolean = item.Status.Value = ""
  3277. item.Hidden.Value = Not visible
  3278. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3279. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3280. episode.Visible = visible
  3281. Next
  3282. Season.Visible = Season.VisibleEpisodeCount > 0
  3283. Next
  3284. item.Visible = True
  3285. Next
  3286. ElseIf butt = "fanart" Then
  3287. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3288. item.Visible = True
  3289. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3290. For Each episode As Media_Companion.TvEpisode In Season.Episodes
  3291. episode.Visible = False
  3292. Next
  3293. Season.Visible = False
  3294. Next
  3295. If item.ImageFanart.Exists Then
  3296. item.Visible = False
  3297. Else
  3298. item.Visible = True
  3299. End If
  3300. Next
  3301. ElseIf butt = "posters" Then
  3302. Dim edenpost As String = ""
  3303. Dim frodopost As String = ""
  3304. Dim frodobann As String = ""
  3305. For Each item As Media_Companion.TvShow In Cache.TvCache.Shows
  3306. item.Visible = False
  3307. For Each Season As Media_Companion.TvSeason In item.Seasons.Values
  3308. edenpost = Season.Poster.Path
  3309. frodopost = Season.Poster.Path.Replace(".tbn", "-poster.jpg")
  3310. frodobann = Season.Banner.Path
  3311. If ((eden And frodo) AndAlso (IO.File.Exists(edenpost) And (IO.File.Exists(frodopost) AndAlso IO.File.Exists(frodobann)))) Or ((eden And Not frodo) AndAlso IO.File.Exists(edenpost)) Or ((frodo And Not eden) AndAlso (IO.File.Exists(frodopost) Or IO.File.Exists(frodobann))) Then
  3312. Season.Visible = False
  3313. Else
  3314. Season.Visible = True
  3315. End If
  3316. For Each Episode As Media_Companion.TvEpisode In Season.Episodes
  3317. Episode.Visible = False
  3318. Next
  3319. Next
  3320. If frodo And Not IO.File.Exists(item.FolderPath + "poster.jpg") Then
  3321. item.Visible = True
  3322. ElseIf eden And Not frodo Then
  3323. item.Visible = Not item.ImagePoster.Exists
  3324. End If
  3325. Next
  3326. End If
  3327. If butt = "all" OrElse butt = "watched" OrElse butt = "unwatched" OrElse butt = "ended" OrElse butt = "continuing" OrElse butt = "unknown" Then TvTreeviewRebuild()
  3328. End Sub
  3329. #Region "Tv MissingEpisode Routines"
  3330. Private Sub Bckgrndfindmissingepisodes_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Bckgrndfindmissingepisodes.DoWork
  3331. Try
  3332. Statusstrip_Enable()
  3333. 'StatusStrip1.BackColor = Color.Honeydew
  3334. 'StatusStrip1.Visible = True
  3335. 'tsStatusLabel1.Visible = False
  3336. Call tv_EpisodesMissingFind(e.Argument)
  3337. e.Result = e.Argument
  3338. Catch ex As Exception
  3339. ExceptionHandler.LogError(ex)
  3340. End Try
  3341. End Sub
  3342. Private Sub Bckgrndfindmissingepisodes_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles Bckgrndfindmissingepisodes.ProgressChanged
  3343. Try
  3344. If e.ProgressPercentage = 1 Then
  3345. If TypeOf e.UserState Is Media_Companion.TvEpisode Then
  3346. Dim MissingEpisode As Media_Companion.TvEpisode = e.UserState
  3347. MissingEpisode.ShowObj.AddEpisode(MissingEpisode)
  3348. End If
  3349. Else
  3350. ToolStripStatusLabel2.Text = e.UserState
  3351. End If
  3352. Catch ex As Exception
  3353. ExceptionHandler.LogError(ex)
  3354. End Try
  3355. End Sub
  3356. Private Sub Bckgrndfindmissingepisodes_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles Bckgrndfindmissingepisodes.RunWorkerCompleted
  3357. Try
  3358. Dim ShowList As List(Of TvShow) = e.Result
  3359. Pref.DlMissingEpData = False
  3360. ToolStripStatusLabel2.Visible = False
  3361. ToolStripStatusLabel2.Text = "TV Show Episode Scan In Progress"
  3362. Statusstrip_Enable(False)
  3363. Application.DoEvents()
  3364. TvTreeview.Sort()
  3365. Dim showToRefresh = Nothing
  3366. If (ShowList.Count = 1) Then
  3367. ' ignore missing episodes checked entry for this forced node refresh
  3368. showToRefresh = ShowList(0).ToString()
  3369. End If
  3370. tv_CacheLoad()
  3371. tv_Filter(showToRefresh)
  3372. 'MsgBox("Missing Episode Download Complete!", MsgBoxStyle.OkOnly, "Missing Episode Download.")
  3373. Catch ex As Exception
  3374. ExceptionHandler.LogError(ex)
  3375. End Try
  3376. End Sub
  3377. Private Sub tv_EpisodesMissingLoad(ByVal refresh As Boolean)
  3378. Try
  3379. If Not Bckgrndfindmissingepisodes.IsBusy And bckgroundscanepisodes.IsBusy = False Then
  3380. If refresh Then
  3381. Dim nod As TreeNode
  3382. For Each nod In TvTreeview.Nodes
  3383. Dim nod2 As TreeNode
  3384. For Each nod2 In nod.Nodes
  3385. Dim nod3 As TreeNode
  3386. For I = nod2.Nodes.count-1 to 0 Step -1
  3387. nod3 = nod2.Nodes(I)
  3388. Dim episo As TvEpisode
  3389. episo = nod3.Tag
  3390. If episo.IsMissing Then
  3391. nod2.Nodes.RemoveAt(I)
  3392. End If
  3393. Next
  3394. Next
  3395. Next
  3396. Dim epcount As Integer = Cache.TvCache.Episodes.Count -1
  3397. For I = epcount to 0 Step -1 'Each episode In sh.Episodes
  3398. Dim episode As TvEpisode = Cache.TvCache.Episodes.Item(I)
  3399. If episode.IsMissing = True Then 'Pref.displayMissingEpisodes AndAlso episode.IsMissing = True
  3400. Cache.TvCache.Remove(episode)
  3401. End If
  3402. Next
  3403. Tv_CacheSave()
  3404. tv_CacheLoad()
  3405. End If
  3406. Dim ShowList As New List(Of TvShow)
  3407. For Each shows In Cache.TvCache.Shows
  3408. 'shows.MissingEpisodes.Clear() ' - Commented out as MissingEpisodes is a Read-only list.
  3409. ShowList.Add(shows)
  3410. Next
  3411. ToolStripStatusLabel2.Text = "Starting search for missing episodes"
  3412. ToolStripStatusLabel2.Visible = True
  3413. Bckgrndfindmissingepisodes.RunWorkerAsync(ShowList)
  3414. ElseIf Bckgrndfindmissingepisodes.IsBusy Then
  3415. MsgBox("Process is already running")
  3416. Else
  3417. MsgBox("Missing episode search cannot be performed" & vbCrLf & " when the episode scraper is running")
  3418. End If
  3419. Catch ex As Exception
  3420. End Try
  3421. End Sub
  3422. Private Sub tv_EpisodesMissingFind(ByVal ShowList As List(Of TvShow))
  3423. Utilities.EnsureFolderExists(Utilities.MissingPath)
  3424. For Each item In ShowList
  3425. Bckgrndfindmissingepisodes.ReportProgress(0, "Downloading episode data for: " & item.Title.Value)
  3426. If item.State = Media_Companion.ShowState.Open Then
  3427. Dim showid As String = item.TvdbId.Value
  3428. If IsNumeric(showid) Then
  3429. 'http://www.thetvdb.com/api/6E82FED600783400/series/85137/all/en.xml
  3430. Dim language As String = ""
  3431. If item.Language.Value <> "" Then
  3432. language = item.Language.Value
  3433. Else
  3434. language = "en"
  3435. End If
  3436. Dim sortorder As String = item.SortOrder.Value
  3437. Dim url As String = "http://www.thetvdb.com/api/6E82FED600783400/series/" & showid & "/all/" & language & ".xml"
  3438. If sortorder = "" Then
  3439. sortorder = "default"
  3440. End If
  3441. Dim xmlfile As String = SeriesXmlPath & showid & ".xml"
  3442. Dim SeriesInfo As New Tvdb.ShowData
  3443. If Not File.Exists(SeriesXmlPath & showid & ".xml") OrElse Pref.DlMissingEpData Then
  3444. If Not DownloadCache.Savexmltopath(url, SeriesXmlPath, showid & ".xml", True) Then
  3445. MsgBox("Error retrieving data from show" & vbCrLf & "-- " & item.Title.Value.ToString & " --", )
  3446. Continue For
  3447. End If
  3448. End If
  3449. SeriesInfo.Load(xmlfile)
  3450. For Each NewEpisode As Tvdb.Episode In SeriesInfo.Episodes
  3451. If Pref.ignoreMissingSpecials AndAlso NewEpisode.SeasonNumber.Value = "0" Then
  3452. Dim missingspecialnfo As String = Utilities.MissingPath & item.TvdbId.Value & "." & NewEpisode.SeasonNumber.Value & "." & NewEpisode.EpisodeNumber.Value & ".nfo"
  3453. If IO.File.Exists(missingspecialnfo) Then
  3454. Utilities.SafeDeleteFile(missingspecialnfo)
  3455. End If
  3456. Continue For
  3457. End If
  3458. Dim Episode As TvEpisode = item.GetEpisode(NewEpisode.SeasonNumber.Value, NewEpisode.EpisodeNumber.Value)
  3459. If Episode Is Nothing OrElse Not IO.File.Exists(Episode.NfoFilePath) Then
  3460. Dim MissingEpisode As New Media_Companion.TvEpisode
  3461. MissingEpisode.NfoFilePath = Utilities.MissingPath & item.TvdbId.Value & "." & NewEpisode.SeasonNumber.Value & "." & NewEpisode.EpisodeNumber.Value & ".nfo"
  3462. If Not IO.File.Exists(MissingEpisode.NfoFilePath) OrElse Pref.DlMissingEpData Then
  3463. MissingEpisode.AbsorbTvdbEpisode(NewEpisode)
  3464. MissingEpisode.IsMissing = True
  3465. MissingEpisode.IsCache = True
  3466. MissingEpisode.ShowObj = item
  3467. MissingEpisode.Save()
  3468. Else
  3469. MissingEpisode.Load()
  3470. End If
  3471. item.AddEpisode(MissingEpisode)
  3472. Bckgrndfindmissingepisodes.ReportProgress(1, MissingEpisode)
  3473. End If
  3474. Next
  3475. End If
  3476. End If
  3477. Next
  3478. Tv_CacheSave()
  3479. End Sub
  3480. Public Function tv_EpisodesMissingUpdate(ByRef newEpList As List(Of TvEpisode)) As Boolean
  3481. Dim Removed As Boolean = False
  3482. Try
  3483. 'Dim missingPath = IO.Path.Combine(Pref.applicationPath, "missing\") '& item.TvdbId.Value & "." & NewEpisode.SeasonNumber.Value & "." & NewEpisode.EpisodeNumber.Value & ".nfo")
  3484. For Each Ep In newEpList
  3485. If IO.File.Exists(Ep.NfoFilePath) Then
  3486. Dim missingEpNfoPath As String = Utilities.MissingPath & Ep.TvdbId.Value & "." & Ep.Season.Value & "." & Ep.Episode.Value & ".nfo"
  3487. If IO.File.Exists(missingEpNfoPath) Then
  3488. IO.File.Delete(missingEpNfoPath)
  3489. Dim Ep2Remove As New TvEpisode
  3490. For Each epis As TvEpisode In Cache.TvCache.Episodes
  3491. If epis.TvdbId.Value = Ep.TvdbId.Value Then
  3492. If epis.Season.Value = Ep.Season.Value AndAlso epis.Episode.Value = Ep.Episode.Value AndAlso epis.IsMissing = True Then
  3493. Ep2Remove = epis
  3494. Removed = True
  3495. Exit For
  3496. End If
  3497. End If
  3498. Next
  3499. If Removed Then Cache.TvCache.Remove(Ep2Remove)
  3500. End If
  3501. End If
  3502. Next
  3503. Catch
  3504. End Try
  3505. Return Removed
  3506. End Function
  3507. 'Public Sub tv_EpisodesMissingClean()
  3508. ' Dim dir_info As New IO.DirectoryInfo(Utilities.MissingPath)
  3509. ' For Each File in dir_info.GetFiles(".nfo")
  3510. ' If IO.File.Exists(File.Fullname) Then
  3511. ' Try
  3512. ' IO.File.Delete(File.FullName)
  3513. ' Catch
  3514. ' End Try
  3515. ' End If
  3516. ' Next
  3517. 'End Sub
  3518. #End Region
  3519. Public Sub New()
  3520. ' This call is required by the designer.
  3521. InitializeComponent()
  3522. ' Add any initialization after the InitializeComponent() call.
  3523. End Sub
  3524. 'Private Sub cmdTasks_Refresh_Click(sender As System.Object, e As System.EventArgs) Handles cmdTasks_Refresh.Click
  3525. ' TasksList.Items.Clear()
  3526. ' 'tv_MissingArtDownload(tv_ShowSelectedCurrently)
  3527. ' For Each Item As ITask In Common.Tasks
  3528. ' TasksList.Items.Add(Item)
  3529. ' Next
  3530. 'End Sub
  3531. #Region "Tasks"
  3532. Private Sub lstTasks_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TasksList.SelectedIndexChanged
  3533. If TasksList.SelectedItem Is Nothing Then Exit Sub
  3534. Dim SelectedTask As ITask
  3535. SelectedTask = TasksList.SelectedItem
  3536. Select Case SelectedTask.State
  3537. Case TaskState.Completed
  3538. TasksStateLabel.Text = "Completed"
  3539. Case TaskState.BackgroundWorkComplete
  3540. TasksStateLabel.Text = "Background Completed"
  3541. Case TaskState.CriticalFault
  3542. TasksStateLabel.Text = "Critial Fault"
  3543. Case TaskState.Fault
  3544. TasksStateLabel.Text = "Fault"
  3545. Case TaskState.Halted
  3546. TasksStateLabel.Text = "Halted"
  3547. Case TaskState.NotStarted
  3548. TasksStateLabel.Text = "Not Started"
  3549. Case TaskState.WaitingForUserInput
  3550. TasksStateLabel.Text = "Waiting For Input"
  3551. Case TaskState.Running
  3552. TasksStateLabel.Text = "Running"
  3553. End Select
  3554. 'lblTask_Attempts.Text = SelectedTask.Attempts
  3555. TasksArgumentSelector.Items.Clear()
  3556. TasksArgumentSelector.Text = ""
  3557. For Each Item In SelectedTask.Arguments
  3558. TasksArgumentSelector.Items.Add(Item)
  3559. Next
  3560. If TasksArgumentSelector.Items.Count > 0 Then TasksArgumentSelector.SelectedIndex = 0
  3561. TasksDependancies.Items.Clear()
  3562. For Each Item In SelectedTask.Dependancies
  3563. TasksDependancies.Items.Add(Item)
  3564. Next
  3565. TasksMessages.Items.Clear()
  3566. For Each Item In SelectedTask.Messages
  3567. TasksMessages.Items.Add(Item)
  3568. Next
  3569. End Sub
  3570. Private Sub lstTasks_Messages_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TasksMessages.SelectedIndexChanged
  3571. If TasksMessages.SelectedItem Is Nothing Then Exit Sub
  3572. TasksSelectedMessage.Text = TasksMessages.SelectedItem
  3573. End Sub
  3574. Private Sub cmbTasks_Arguments_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TasksArgumentSelector.SelectedIndexChanged
  3575. If TasksArgumentSelector.SelectedItem Is Nothing Then Exit Sub
  3576. TasksArgumentDisplay.Controls.Clear()
  3577. Dim Item As KeyValuePair(Of String, Object) = TasksArgumentSelector.SelectedItem
  3578. If TypeOf Item.Value Is String Then
  3579. TasksArgumentDisplay.Controls.Add(New TextBox() With {.Text = Item.Value, .Dock = DockStyle.Fill, .Multiline = True, .ScrollBars = ScrollBars.Both})
  3580. ElseIf TypeOf Item.Value Is TvShow Then
  3581. Dim TempShow As TvShow = Item.Value
  3582. TasksArgumentDisplay.Controls.Add(New TextBox() With {.Text = TempShow.TvdbId.Value & " - " & TempShow.Title.Value, .Dock = DockStyle.Fill, .ScrollBars = ScrollBars.Both})
  3583. ElseIf TypeOf Item.Value Is TvEpisode Then
  3584. Dim TempEpisode As TvEpisode = Item.Value
  3585. TasksArgumentDisplay.Controls.Add(New TextBox() With {.Text = TempEpisode.Id.Value & " - " & TempEpisode.Title.Value, .Dock = DockStyle.Fill, .ScrollBars = ScrollBars.Both})
  3586. ElseIf TypeOf Item.Value Is Image Then
  3587. TasksArgumentDisplay.Controls.Add(New PictureBox() With {.Image = Item.Value, .Dock = DockStyle.Fill})
  3588. End If
  3589. End Sub
  3590. Private Sub TasksTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TasksTest.Click
  3591. For I = 0 To 20
  3592. Common.Tasks.Add(New Tasks.BlankTask())
  3593. Next
  3594. RefreshTaskList()
  3595. End Sub
  3596. Private Sub TasksRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TasksRefresh.Click
  3597. RefreshTaskList()
  3598. End Sub
  3599. Private Sub TasksClearCompleted_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TasksClearCompleted.Click
  3600. 'Manually building a for loop
  3601. Dim Count As Long = Common.Tasks.Count
  3602. Dim Cursor As Long = 0
  3603. Dim CurrentTask As ITask
  3604. Do
  3605. CurrentTask = Common.Tasks(Cursor)
  3606. If CurrentTask.State = TaskState.Completed Then
  3607. Common.Tasks.Remove(CurrentTask)
  3608. Count -= 1
  3609. Else
  3610. Cursor += 1
  3611. End If
  3612. If Count < 1 Or Cursor >= Count Then
  3613. Exit Do
  3614. End If
  3615. System.Windows.Forms.Application.DoEvents()
  3616. Loop
  3617. RefreshTaskList()
  3618. End Sub
  3619. Public TasksOnlyIncompleteTasks As Boolean = True
  3620. Public Sub RefreshTaskList()
  3621. For Each Item As ITask In Common.Tasks
  3622. If Not (TasksOnlyIncompleteTasks AndAlso Item.State = TaskState.Completed) AndAlso Not TasksList.Items.Contains(Item) Then
  3623. TasksList.Items.Add(Item)
  3624. System.Windows.Forms.Application.DoEvents()
  3625. End If
  3626. Next
  3627. Dim taskCount = TasksList.Items.Count
  3628. Dim Cursor = 0
  3629. Dim CurrentTask As ITask
  3630. Do
  3631. If taskCount < 1 Or Cursor >= taskCount Then
  3632. Exit Do
  3633. End If
  3634. Try
  3635. CurrentTask = TasksList.Items(Cursor)
  3636. If (TasksOnlyIncompleteTasks AndAlso CurrentTask.State = TaskState.Completed) OrElse Not Common.Tasks.Contains(CurrentTask) Then
  3637. TasksList.Items.Remove(CurrentTask)
  3638. taskCount -= 1
  3639. Else
  3640. Cursor += 1
  3641. End If
  3642. Catch
  3643. End Try
  3644. System.Windows.Forms.Application.DoEvents()
  3645. Loop
  3646. End Sub
  3647. #End Region
  3648. #Region "Tv Artwork, TV Actor & EP Thumbnail Routines"
  3649. Private Function TvGetArtwork(ByVal currentshow As Media_Companion.TvShow, ByVal shFanart As Boolean, ByVal shPosters As Boolean, ByVal shSeason As Boolean, ByVal shXtraFanart As Boolean, Optional ByVal langu As String = "", Optional ByVal force As Boolean = True) As Boolean
  3650. '(ByVal currentshow As Media_Companion.TvShow, Optional ByVal shFanart As Boolean = True, Optional ByVal shPosters As Boolean = True,Optional ByVal shSeason As Boolean = True)
  3651. Dim success As Boolean = False
  3652. Try
  3653. Dim MaxSeasonNo As Integer = 1
  3654. Dim tvdbstuff As New TVDBScraper
  3655. Dim currentshowpath As String = currentshow.NfoFilePath.Replace("tvshow.nfo", "")
  3656. Dim eden As Boolean = Pref.EdenEnabled
  3657. Dim frodo As Boolean = Pref.FrodoEnabled
  3658. Dim overwriteimage As Boolean = If(Pref.overwritethumbs OrElse Pref.TvChgShowOverwriteImgs, True, False)
  3659. If Not force then overwriteimage = False 'Over-ride overwrite if we force not to overwrite, ie: missing artwork
  3660. Dim doPoster As Boolean = If(Pref.tvdlposter OrElse Pref.TvChgShowDlPoster, True, False)
  3661. Dim doFanart As Boolean = If(Pref.tvdlfanart OrElse Pref.TvChgShowDlFanart, True, False)
  3662. Dim doSeason As Boolean = If(Pref.tvdlseasonthumbs OrElse Pref.TvChgShowDlSeasonthumbs, True, False)
  3663. Dim artlist As New List(Of TvBanners)
  3664. artlist.Clear()
  3665. Dim thumblist As String = tvdbstuff.GetPosterList(currentshow.TvdbId.Value, artlist)
  3666. Dim isposter As String = Pref.postertype
  3667. Dim isseasonall As String = Pref.seasonall
  3668. Dim Langlist As New List(Of String)
  3669. If Not langu = "" Then Langlist.Add(langu)
  3670. Langlist.Add(currentshow.Language.Value)
  3671. If Not Langlist.Contains("en") Then Langlist.Add("en")
  3672. If Not Langlist.Contains(Pref.TvdbLanguageCode) Then Langlist.Add(Pref.TvdbLanguageCode)
  3673. Langlist.Add("")
  3674. If artlist.Count = 0 Then Exit Function
  3675. For each art In artlist
  3676. If Not IsNothing(art.Season) AndAlso art.Season.ToInt > MaxSeasonNo Then MaxSeasonNo = art.Season.ToInt
  3677. Next
  3678. 'Posters, Main and Season Including Banners
  3679. If shPosters Then
  3680. 'Main Poster
  3681. If (isposter = "poster" Or frodo Or isseasonall = "poster") And doPoster Then 'poster
  3682. Dim mainposter As String = Nothing
  3683. For Each lang In Langlist
  3684. For Each Image In artlist
  3685. If (Image.Language = lang Or lang = "") AndAlso Image.BannerType = "poster" Then
  3686. mainposter = Image.Url
  3687. Exit For
  3688. End If
  3689. Next
  3690. If Not IsNothing(mainposter) Then Exit For
  3691. Next
  3692. If Not IsNothing(mainposter) Then
  3693. Dim imgpaths As New List(Of String)
  3694. If frodo Then imgpaths.Add(currentshowpath & "poster.jpg")
  3695. If eden AndAlso isposter = "poster" Then imgpaths.Add(currentshowpath & "folder.jpg")
  3696. If frodo AndAlso isseasonall <> "none" Then imgpaths.Add(currentshowpath & "season-all-poster.jpg")
  3697. If eden AndAlso isseasonall = "poster" Then imgpaths.Add(currentshowpath & "season-all.tbn")
  3698. success = DownloadCache.SaveImageToCacheAndPaths(mainposter, imgpaths, False, , ,overwriteimage)
  3699. Dim popath As String = Utilities.save2postercache(currentshow.NfoFilePath, currentshow.ImagePoster.Path, WallPicWidth, WallPicHeight)
  3700. updateTvPosterWall(popath, currentshow.NfoFilePath)
  3701. End If
  3702. End If
  3703. 'Main Banner
  3704. If (isposter = "banner" Or frodo Or isseasonall = "wide") And doPoster Then 'banner
  3705. Dim mainbanner As String = Nothing
  3706. For Each lang In Langlist
  3707. For Each Image In artlist
  3708. If (Image.Language = lang Or lang = "") AndAlso Image.BannerType = "series" AndAlso Image.Season = Nothing Then
  3709. mainbanner = Image.Url
  3710. Exit For
  3711. End If
  3712. Next
  3713. If Not IsNothing(mainbanner) Then Exit For
  3714. Next
  3715. If Not IsNothing(mainbanner) Then
  3716. Dim imgpaths As New List(Of String)
  3717. If frodo then imgpaths.Add(currentshowpath & "banner.jpg")
  3718. If eden AndAlso isposter = "banner" Then imgpaths.Add(currentshowpath & "folder.jpg")
  3719. If frodo AndAlso isseasonall <> "none" Then imgpaths.Add(currentshowpath & "season-all-banner.jpg")
  3720. If eden AndAlso isseasonall = "wide" Then imgpaths.Add(currentshowpath & "season-all.tbn")
  3721. success = DownloadCache.SaveImageToCacheAndPaths(mainbanner, imgpaths, False, , ,overwriteimage)
  3722. End If
  3723. End If
  3724. End If
  3725. 'Dim shSeason As Boolean =True
  3726. If shSeason Then
  3727. 'SeasonXX Poster
  3728. For f = 0 To MaxSeasonNo+1
  3729. If (isposter = "poster" Or frodo) And doSeason Then 'poster
  3730. Dim seasonXXposter As String = Nothing
  3731. For Each lang In Langlist
  3732. For Each Image In artlist
  3733. If Image.Season = f.ToString AndAlso (Image.Language = lang Or lang = "") Then
  3734. seasonXXposter = Image.Url
  3735. Exit For
  3736. End If
  3737. Next
  3738. If Not IsNothing(seasonXXposter) Then Exit For
  3739. Next
  3740. If Not IsNothing(seasonXXposter) Then
  3741. Dim tempstring As String = ""
  3742. If f < 10 Then
  3743. tempstring = "0" & f.ToString
  3744. Else
  3745. tempstring = f.ToString
  3746. End If
  3747. If tempstring = "00" Then tempstring = "-specials"
  3748. Dim imgpaths As New List(Of String)
  3749. If frodo Then imgpaths.Add(currentshowpath & "season" & tempstring & "-poster.jpg")
  3750. If eden Then imgpaths.Add(currentshowpath & "season" & tempstring & ".tbn")
  3751. success = DownloadCache.SaveImageToCacheAndPaths(seasonXXposter, imgpaths, False, , ,overwriteimage)
  3752. End If
  3753. End If
  3754. 'SeasonXX Banner
  3755. If (isposter = "banner" Or frodo) And doSeason Then 'banner
  3756. Dim seasonXXbanner As String = Nothing
  3757. For Each lang In Langlist
  3758. For Each Image In artlist
  3759. If Image.Season = f.ToString AndAlso (Image.Language = lang Or lang = "") AndAlso Image.Resolution = "seasonwide" Then
  3760. seasonXXbanner = Image.Url
  3761. Exit For
  3762. End If
  3763. Next
  3764. If Not IsNothing(seasonXXbanner) Then Exit For
  3765. Next
  3766. If seasonXXbanner <> "" Then
  3767. Dim tempstring As String = ""
  3768. If f < 10 Then
  3769. tempstring = "0" & f.ToString
  3770. Else
  3771. tempstring = f.ToString
  3772. End If
  3773. If tempstring = "00" Then tempstring = "-specials"
  3774. Dim imgpaths As New List(Of String)
  3775. If frodo Then imgpaths.Add(currentshowpath & "season" & tempstring & "-banner.jpg")
  3776. If eden Then imgpaths.Add(currentshowpath & "season" & tempstring & ".tbn")
  3777. success = DownloadCache.SaveImageToCacheAndPaths(seasonXXbanner, imgpaths, False, , ,overwriteimage)
  3778. End If
  3779. End If
  3780. Next
  3781. TvCheckfolderjpgart(currentshow)
  3782. End If
  3783. 'Main Fanart
  3784. If shFanart AndAlso doFanart Then
  3785. Dim fanartposter As String = Nothing
  3786. For Each lang In Langlist
  3787. For Each Image In artlist
  3788. If (Image.Language = lang Or lang = "") AndAlso Image.BannerType = "fanart" Then
  3789. fanartposter = Image.Url
  3790. Exit For
  3791. End If
  3792. Next
  3793. If Not IsNothing(fanartposter) Then Exit For
  3794. Next
  3795. If Not IsNothing(fanartposter) Then
  3796. Dim imgpaths As New List(Of String)
  3797. imgpaths.Add(currentshowpath & "fanart.jpg")
  3798. If frodo And isseasonall <> "none" Then imgpaths.Add(currentshowpath & "season-all-fanart.jpg")
  3799. success = DownloadCache.SaveImageToCacheAndPaths(fanartposter, imgpaths, False, , ,overwriteimage)
  3800. End If
  3801. End If
  3802. 'ExtraFanart
  3803. If shXtraFanart Then
  3804. Dim xfanart As String = currentshowpath & "extrafanart\"
  3805. Dim fanartposter As New List(Of TVBanners)
  3806. For Each lang In Langlist
  3807. For Each Image In artlist
  3808. If (Image.Language = lang Or lang = "") AndAlso Image.BannerType = "fanart" Then
  3809. fanartposter.Add(Image)
  3810. End If
  3811. Next
  3812. Next
  3813. If fanartposter.Count > 0 Then
  3814. Dim x As Integer = 0
  3815. Do Until x = Pref.TvXtraFanartQty
  3816. If x = fanartposter.Count Then Exit Do
  3817. success = Utilities.DownloadFile(fanartposter(x).url, (xfanart & fanartposter(x).id & ".jpg"))
  3818. x = x + 1
  3819. Loop
  3820. End If
  3821. End If
  3822. Catch
  3823. End Try
  3824. Return success
  3825. End Function
  3826. Private Function TvGetActorTvdb(ByRef NewShow As Media_Companion.TvShow) As Boolean
  3827. Dim success As Boolean = True
  3828. Dim tvdbstuff As New TVDBScraper
  3829. Dim tempstring As String = ""
  3830. Dim TvdbActors As List(Of str_MovieActors) = tvdbstuff.GetActors(NewShow.TvdbId.Value, templanguage)
  3831. Dim workingpath As String = ""
  3832. If Pref.actorseasy AndAlso Not Pref.tvshowautoquick Then
  3833. workingpath = NewShow.NfoFilePath.Replace(IO.Path.GetFileName(NewShow.NfoFilePath), "") & ".actors\"
  3834. Utilities.EnsureFolderExists(workingpath)
  3835. End If
  3836. For Each NewAct In TvdbActors
  3837. Dim id As String = If(NewAct.ActorId = Nothing, "", NewAct.ActorId)
  3838. Dim results As XmlNode = Nothing
  3839. Dim filename As String = Utilities.cleanFilenameIllegalChars(NewAct.actorname)
  3840. filename = filename.Replace(" ", "_")
  3841. If Not String.IsNullOrEmpty(NewAct.actorthumb) And NewAct.actorthumb <> "http://thetvdb.com/banners/" Then
  3842. 'Save to .actor folder
  3843. If NewAct.actorthumb <> "" And Pref.actorseasy = True And Pref.tvshowautoquick = False Then
  3844. If NewShow.TvShowActorSource.Value <> "imdb" Or NewShow.ImdbId = Nothing Then
  3845. Dim ActorFilename As String = IO.Path.Combine(workingpath, filename)
  3846. Dim actorpaths As New List(Of String)
  3847. If Pref.FrodoEnabled Then actorpaths.Add(ActorFilename & ".jpg")
  3848. If Pref.EdenEnabled Then actorpaths.Add(ActorFilename & ".tbn")
  3849. Dim cachename As String = Utilities.Download2Cache(NewAct.actorthumb)
  3850. If cachename <> "" Then
  3851. For Each p In actorpaths
  3852. Utilities.SafeCopyFile(cachename, p, Pref.overwritethumbs)
  3853. Next
  3854. End If
  3855. End If
  3856. End If
  3857. 'Save to Local actor folder
  3858. If Pref.actorsave = True And id <> "" Then 'Allow Local folder save, separate from .actor folder saving
  3859. Dim workingpath2 As String = ""
  3860. Dim networkpath As String = Pref.actorsavepath
  3861. filename = filename & "_" & id
  3862. tempstring = networkpath & "\" & filename.Substring(0,1) & "\"
  3863. Utilities.EnsureFolderExists(tempstring)
  3864. workingpath2 = tempstring & filename
  3865. Dim actorpaths As New List(Of String)
  3866. If Pref.FrodoEnabled Then actorpaths.Add(workingpath2 & ".jpg")
  3867. If Pref.EdenEnabled Then actorpaths.Add(workingpath2 & ".tbn")
  3868. Dim cachename As String = Utilities.Download2Cache(NewAct.actorthumb)
  3869. If cachename <> "" Then
  3870. For Each p In actorpaths
  3871. Utilities.SafeCopyFile(cachename, p, Pref.overwritethumbs)
  3872. Next
  3873. End If
  3874. NewAct.actorthumb = actorpaths(0)
  3875. If Pref.actornetworkpath.IndexOf("/") <> -1 Then
  3876. NewAct.actorthumb = actorpaths(0).Replace(networkpath, Pref.actornetworkpath).Replace("\","/")
  3877. ElseIf Pref.actornetworkpath.IndexOf("\") <> -1
  3878. NewAct.actorthumb = actorpaths(0).Replace(networkpath, Pref.actornetworkpath).Replace("/","\")
  3879. End If
  3880. End If
  3881. End If
  3882. Dim exists As Boolean = False
  3883. NewShow.ListActors.Add(NewAct)
  3884. Next
  3885. Return success
  3886. End Function
  3887. Private Function TvGetActorImdb(ByRef NewShow As Media_Companion.TvShow) As Boolean
  3888. Dim imdbscraper As New Classimdb
  3889. Dim success As Boolean = True
  3890. Dim actmax As Integer = Pref.maxactors
  3891. Dim actcount As Integer = 0
  3892. Dim actorstring As New XmlDocument
  3893. If String.IsNullOrEmpty(NewShow.ImdbId.Value) Then Return success
  3894. Dim actorlist As List(Of str_MovieActors) = imdbscraper.GetImdbActorsList(Pref.imdbmirror, NewShow.ImdbId.Value, actmax)
  3895. Dim workingpath As String = ""
  3896. If Pref.actorseasy And Not Pref.tvshowautoquick Then
  3897. workingpath = NewShow.NfoFilePath.Replace(IO.Path.GetFileName(NewShow.NfoFilePath), "")
  3898. workingpath = workingpath & ".actors\"
  3899. Utilities.EnsureFolderExists(workingpath)
  3900. End If
  3901. For Each thisresult In actorlist
  3902. If Not String.IsNullOrEmpty(thisresult.actorthumb) AndAlso Not String.IsNullOrEmpty(thisresult.actorid) AndAlso actcount < (actmax + 1) Then
  3903. If Pref.actorseasy And Not Pref.tvshowautoquick Then
  3904. Dim actorpaths As New List(Of String)
  3905. Dim filename As String = Utilities.cleanFilenameIllegalChars(thisresult.actorname)
  3906. filename = filename.Replace(" ", "_")
  3907. filename = IO.Path.Combine(workingpath, filename)
  3908. If Pref.FrodoEnabled Then actorpaths.Add(filename & ".jpg")
  3909. If Pref.EdenEnabled Then actorpaths.Add(filename & ".tbn")
  3910. Dim cachename As String = Utilities.Download2Cache(thisresult.actorthumb)
  3911. If cachename <> "" Then
  3912. For Each p In actorpaths
  3913. Utilities.SafeCopyFile(cachename, p, Pref.overwritethumbs)
  3914. Next
  3915. End If
  3916. End If
  3917. If Pref.actorsave = True AndAlso Pref.tvshowautoquick = False Then
  3918. Dim tempstring As String = Pref.actorsavepath
  3919. Dim workingpath2 As String = ""
  3920. If Pref.actorsavealpha Then
  3921. Dim actorfilename As String = thisresult.actorname.Replace(" ", "_") & "_" & thisresult.actorid ' & ".tbn"
  3922. tempstring = tempstring & "\" & actorfilename.Substring(0,1) & "\"
  3923. workingpath2 = tempstring & actorfilename
  3924. Else
  3925. tempstring = tempstring & "\" & thisresult.actorid.Substring(thisresult.actorid.Length - 2, 2) & "\"
  3926. workingpath2 = tempstring & thisresult.actorid ' & ".tbn"
  3927. End If
  3928. Dim actorpaths As New List(Of String)
  3929. If Pref.FrodoEnabled Then actorpaths.Add(workingpath2 & ".jpg")
  3930. If Pref.EdenEnabled Then actorpaths.Add(workingpath2 & ".tbn")
  3931. Utilities.EnsureFolderExists(tempstring)
  3932. Dim cachename As String = Utilities.Download2Cache(thisresult.actorthumb)
  3933. If cachename <> "" Then
  3934. For Each p In actorpaths
  3935. Utilities.SafeCopyFile(cachename, p, Pref.overwritethumbs)
  3936. Next
  3937. End If
  3938. If Not String.IsNullOrEmpty(Pref.actornetworkpath) Then
  3939. If Pref.actornetworkpath.IndexOf("/") <> -1 Then
  3940. thisresult.actorthumb = actorpaths(0).Replace(Pref.actorsavepath, Pref.actornetworkpath).Replace("\", "/")
  3941. Else
  3942. thisresult.actorthumb = actorpaths(0).Replace(Pref.actorsavepath, Pref.actornetworkpath).Replace("/", "\")
  3943. End If
  3944. End If
  3945. End If
  3946. End If
  3947. NewShow.ListActors.Add(thisresult)
  3948. success = True
  3949. actcount += 1
  3950. Next
  3951. While NewShow.ListActors.Count > actmax
  3952. NewShow.ListActors.RemoveAt(NewShow.ListActors.Count - 1)
  3953. End While
  3954. Return success
  3955. End Function
  3956. Private Sub FixTvActorsNfo(ByRef TvSeries As TvShow)
  3957. 'If XBMC networkpath changed, update actor thumb path
  3958. For Each tvActor In TvSeries.listactors
  3959. If Pref.actorsave AndAlso tvActor.actorid <> "" Then
  3960. If Not String.IsNullOrEmpty(Pref.actorsavepath) Then
  3961. Dim tempstring As String = Pref.actorsavepath
  3962. Dim workingpath As String = ""
  3963. If Pref.actorsavealpha Then
  3964. Dim actorfilename As String = tvActor.actorname.Replace(" ", "_") & "_" & tvActor.actorid & ".jpg"
  3965. tempstring = tempstring & "\" & actorfilename.Substring(0,1) & "\"
  3966. workingpath = tempstring & actorfilename
  3967. Else
  3968. tempstring = tempstring & "\" & tvActor.actorid.Substring(tvActor.actorid.Length - 2, 2) & "\"
  3969. workingpath = tempstring & tvActor.actorid & ".jpg"
  3970. End If
  3971. If Not String.IsNullOrEmpty(Pref.actornetworkpath) Then
  3972. If Pref.actornetworkpath.IndexOf("/") <> -1 Then
  3973. tvActor.actorthumb = workingpath.Replace(Pref.actorsavepath, Pref.actornetworkpath).Replace("\", "/")
  3974. Else
  3975. tvActor.actorthumb = workingpath.Replace(Pref.actorsavepath, Pref.actornetworkpath).Replace("/", "\")
  3976. End If
  3977. End If
  3978. End If
  3979. End If
  3980. Next
  3981. End Sub
  3982. Private Sub TvDeleteShowArt(ByVal NewShow As Media_Companion.TvShow, Optional ByVal NotActors As Boolean = True)
  3983. Try
  3984. Dim workingpath As String = NewShow.FolderPath
  3985. If NotActors AndAlso Directory.Exists(workingpath & ".actors") Then Directory.Delete(workingpath & ".actors", True)
  3986. If Directory.Exists(workingpath & "extrafanart") Then Directory.Delete(workingpath & "extrafanart", True)
  3987. Dim artextn() As String = "*.jpg:*.tbn:*.png".Split(":")
  3988. For Each arttype In artextn
  3989. For Each filepath In Directory.GetFiles(workingpath, arttype, SearchOption.TopDirectoryOnly)
  3990. File.Delete(filepath)
  3991. Next
  3992. Next
  3993. Dim seasonfolderpath As String = ""
  3994. For Each ep As Media_Companion.TvEpisode In NewShow.Episodes
  3995. seasonfolderpath = ep.FolderPath
  3996. If File.Exists(seasonfolderpath & "folder.jpg") Then Utilities.SafeDeleteFile(seasonfolderpath & "folder.jpg")
  3997. Next
  3998. Catch ex As Exception
  3999. End Try
  4000. End Sub
  4001. Private Sub TvDeleteEpisodeNfoAndArt(ByVal NewShow As Media_Companion.TvShow)
  4002. Try
  4003. For Each ep As Media_Companion.TvEpisode In NewShow.Episodes
  4004. Dim eppath As String = ep.NfoFilePath.Replace(".nfo", "")
  4005. If File.Exists(eppath & "-fanart.jpg") Then Utilities.SafeDeleteFile(eppath & "-fanart.jpg")
  4006. If File.Exists(eppath & ".tbn") Then Utilities.SafeDeleteFile(eppath & ".tbn")
  4007. If File.Exists(ep.FolderPath & "folder.jpg") Then Utilities.SafeDeleteFile(ep.FolderPath & "folder.jpg")
  4008. If File.Exists(ep.NfoFilePath) Then Utilities.SafeDeleteFile(ep.NfoFilePath)
  4009. Next
  4010. Catch ex As Exception
  4011. End Try
  4012. End Sub
  4013. Public Sub tv_MissingArtDownload(ByVal BrokenShow As TvShow)
  4014. Dim messbox As New frmMessageBox("Attempting to download art", "", " Please Wait")
  4015. messbox.Show()
  4016. messbox.Refresh()
  4017. Application.DoEvents()
  4018. Try
  4019. If Pref.TvFanartTvFirst Then
  4020. If Pref.TvDlFanartTvArt Then TvFanartTvArt(BrokenShow, False)
  4021. TvGetArtwork(BrokenShow, True, True, True, Pref.dlTVxtrafanart, force:= False)
  4022. Else
  4023. TvGetArtwork(BrokenShow, True, True, True, Pref.dlTVxtrafanart, force:= False)
  4024. If Pref.TvDlFanartTvArt Then TvFanartTvArt(BrokenShow, False)
  4025. End If
  4026. If Pref.tvfolderjpg OrElse Pref.seasonfolderjpg Then
  4027. TvCheckfolderjpgart(BrokenShow)
  4028. End If
  4029. Catch
  4030. End Try
  4031. Call tv_ShowLoad(BrokenShow)
  4032. messbox.Close()
  4033. End Sub
  4034. Private Sub TvCheckfolderjpgart(ByVal ThisShow As TvShow)
  4035. Dim currentshowpath As String = ThisShow.FolderPath
  4036. If Pref.tvfolderjpg AndAlso Not File.Exists(currentshowpath & "folder.jpg") Then
  4037. If File.Exists(currentshowpath & "poster.jpg") AndAlso Pref.FrodoEnabled Then
  4038. Utilities.SafeCopyFile(currentshowpath & "poster.jpg", currentshowpath & "folder.jpg", False)
  4039. End If
  4040. End If
  4041. Dim I = 1
  4042. If Pref.seasonfolderjpg Then
  4043. For Each Seas In ThisShow.Seasons.Values
  4044. If Seas.FolderPath <> ThisShow.FolderPath Then
  4045. Dim seasonfile As String = Seas.Poster.FileName '= Seas.SeasonLabel.ToLower.Replace(" ", "")& "-poster.jpg"
  4046. If File.Exists(ThisShow.FolderPath & seasonfile) AndAlso Not File.Exists(Seas.FolderPath & "folder.jpg") Then
  4047. Utilities.SafeCopyFile(ThisShow.FolderPath & seasonfile, Seas.FolderPath & "folder.jpg", False)
  4048. End If
  4049. End If
  4050. Next
  4051. End If
  4052. End Sub
  4053. Private Sub TvEpThumbScreenShot()
  4054. Try
  4055. Dim aok As Boolean = False
  4056. Dim WorkingEpisode As TvEpisode = ep_SelectedCurrently(TvTreeview)
  4057. If WorkingEpisode.IsMissing Then Exit Sub
  4058. If TextBox35.Text = "" Then TextBox35.Text = Pref.ScrShtDelay
  4059. If IsNumeric(TextBox35.Text) Then
  4060. Dim paths As New List(Of String)
  4061. If Pref.EdenEnabled Then paths.Add(WorkingEpisode.NfoFilePath.Replace(".nfo", ".tbn"))
  4062. If Pref.FrodoEnabled Then paths.Add(WorkingEpisode.NfoFilePath.Replace(".nfo", "-thumb.jpg"))
  4063. Dim messbox As frmMessageBox = New frmMessageBox("ffmpeg is working to capture the desired screenshot", "", "Please Wait")
  4064. Dim tempstring2 As String = WorkingEpisode.VideoFilePath
  4065. If IO.File.Exists(tempstring2) Then
  4066. Dim seconds As Integer = Pref.ScrShtDelay
  4067. If Convert.ToInt32(TextBox35.Text) > 0 Then
  4068. seconds = Convert.ToInt32(TextBox35.Text)
  4069. End If
  4070. System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
  4071. messbox.Show()
  4072. messbox.Refresh()
  4073. Application.DoEvents()
  4074. Dim cachepathandfilename As String = Utilities.CreateScrnShotToCache(tempstring2, paths(0), seconds)
  4075. If cachepathandfilename <> "" Then
  4076. aok = True
  4077. Dim imagearr() As Integer = GetAspect(WorkingEpisode)
  4078. If Pref.tvscrnshtTVDBResize AndAlso Not imagearr(0) = 0 Then
  4079. DownloadCache.CopyAndDownSizeImage(cachepathandfilename, paths(0), imagearr(0), imagearr(1))
  4080. Else
  4081. File.Copy(cachepathandfilename, paths(0), True)
  4082. End If
  4083. If paths.Count > 1 Then File.Copy(paths(0), paths(1), True)
  4084. If File.Exists(paths(0)) Then
  4085. util_ImageLoad(pbTvEpScrnShot, paths(0), Utilities.DefaultTvFanartPath)
  4086. util_ImageLoad(tv_PictureBoxLeft, paths(0), Utilities.DefaultTvFanartPath)
  4087. Dim Rating As String = tb_EpRating.Text 'WorkingEpisode.Rating.Value
  4088. If TestForMultiepisode(WorkingEpisode.NfoFilePath) Then
  4089. Dim episodelist As New List(Of TvEpisode)
  4090. episodelist = WorkingWithNfoFiles.ep_NfoLoad(WorkingEpisode.NfoFilePath)
  4091. For Each Ep In episodelist
  4092. If Ep.Season.Value = WorkingEpisode.Season.Value And Ep.Episode.Value = WorkingEpisode.Episode.value Then
  4093. Dim video_flags = GetMultiEpMediaFlags(ep)
  4094. movieGraphicInfo.OverlayInfo(tv_PictureBoxLeft, Rating, video_flags)
  4095. End If
  4096. Next
  4097. Else
  4098. Dim video_flags = GetEpMediaFlags()
  4099. movieGraphicInfo.OverlayInfo(tv_PictureBoxLeft, Rating, video_flags)
  4100. End If
  4101. End If
  4102. End If
  4103. End If
  4104. messbox.Close()
  4105. If Not aok Then MsgBox("Could not create ScreenShot")
  4106. Else
  4107. MsgBox("Please enter a numerical value into the textbox")
  4108. TextBox34.Focus()
  4109. Exit Sub
  4110. End If
  4111. Catch ex As Exception
  4112. ExceptionHandler.LogError(ex)
  4113. End Try
  4114. End Sub
  4115. Private Sub TvEpThumbRescrape()
  4116. Try
  4117. Dim WorkingTvShow As TvShow = tv_ShowSelectedCurrently(TvTreeview)
  4118. Dim WorkingEpisode As TvEpisode = ep_SelectedCurrently(TvTreeview)
  4119. If WorkingEpisode.IsMissing Then Exit Sub
  4120. Dim messbox As frmMessageBox = New frmMessageBox("Checking TVDB for screenshot", "", "Please Wait")
  4121. Dim episodescraper As New TVDBScraper
  4122. Dim id As String = WorkingTvShow.TvdbId.Value
  4123. Dim sortorder As String = WorkingTvShow.SortOrder.Value
  4124. Dim seasonno As String = WorkingEpisode.Season.Value
  4125. Dim episodeno As String = WorkingEpisode.Episode.Value
  4126. Dim language As String = WorkingTvShow.Language.Value
  4127. Dim eden As Boolean = Pref.EdenEnabled
  4128. Dim frodo As Boolean = Pref.FrodoEnabled
  4129. If language = Nothing Then language = "en"
  4130. If language = "" Then language = "en"
  4131. If String.IsNullOrEmpty(sortorder) Then sortorder = "default"
  4132. 'If sortorder = Nothing Then sortorder = "default"
  4133. 'If sortorder = "" Then sortorder = "default"
  4134. If String.IsNullOrEmpty(id) Then
  4135. MsgBox("No ID is available for this show")
  4136. Exit Sub
  4137. End If
  4138. If String.IsNullOrEmpty(episodeno) Then
  4139. MsgBox("No Episode Number is available for this show")
  4140. Exit Sub
  4141. End If
  4142. If String.IsNullOrEmpty(seasonno) Then
  4143. MsgBox("No Season Number is available for this show")
  4144. Exit Sub
  4145. End If
  4146. System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
  4147. messbox.Show()
  4148. messbox.Refresh()
  4149. Application.DoEvents()
  4150. Dim tempepisode As String = episodescraper.getepisode(WorkingTvShow.TvdbId.Value, sortorder, seasonno, episodeno, language, True)
  4151. Dim thumburl As String = ""
  4152. messbox.Close()
  4153. Dim scrapedepisode As New XmlDocument
  4154. scrapedepisode.LoadXml(tempepisode)
  4155. Try
  4156. Dim thisresult As XmlNode = Nothing
  4157. For Each thisresult In scrapedepisode("episodedetails")
  4158. Select Case thisresult.Name
  4159. Case "thumb"
  4160. thumburl = thisresult.InnerText
  4161. Exit For
  4162. End Select
  4163. Next
  4164. Catch
  4165. End Try
  4166. If thumburl = "" Then
  4167. Dim tvdbstuff As New TVDBScraper
  4168. Dim tmpep As Tvdb.Episode = tvdbstuff.getepisodefromxml(WorkingTvShow.TvdbId.Value, sortorder, seasonno, episodeno, language, True)
  4169. If tmpep.ThumbNail.Value <> Nothing Then thumburl = tmpep.ThumbNail.Value
  4170. End If
  4171. Try
  4172. If thumburl <> "" And thumburl.ToLower <> "http://www.thetvdb.com/banners/" Then
  4173. messbox = New frmMessageBox("Screenshot found, downloading now", "", "Please Wait")
  4174. System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
  4175. messbox.Show()
  4176. messbox.Refresh()
  4177. Application.DoEvents()
  4178. Dim tempstring As String = WorkingEpisode.VideoFilePath.Replace(IO.Path.GetExtension(WorkingEpisode.VideoFilePath), ".tbn")
  4179. Dim cachename As String = Utilities.Download2Cache(thumburl)
  4180. If cachename <> "" Then
  4181. If eden Then Utilities.SafeCopyFile(cachename, tempstring, True)
  4182. If frodo Then
  4183. tempstring = tempstring.Replace(".tbn", "-thumb.jpg")
  4184. Utilities.SafeCopyFile(cachename, tempstring, True)
  4185. End If
  4186. util_ImageLoad(pbTvEpScrnShot, tempstring, Utilities.DefaultTvFanartPath)
  4187. util_ImageLoad(tv_PictureBoxLeft, tempstring, Utilities.DefaultTvFanartPath)
  4188. Dim Rating As String = tb_EpRating.Text 'WorkingEpisode.Rating.Value
  4189. If TestForMultiepisode(WorkingEpisode.NfoFilePath) Then
  4190. Dim episodelist As New List(Of TvEpisode)
  4191. episodelist = WorkingWithNfoFiles.ep_NfoLoad(WorkingEpisode.NfoFilePath)
  4192. For Each Ep In episodelist
  4193. If Ep.Season.Value = seasonno And Ep.Episode.Value = episodeno Then
  4194. Dim video_flags = GetMultiEpMediaFlags(ep)
  4195. movieGraphicInfo.OverlayInfo(tv_PictureBoxLeft, Rating, video_flags)
  4196. Exit For
  4197. End If
  4198. Next
  4199. Else
  4200. Dim video_flags = GetEpMediaFlags()
  4201. movieGraphicInfo.OverlayInfo(tv_PictureBoxLeft, Rating, video_flags)
  4202. End If
  4203. messbox.Close()
  4204. Else
  4205. messbox.Close()
  4206. MsgBox("Unable To Download Image")
  4207. End If
  4208. Else
  4209. MsgBox("No Episode Screenshot Found On TVDB")
  4210. End If
  4211. Catch ex As Exception
  4212. #If SilentErrorScream Then
  4213. Throw ex
  4214. #End If
  4215. Finally
  4216. messbox.Close()
  4217. End Try
  4218. Catch ex As Exception
  4219. ExceptionHandler.LogError(ex)
  4220. End Try
  4221. End Sub
  4222. Private Sub TvScrapePosterBanner(ByVal postertype As String)
  4223. Try
  4224. Dim WorkingTvShow As TvShow = tv_ShowSelectedCurrently(TvTreeview)
  4225. Dim messbox As frmMessageBox = New frmMessageBox("Searching TVDB for " & If(postertype = "poster", "Poster", "Banner"), "", "Please Wait")
  4226. System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
  4227. messbox.Show()
  4228. messbox.Refresh()
  4229. Application.DoEvents()
  4230. Dim id As String = WorkingTvShow.TvdbId.Value
  4231. Dim mainimages As Boolean = TypeOf TvTreeview.SelectedNode.Tag Is Media_Companion.TvShow
  4232. Dim posterpath As String = ""
  4233. Dim seasonno As String = ""
  4234. Dim seasonpath As String = ""
  4235. If Not mainimages Then
  4236. seasonno = tv_SeasonSelectedCurrently(TvTreeview).ToString
  4237. seasonno = seasonno.ToLower.Replace("season ", "")
  4238. Dim tmp As Integer = seasonno.ToInt
  4239. seasonno = tmp.ToString
  4240. If Pref.seasonfolderjpg Then
  4241. For Each ep As TvEpisode In WorkingTvShow.Episodes
  4242. If ep.Season.Value = seasonno Then
  4243. seasonpath = ep.FolderPath.Replace(WorkingTvShow.FolderPath, "")
  4244. Exit For
  4245. End If
  4246. Next
  4247. End If
  4248. End If
  4249. Dim language As String = WorkingTvShow.Language.Value
  4250. Dim eden As Boolean = Pref.EdenEnabled
  4251. Dim frodo As Boolean = Pref.FrodoEnabled
  4252. If String.IsNullOrEmpty(language) Then language = "en"
  4253. Dim tvdbstuff As New TVDBScraper
  4254. Dim artlist As New List(Of TvBanners)
  4255. artlist.Clear()
  4256. Dim thumblist As String = tvdbstuff.GetPosterList(id, artlist)
  4257. If artlist.Count = 0 Then
  4258. messbox.Close()
  4259. If thumblist <> "ok" Then
  4260. MsgBox("failed to retrieve any artwork")
  4261. Else
  4262. MsgBox("No " & If(postertype = "poster", "Poster", "Banner") & " found")
  4263. End If
  4264. Exit Sub
  4265. End If
  4266. If mainimages Then
  4267. For Each Image In artlist
  4268. If Image.Language = Pref.TvdbLanguageCode And Image.BannerType = postertype And Image.Season = Nothing Then
  4269. posterpath = Image.Url : Exit For
  4270. End If
  4271. Next
  4272. If posterpath = "" Then
  4273. For Each Image In artlist
  4274. If Image.Language = "en" And Image.BannerType = postertype And Image.Season = Nothing Then
  4275. posterpath = Image.Url : Exit For
  4276. End If
  4277. Next
  4278. End If
  4279. If posterpath = "" Then
  4280. For Each Image In artlist
  4281. If Image.BannerType = postertype And Image.Season = Nothing Then
  4282. posterpath = Image.Url : Exit For
  4283. End If
  4284. Next
  4285. End If
  4286. Else
  4287. Dim istype As String = ""
  4288. If postertype = "poster" Then
  4289. istype = "season"
  4290. Else
  4291. istype = "seasonwide"
  4292. End If
  4293. For Each Image In artlist
  4294. If Image.Season = seasonno And Image.Language = Pref.TvdbLanguageCode And Image.Resolution = istype Then posterpath = Image.Url : Exit For
  4295. Next
  4296. If posterpath = "" Then
  4297. For Each Image In artlist
  4298. If Image.Season = seasonno And Image.Language = "en" And Image.Resolution = istype Then posterpath = Image.Url : Exit For
  4299. Next
  4300. End If
  4301. If posterpath = "" Then
  4302. For Each Image In artlist
  4303. If Image.Season = seasonno And Image.Resolution = istype Then posterpath = Image.Url : Exit For
  4304. Next
  4305. End If
  4306. End If
  4307. If posterpath <> "" Then
  4308. Dim imagepath As New List(Of String)
  4309. If mainimages Then
  4310. If postertype = "poster" Then
  4311. If frodo Then imagepath.Add(WorkingTvShow.FolderPath & "poster.jpg")
  4312. If eden Then imagepath.Add(WorkingTvShow.FolderPath & "folder.jpg")
  4313. Else
  4314. If frodo Then imagepath.Add(WorkingTvShow.FolderPath & "banner.jpg")
  4315. If eden And Pref.postertype = "banner" Then imagepath.Add(WorkingTvShow.FolderPath & "folder.jpg")
  4316. End If
  4317. Else
  4318. If seasonno.ToInt < 10 Then seasonno = "0" & seasonno
  4319. If postertype = "poster" Then
  4320. If seasonno <> "00" Then
  4321. If Pref.seasonfolderjpg AndAlso seasonpath <> "" Then imagepath.Add(WorkingTvShow.FolderPath & seasonpath & "folder.jpg")
  4322. If eden Then imagepath.Add(WorkingTvShow.FolderPath & "season" & seasonno & ".tbn")
  4323. If frodo Then imagepath.Add(WorkingTvShow.FolderPath & "season" & seasonno & "-poster.jpg")
  4324. Else
  4325. If Pref.seasonfolderjpg AndAlso seasonpath <> "" Then imagepath.Add(WorkingTvShow.FolderPath & seasonpath & "folder.jpg")
  4326. If eden Then imagepath.Add(WorkingTvShow.FolderPath & "season-specials" & ".tbn")
  4327. If frodo Then imagepath.Add(WorkingTvShow.FolderPath & "season-specials" & "-poster.jpg")
  4328. End If
  4329. Else
  4330. If eden And Pref.postertype = "banner" Then imagepath.Add(WorkingTvShow.FolderPath & "season" & seasonno & ".tbn")
  4331. If frodo Then imagepath.Add(WorkingTvShow.FolderPath & "season" & seasonno & "-banner.jpg")
  4332. End If
  4333. End If
  4334. For Each impath In imagepath
  4335. Utilities.DownloadFile(posterpath, impath)
  4336. Next
  4337. 'Dim Showname As TvShow = tv_ShowSelectedCurrently()
  4338. Dim last As Integer = imagepath.Count - 1
  4339. If postertype = "poster" Then
  4340. util_ImageLoad(tv_PictureBoxRight, imagepath(last), Utilities.DefaultTvPosterPath)
  4341. Else
  4342. util_ImageLoad(tv_PictureBoxBottom, imagepath(last), Utilities.DefaultTvBannerPath)
  4343. End If
  4344. 'tv_ShowLoad(Showname)
  4345. Else
  4346. messbox.Close()
  4347. MsgBox("No " & If(postertype = "poster", "Poster", "Banner") & " found")
  4348. End If
  4349. messbox.Close()
  4350. Catch ex As Exception
  4351. messbox.Close()
  4352. End Try
  4353. End Sub
  4354. Private Sub TvSelectPosterBanner(ByVal poster As Boolean)
  4355. Dim IsOfType As String = "banner"
  4356. Dim tpindex As Integer = 2
  4357. If Not poster Then IsOfType = "poster"
  4358. If TypeOf TvTreeview.SelectedNode.Tag Is Media_Companion.TvEpisode Then tpindex = 3
  4359. RemoveHandler TabControl3.SelectedIndexChanged, AddressOf TabControl3_SelectedIndexChanged
  4360. TabControl3.SelectTab(tpindex)
  4361. AddHandler TabControl3.SelectedIndexChanged, AddressOf TabControl3_SelectedIndexChanged
  4362. tv_PosterSetup(IsOfType)
  4363. End Sub
  4364. Private Sub TvFanartTvArt (ByVal ThisShow As TvShow, ByVal force As Boolean)
  4365. Dim clearartLD As String = Nothing : Dim logoLD As String = Nothing : Dim clearart As String = Nothing : Dim logo As String = Nothing
  4366. Dim poster As String = Nothing : Dim fanart As String = Nothing : Dim banner As String = Nothing : Dim landscape As String = Nothing
  4367. Dim character As String = Nothing
  4368. Dim currentshowpath As String = ThisShow.FolderPath
  4369. Dim DestImg As String = ""
  4370. Dim aok As Boolean = True
  4371. Dim frodo As Boolean = Pref.FrodoEnabled
  4372. Dim eden As Boolean = Pref.EdenEnabled
  4373. 'Dim Overwrite As Boolean = If(Pref.overwritethumbs OrElse force OrElse Pref.TvChgShowOverwriteImgs, True, False)
  4374. Dim ID As String = ThisShow.TvdbId.Value
  4375. Dim TvFanartlist As New FanartTvTvList
  4376. Dim newobj As New FanartTv
  4377. newobj.ID = ID
  4378. newobj.src = "tv"
  4379. Try
  4380. TvFanartlist = newobj.FanarttvTvresults
  4381. Catch ex As Exception
  4382. 'ExceptionHandler.LogError(ex)
  4383. aok = False
  4384. End Try
  4385. If Not aok Then Exit Sub
  4386. Dim lang As New List(Of String)
  4387. lang.Add(ThisShow.Language.Value)
  4388. If Not lang.Contains(Pref.TvdbLanguageCode) Then lang.Add(Pref.TvdbLanguageCode)
  4389. If Not lang.Contains("en") Then lang.Add("en")
  4390. lang.Add("00")
  4391. For Each lan In lang
  4392. If IsNothing(clearart) Then
  4393. For Each Art In TvFanartlist.hdclearart
  4394. If Art.lang = lan Then clearart = Art.url : Exit For
  4395. Next
  4396. End If
  4397. If IsNothing(clearartLD) Then
  4398. For Each Art In TvFanartlist.clearart
  4399. If Art.lang = lan Then clearartLD = Art.url : Exit For
  4400. Next
  4401. End If
  4402. If IsNothing(logo) Then
  4403. For Each Art In TvFanartlist.hdtvlogo
  4404. If Art.lang = lan Then logo = Art.url : Exit For
  4405. Next
  4406. End If
  4407. If IsNothing(logoLD) Then
  4408. For Each Art In TvFanartlist.clearlogo
  4409. If Art.lang = lan Then logoLD = Art.url : Exit For
  4410. Next
  4411. End If
  4412. If IsNothing(poster) Then
  4413. For Each Art In TvFanartlist.tvposter
  4414. If Art.lang = lan Then poster = Art.url : Exit For
  4415. Next
  4416. End If
  4417. If IsNothing(fanart) Then
  4418. For Each Art In TvFanartlist.showbackground
  4419. If Art.lang = lan Then fanart = Art.url : Exit For
  4420. Next
  4421. End If
  4422. If IsNothing(banner) Then
  4423. For Each Art In TvFanartlist.tvbanner
  4424. If Art.lang = lan Then banner = Art.url : Exit For
  4425. Next
  4426. End If
  4427. If IsNothing(landscape) Then
  4428. For Each Art In TvFanartlist.tvthumb
  4429. If Art.lang = lan Then landscape = Art.url : Exit For
  4430. Next
  4431. End If
  4432. If IsNothing(character) Then
  4433. For Each Art In TvFanartlist.characterart
  4434. If Art.lang = lan Then character = Art.url : Exit For
  4435. Next
  4436. End If
  4437. Next
  4438. If IsNothing(clearart) AndAlso Not IsNothing(clearartld) Then clearart = clearartLD
  4439. If IsNothing(logo) AndAlso Not IsNothing(logold) Then logo = logold
  4440. DestImg = currentshowpath & "clearart.png"
  4441. If Not IsNothing(clearart) Then Utilities.DownloadFile(clearart, DestImg, force) 'AndAlso (force OrElse Not File.Exists(DestImg))
  4442. DestImg = currentshowpath & "logo.png"
  4443. If Not IsNothing(logo) Then Utilities.DownloadFile(logo, DestImg, force) 'AndAlso (force OrElse Not File.Exists(DestImg))
  4444. DestImg = currentshowpath & "character.png"
  4445. If Not IsNothing(character) Then Utilities.DownloadFile(character, DestImg, force) 'AndAlso (force OrElse Not File.Exists(DestImg))
  4446. If Not IsNothing(poster) Then
  4447. Dim destpaths As New List(Of String)
  4448. If frodo Then
  4449. destpaths.Add(currentshowpath & "poster.jpg")
  4450. destpaths.Add(currentshowpath & "season-all-poster.jpg")
  4451. 'If Pref.tvfolderjpg Then destpaths.Add(currentshowpath & "folder.jpg")
  4452. End If
  4453. If eden then
  4454. destpaths.Add(currentshowpath & "poster.jpg")
  4455. destpaths.Add(currentshowpath & "season-all.tbn")
  4456. End If
  4457. Dim success As Boolean = DownloadCache.SaveImageToCacheAndPaths(poster, destpaths, False, , , force)
  4458. End If
  4459. If Not IsNothing(fanart) Then
  4460. Dim Destpaths As New List(Of String)
  4461. If frodo Then
  4462. Destpaths.Add(currentshowpath & "fanart.jpg")
  4463. Destpaths.Add(currentshowpath & "season-all-fanart.jpg")
  4464. End If
  4465. If eden Then Destpaths.Add(currentshowpath & "fanart.jpg")
  4466. Dim success As Boolean = DownloadCache.SaveImageToCacheAndPaths(fanart, Destpaths, False, , , force)
  4467. End If
  4468. DestImg = currentshowpath & "landscape.jpg"
  4469. If Not IsNothing(landscape) Then Utilities.DownloadFile(landscape, DestImg, force) 'AndAlso (force OrElse Not File.Exists(DestImg))
  4470. DestImg = currentshowpath & "banner.jpg"
  4471. If Not IsNothing(banner) Then 'AndAlso (force OrElse Not File.Exists(DestImg))
  4472. Utilities.DownloadFile(banner, DestImg, force)
  4473. If frodo Then
  4474. DestImg = currentshowpath & "season-all-banner.jpg"
  4475. Utilities.DownloadFile(banner, DestImg, force) 'If force OrElse Not File.Exists(DestImg) Then
  4476. End If
  4477. End If
  4478. Dim firstseason As Integer = 1
  4479. Dim lastseason As Integer = -1
  4480. For Each item In TvFanartlist.seasonposter
  4481. Dim itemseason As Integer = item.season.ToInt
  4482. If itemseason > lastseason Then lastseason = itemseason
  4483. If itemseason < firstseason Then firstseason = itemseason
  4484. Next
  4485. If lastseason >= firstseason Then
  4486. For i = firstseason to lastseason
  4487. Dim savepaths As New List(Of String)
  4488. Dim seasonurl As String = Nothing
  4489. For Each lan In lang
  4490. For Each item In TvFanartlist.seasonposter
  4491. If item.lang = lan AndAlso item.season = i.ToString Then
  4492. seasonurl = item.url
  4493. Exit For
  4494. End If
  4495. Next
  4496. If Not IsNothing(seasonurl) Then Exit for
  4497. Next
  4498. If Not IsNothing(seasonurl) Then
  4499. Dim seasonno As String = i.ToString
  4500. If seasonno <> "" Then
  4501. If seasonno.Length = 1 Then seasonno = "0" & seasonno
  4502. If seasonno = "00" Then
  4503. seasonno = "-specials"
  4504. End If
  4505. destimg = currentshowpath & "season" & seasonno & "-poster.jpg"
  4506. If Pref.FrodoEnabled Then savepaths.Add(destimg)
  4507. If Pref.EdenEnabled Then
  4508. destimg = destimg.Replace("-poster.jpg", ".tbn")
  4509. savepaths.Add(destimg)
  4510. End If
  4511. 'If Pref.seasonfolderjpg AndAlso ThisShow.Episodes.Count > 0 Then
  4512. ' For Each ep In ThisShow.Episodes
  4513. ' Dim TrueSeasonFolder As String = Nothing
  4514. ' Dim folder As Boolean = False
  4515. ' If ep.Season.Value = i Then
  4516. ' If ep.FolderPath <> currentshowpath Then
  4517. ' TrueSeasonFolder = ep.FolderPath & "folder.jpg"
  4518. ' If Not savepaths.Contains(TrueSeasonFolder) Then
  4519. ' savepaths.Add(TrueSeasonFolder)
  4520. ' folder = True
  4521. ' End If
  4522. ' End If
  4523. ' End If
  4524. ' If folder Then Exit For
  4525. ' Next
  4526. 'End If
  4527. End If
  4528. End If
  4529. If savepaths.Count > 0 Then DownloadCache.SaveImageToCacheAndPaths(seasonurl, savepaths, False, , , force)
  4530. Next
  4531. End If
  4532. firstseason = 1
  4533. lastseason = -1
  4534. For Each item In TvFanartlist.seasonbanner
  4535. Dim itemseason As Integer = item.season.ToInt
  4536. If itemseason > lastseason Then lastseason = itemseason
  4537. If itemseason < firstseason Then firstseason = itemseason
  4538. Next
  4539. If lastseason >= firstseason AndAlso frodo Then
  4540. For i = firstseason to lastseason
  4541. Dim savepaths As New List(Of String)
  4542. Dim seasonurl As String = Nothing
  4543. For Each lan In lang
  4544. For Each item In TvFanartlist.seasonbanner
  4545. If item.lang = lan AndAlso item.season = i.ToString Then
  4546. seasonurl = item.url
  4547. Exit For
  4548. End If
  4549. Next
  4550. If Not IsNothing(seasonurl) Then Exit for
  4551. Next
  4552. If Not IsNothing(seasonurl) Then
  4553. Dim seasonno As String = i.ToString
  4554. If seasonno <> "" Then
  4555. If seasonno.Length = 1 Then seasonno = "0" & seasonno
  4556. If seasonno = "00" Then
  4557. seasonno = "-specials"
  4558. End If
  4559. destimg = currentshowpath & "season" & seasonno & "-banner.jpg"
  4560. If Pref.FrodoEnabled Then savepaths.Add(destimg)
  4561. End If
  4562. End If
  4563. If savepaths.Count > 0 Then DownloadCache.SaveImageToCacheAndPaths(seasonurl, savepaths, False, , , force)
  4564. Next
  4565. End If
  4566. firstseason = 1
  4567. lastseason = -1
  4568. For Each item In TvFanartlist.seasonthumb
  4569. Dim itemseason As Integer = item.season.ToInt
  4570. If itemseason > lastseason Then lastseason = itemseason
  4571. If itemseason < firstseason Then firstseason = itemseason
  4572. Next
  4573. If lastseason >= firstseason AndAlso frodo Then
  4574. For i = firstseason to lastseason
  4575. Dim savepaths As New List(Of String)
  4576. Dim seasonurl As String = Nothing
  4577. For Each lan In lang
  4578. For Each item In TvFanartlist.seasonthumb
  4579. If item.lang = lan AndAlso item.season = i.ToString Then
  4580. seasonurl = item.url
  4581. Exit For
  4582. End If
  4583. Next
  4584. If Not IsNothing(seasonurl) Then Exit for
  4585. Next
  4586. If Not IsNothing(seasonurl) Then
  4587. Dim seasonno As String = i.ToString
  4588. If seasonno <> "" Then
  4589. If seasonno.Length = 1 Then seasonno = "0" & seasonno
  4590. If seasonno = "00" Then
  4591. seasonno = "-specials"
  4592. End If
  4593. destimg = currentshowpath & "season" & seasonno & "-landscape.jpg"
  4594. If Pref.FrodoEnabled Then savepaths.Add(destimg)
  4595. End If
  4596. End If
  4597. If savepaths.Count > 0 Then DownloadCache.SaveImageToCacheAndPaths(seasonurl, savepaths, False, , , force)
  4598. Next
  4599. End If
  4600. End Sub
  4601. #End Region
  4602. 'Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
  4603. ' Try
  4604. ' For Each Task In TaskCache.Tasks
  4605. ' If Task.State = TaskState.BackgroundWorkComplete Then
  4606. ' Task.FinishWork()
  4607. ' End If
  4608. ' Windows.Forms.Application.DoEvents()
  4609. ' Next
  4610. ' Catch
  4611. ' End Try
  4612. 'End Sub
  4613. 'Private Sub TaskListUpdater_Tick(sender As System.Object, e As System.EventArgs) Handles TaskListUpdater.Tick
  4614. ' 'cmdTasks_Refresh_Click(Nothing, Nothing)
  4615. ' TaskListUpdater.Enabled = False
  4616. ' lstTasks.ResetText()
  4617. 'End Sub
  4618. 'Protected Overrides Sub Finalize()
  4619. ' MyBase.Finalize()
  4620. 'End Sub
  4621. Private Sub Label136_AutoSizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label136.AutoSizeChanged
  4622. End Sub
  4623. Public Function tv_Showremovedfromlist(ByRef lstbox As Listbox, ByVal tvcache As Boolean, Optional ByVal nofolder As List(Of String) = Nothing, Optional ByVal lstboxscan As Boolean = False) As Boolean
  4624. Dim remfolder As New List(Of String)
  4625. Dim notvshownfo As New List(Of String)
  4626. Dim status As Boolean = False
  4627. If IsNothing(nofolder) Then
  4628. For Each item In Pref.tvFolders
  4629. If Not IO.Directory.Exists(item) Then
  4630. remfolder.Add(item)
  4631. Else
  4632. Dim tvnfopath As String = item & "\tvshow.nfo"
  4633. If Not File.Exists(tvnfopath) Then notvshownfo.Add(item)
  4634. End If
  4635. Next
  4636. End If
  4637. If notvshownfo.Count > 0 Then
  4638. Dim notvshmsg As String = "Folders found that did not contain a tvshow.nfo file" & vbCrLf & "Do you wish to also remove these folders?" & vbCrLf
  4639. For Each fo In notvshownfo
  4640. notvshmsg &= fo & vbcrlf
  4641. Next
  4642. Dim x = MsgBox(notvshmsg, MsgBoxStyle.YesNo)
  4643. If x = MsgBoxResult.Yes Then
  4644. remfolder.AddRange(notvshownfo)
  4645. Else
  4646. notvshownfo.Clear()
  4647. End If
  4648. End If
  4649. If IsNothing(nofolder) AndAlso (IsNothing(remfolder) Or remfolder.Count <= 0) AndAlso notvshownfo.Count = 0 Then
  4650. MsgBox("No Folders Missing or removed")
  4651. Return False
  4652. End If
  4653. If IsNothing(nofolder) And Not IsNothing(remfolder) Then nofolder = remfolder
  4654. If nofolder.Count > 0 Then
  4655. For Each folder In nofolder
  4656. If tvcache Then
  4657. If lstboxscan Then
  4658. For Each Item As Media_Companion.TvShow In Cache.TvCache.Shows
  4659. If Item.FolderPath.Trim("\") = folder Then
  4660. TvTreeview.Nodes.Remove(Item.ShowNode)
  4661. Cache.TvCache.Remove(Item)
  4662. Exit For
  4663. End If
  4664. Next
  4665. lstbox.Items.Remove(folder)
  4666. status = True
  4667. Else
  4668. tvFolders.Remove(folder)
  4669. End If
  4670. Else
  4671. lstbox.Items.Remove(folder)
  4672. custtvFolders.Remove(folder)
  4673. End If
  4674. Next
  4675. End If
  4676. Return status
  4677. End Function
  4678. #Region "Tv Watched/Unwatched Routines"
  4679. Private Sub Tv_MarkAs_Watched_UnWatched(ByVal toggle As String)
  4680. If TvTreeview.SelectedNode Is Nothing Then Exit Sub
  4681. Dim WorkingTvShow As TvShow = tv_ShowSelectedCurrently(TvTreeview)
  4682. Dim WorkingTvSeason As TvSeason = tv_SeasonSelectedCurrently(TvTreeview)
  4683. Dim WorkingEpisode As TvEpisode = ep_SelectedCurrently(TvTreeview)
  4684. If WorkingTvShow Is Nothing Then Exit Sub
  4685. If Not IsNothing(WorkingEpisode) Then
  4686. Dim episodelist As New List(Of TvEpisode)
  4687. episodelist = WorkingWithNfoFiles.ep_NfoLoad(WorkingEpisode.NfoFilePath)
  4688. For Each epis In episodelist
  4689. If toggle = "3" Then
  4690. Dim tmpstr As Integer = If(String.IsNullOrEmpty(epis.PlayCount.Value), 0, epis.PlayCount.Value.ToInt)
  4691. If tmpstr > 0 Then
  4692. epis.PlayCount.Value = "0"
  4693. Else
  4694. epis.PlayCount.Value = "1"
  4695. End If
  4696. With Me.btn_EpWatched
  4697. .Text = If(tmpstr = 0, "Watched", "Unwatched")
  4698. .BackColor = If(tmpstr = 0, Color.LawnGreen, Color.Red)
  4699. End With
  4700. Else
  4701. epis.PlayCount.Value = toggle
  4702. End If
  4703. Next
  4704. WorkingWithNfoFiles.ep_NfoSave(episodelist, WorkingEpisode.NfoFilePath)
  4705. WorkingEpisode.Load
  4706. WorkingEpisode.UpdateTreenode()
  4707. ElseIf Not IsNothing(WorkingTvSeason) Then
  4708. For Each ep In WorkingTvSeason.Episodes
  4709. If ep.IsMissing Then Continue For
  4710. Dim episodelist As New List(Of TvEpisode)
  4711. episodelist = WorkingWithNfoFiles.ep_NfoLoad(ep.NfoFilePath)
  4712. For Each epis In episodelist
  4713. epis.PlayCount.Value = toggle
  4714. Next
  4715. WorkingWithNfoFiles.ep_NfoSave(episodelist, ep.NfoFilePath)
  4716. ep.Load
  4717. ep.UpdateTreenode()
  4718. Next
  4719. WorkingTvSeason.UpdateTreenode()
  4720. ElseIf Not IsNothing(WorkingTvShow) Then
  4721. For Each ep In WorkingTvShow.Episodes
  4722. If ep.IsMissing Then Continue For
  4723. Dim episodelist As New List(Of TvEpisode)
  4724. episodelist = WorkingWithNfoFiles.ep_NfoLoad(ep.NfoFilePath)
  4725. For Each epis In episodelist
  4726. epis.PlayCount.Value = toggle
  4727. Next
  4728. WorkingWithNfoFiles.ep_NfoSave(episodelist, ep.NfoFilePath)
  4729. ep.Load
  4730. ep.UpdateTreenode()
  4731. Next
  4732. For Each seas In WorkingTvShow.Seasons.keys
  4733. WorkingTvShow.Seasons(seas).UpdateTreenode()
  4734. Next
  4735. End If
  4736. WorkingTvShow.UpdateTreenode()
  4737. End Sub
  4738. Public Shared Sub util_EpisodeSetWatched(ByRef playcount As String, Optional ByVal toggle As Boolean = False)
  4739. Dim watched As Boolean = False
  4740. If IsNumeric(playcount) Then
  4741. watched = Convert.ToInt32(playcount) > 0
  4742. If toggle Then
  4743. watched = Not watched
  4744. playcount = If(watched, "1", "0")
  4745. End If
  4746. End If
  4747. With Form1.btn_EpWatched
  4748. .Text = If(watched, "Watched", "Unwatched")
  4749. .BackColor = If(watched, Color.LawnGreen, Color.Red)
  4750. End With
  4751. End Sub
  4752. #End Region
  4753. Private Function GetEpImdbId(ByVal ImdbId As String, ByVal SeasonNo As String, ByVal EpisodeNo As String) As String
  4754. Dim url = "http://www.imdb.com/title/" & ImdbId & "/episodes?season=" & SeasonNo
  4755. Dim webpage As New List(Of String)
  4756. Dim s As New Classimdb
  4757. webpage.Clear()
  4758. webpage = s.loadwebpage(Pref.proxysettings, url,False,10)
  4759. Dim webPg As String = String.Join( "" , webpage.ToArray() )
  4760. Dim matchstring As String = "<strong><a href=""/title/tt"
  4761. For f = 0 to webpage.Count -1
  4762. Dim m As Match = Regex.Match(webpage(f), matchstring)
  4763. If m.Success AndAlso webpage(f).Contains("ttep_ep"&EpisodeNo) Then
  4764. Dim tmp As String = webpage(f)
  4765. Dim n As Match = Regex.Match(tmp, "(tt\d{7})")
  4766. If n.Success = True Then
  4767. url = n.Value
  4768. Exit For
  4769. End If
  4770. End If
  4771. Next
  4772. Return url
  4773. End Function
  4774. Private Function GetEpMediaFlags() As List(Of KeyValuePair(Of String, String))
  4775. Dim thisep As TvEpisode = ep_SelectedCurrently(TvTreeview)
  4776. Dim flags As New List(Of KeyValuePair(Of String, String))
  4777. Try
  4778. If thisep.Details.StreamDetails.Audio.Count > 0 Then
  4779. 'Dim defaultAudioTrack = (From x In thisep.Details.StreamDetails.Audio Where x.DefaultTrack.Value="Yes").FirstOrDefault
  4780. 'If IsNothing(defaultAudioTrack) Then
  4781. ' defaultAudioTrack = thisep.Details.StreamDetails.Audio(0)
  4782. 'End If
  4783. Dim tracks = If(Pref.ShowAllAudioTracks,thisep.Details.StreamDetails.Audio,From x In thisep.Details.StreamDetails.Audio Where x=thisep.Details.StreamDetails.defaultAudioTrack)
  4784. For Each track In tracks
  4785. flags.Add(New KeyValuePair(Of String, string)("channels" + GetNotDefaultStr(track=thisep.Details.StreamDetails.defaultAudioTrack), GetNumAudioTracks(track.Channels.Value) ))
  4786. flags.Add(New KeyValuePair(Of String, string)("audio" + GetNotDefaultStr(track=thisep.Details.StreamDetails.defaultAudioTrack), track.Codec.Value ))
  4787. flags.Add(New KeyValuePair(Of String, string)("lang" + GetNotDefaultStr(track=thisep.Details.StreamDetails.defaultAudioTrack), track.Language.Value ))
  4788. Next
  4789. Else
  4790. flags.Add(New KeyValuePair(Of String, string)("channels", ""))
  4791. flags.Add(New KeyValuePair(Of String, string)("audio", ""))
  4792. flags.Add(New KeyValuePair(Of String, string)("lang" , ""))
  4793. End If
  4794. flags.Add(New KeyValuePair(Of String, string)("aspect", Utilities.GetStdAspectRatio(thisep.Details.StreamDetails.Video.Aspect.Value)))
  4795. flags.Add(New KeyValuePair(Of String, string)("codec", Utilities.GetCodecCommonName(GetMasterCodec(thisep.Details.StreamDetails.Video))))
  4796. flags.Add(New KeyValuePair(Of String, string)("resolution", If(thisep.Details.StreamDetails.Video.VideoResolution < 0, "", thisep.Details.StreamDetails.Video.VideoResolution.ToString)))
  4797. Dim subtitles = If(Not Pref.DisplayDefaultSubtitleLang, Nothing, If(Pref.DisplayAllSubtitleLang, thisep.Details.StreamDetails.Subtitles, From x In thisep.Details.StreamDetails.Subtitles Where x = thisep.Details.StreamDetails.DefaultSubTrack))
  4798. If Not IsNothing(subtitles) Then
  4799. For each subtitle In subtitles
  4800. flags.Add( New KeyValuePair(Of String, String)("sublang", subtitle.Language.Value))
  4801. Next
  4802. End If
  4803. Catch
  4804. End Try
  4805. Return flags
  4806. End Function
  4807. Private Function GetMultiEpMediaFlags(ByVal thisep As TvEpisode) As List(Of KeyValuePair(Of String, String))
  4808. Dim flags As New List(Of KeyValuePair(Of String, String))
  4809. Try
  4810. If thisep.Details.StreamDetails.Audio.Count > 0 Then
  4811. Dim tracks = If(Pref.ShowAllAudioTracks,thisep.Details.StreamDetails.Audio,From x In thisep.Details.StreamDetails.Audio Where x=thisep.Details.StreamDetails.defaultAudioTrack)
  4812. For Each track In tracks
  4813. flags.Add(New KeyValuePair(Of String, string)("channels" + GetNotDefaultStr(track=thisep.Details.StreamDetails.defaultAudioTrack), GetNumAudioTracks(track.Channels.Value) ))
  4814. flags.Add(New KeyValuePair(Of String, string)("audio" + GetNotDefaultStr(track=thisep.Details.StreamDetails.defaultAudioTrack), track.Codec.Value ))
  4815. flags.Add(New KeyValuePair(Of String, string)("lang" + GetNotDefaultStr(track=thisep.Details.StreamDetails.defaultAudioTrack), track.Language.Value ))
  4816. Next
  4817. Else
  4818. flags.Add(New KeyValuePair(Of String, string)("channels", ""))
  4819. flags.Add(New KeyValuePair(Of String, string)("audio", ""))
  4820. flags.Add(New KeyValuePair(Of String, string)("lang" , ""))
  4821. End If
  4822. flags.Add(New KeyValuePair(Of String, string)("aspect", Utilities.GetStdAspectRatio(thisep.Details.StreamDetails.Video.Aspect.Value)))
  4823. flags.Add(New KeyValuePair(Of String, string)("codec", Utilities.GetCodecCommonName(GetMasterCodec(thisep.Details.StreamDetails.Video)))) 'thisep.Details.StreamDetails.Video.Codec.Value.RemoveWhitespace))
  4824. flags.Add(New KeyValuePair(Of String, string)("resolution", If(thisep.Details.StreamDetails.Video.VideoResolution < 0, "", thisep.Details.StreamDetails.Video.VideoResolution.ToString)))
  4825. Dim subtitles = If(Not Pref.DisplayDefaultSubtitleLang, Nothing, If(Pref.DisplayAllSubtitleLang, thisep.Details.StreamDetails.Subtitles, From x In thisep.Details.StreamDetails.Subtitles Where x = thisep.Details.StreamDetails.DefaultSubTrack))
  4826. If Not IsNothing(subtitles) Then
  4827. For each subtitle In subtitles
  4828. flags.Add( New KeyValuePair(Of String, String)("sublang", subtitle.Language.Value))
  4829. Next
  4830. End If
  4831. Catch
  4832. End Try
  4833. Return flags
  4834. End Function
  4835. Private Function GetAspect(ep As TvEpisode)
  4836. Dim thisarray(2) As Integer
  4837. thisarray(0) = 400
  4838. thisarray(1) = 225
  4839. Try
  4840. If ep.Details.StreamDetails.Video.Width.Value is Nothing Then
  4841. ep.GetFileDetails
  4842. End If
  4843. Dim epw As Integer = ep.Details.StreamDetails.Video.Width.Value.ToInt
  4844. Dim eph As Integer= ep.Details.StreamDetails.Video.Height.Value.ToInt
  4845. Dim ThisAsp As Double = epw/eph
  4846. If ThisAsp < 1.37 Then 'aspect greater than Industry Standard of 1.37:1 is classed as WideScreen
  4847. thisarray(1) = 300
  4848. End If
  4849. Catch
  4850. thisarray(0) = 0
  4851. End Try
  4852. Return thisarray
  4853. End Function
  4854. End Class