Skip to content

Commit

Permalink
fixed: crash while scraping no longer available YouTube trailers
Browse files Browse the repository at this point in the history
now each trailer from YouTube will be checked before adding to results
  • Loading branch information
DanCooper committed Feb 15, 2016
1 parent feaa675 commit 28e8910
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Addons/scraper.TMDB.Data/Scraper/clsScrapeTMDB.vb
Expand Up @@ -487,7 +487,12 @@ Namespace TMDB
End If

If aTrailers IsNot Nothing AndAlso aTrailers.Count > 0 Then
nMovie.Trailer = "http://www.youtube.com/watch?hd=1&v=" & aTrailers(0).Key
For Each tTrailer In aTrailers
If YouTube.Scraper.IsAvailable("http://www.youtube.com/watch?hd=1&v=" & tTrailer.Key) Then
nMovie.Trailer = "http://www.youtube.com/watch?hd=1&v=" & tTrailer.Key
Exit For
End If
Next
End If
End If

Expand Down
22 changes: 12 additions & 10 deletions Addons/scraper.TMDB.Trailer/Scraper/clsScrapeTMDB.vb
Expand Up @@ -99,16 +99,18 @@ Namespace TMDB
If trailers IsNot Nothing AndAlso trailers.Results IsNot Nothing Then
For Each Video As TMDbLib.Objects.General.Video In trailers.Results.Where(Function(f) f.Site = "YouTube")
Dim tLink As String = String.Format("http://www.youtube.com/watch?v={0}", Video.Key)
Dim tName As String = YouTube.Scraper.GetVideoTitle(tLink)
alTrailers.Add(New MediaContainers.Trailer With { _
.LongLang = If(String.IsNullOrEmpty(Video.Iso_639_1), String.Empty, Localization.ISOGetLangByCode2(Video.Iso_639_1)), _
.Quality = GetVideoQuality(Video.Size), _
.Scraper = "TMDB", _
.ShortLang = If(String.IsNullOrEmpty(Video.Iso_639_1), String.Empty, Video.Iso_639_1), _
.Source = Video.Site, _
.Title = tName, _
.Type = GetVideoType(Video.Type), _
.URLWebsite = tLink})
If YouTube.Scraper.IsAvailable(tLink) Then
Dim tName As String = YouTube.Scraper.GetVideoTitle(tLink)
alTrailers.Add(New MediaContainers.Trailer With {
.LongLang = If(String.IsNullOrEmpty(Video.Iso_639_1), String.Empty, Localization.ISOGetLangByCode2(Video.Iso_639_1)),
.Quality = GetVideoQuality(Video.Size),
.Scraper = "TMDB",
.ShortLang = If(String.IsNullOrEmpty(Video.Iso_639_1), String.Empty, Video.Iso_639_1),
.Source = Video.Site,
.Title = tName,
.Type = GetVideoType(Video.Type),
.URLWebsite = tLink})
End If
Next
End If

Expand Down
20 changes: 17 additions & 3 deletions EmberAPI/clsAPIYouTube.vb
Expand Up @@ -88,13 +88,27 @@ Namespace YouTube
''' </summary>
''' <param name="strURL">The text to parse for the title</param>
Public Shared Function GetVideoTitle(ByRef strURL As String) As String
Dim result As String = String.Empty
If UrlUtils.IsYouTubeURL(strURL) Then
Dim raw_video_info As String = GetVideoDetails(UrlUtils.GetVideoID(strURL))
Dim rawAllData As Dictionary(Of String, String) = ToStringTable(raw_video_info).ToDictionary(Function(entry) entry(0), Function(entry) entry(1))
result = HttpUtility.UrlDecode(rawAllData("title"))
Try
Return HttpUtility.UrlDecode(rawAllData("title"))
Catch ex As Exception
Return HttpUtility.UrlDecode(rawAllData("reason"))
End Try
End If
Return result
Return String.Empty
End Function

Public Shared Function IsAvailable(ByVal strURL As String) As Boolean
If UrlUtils.IsYouTubeURL(strURL) Then
Dim raw_video_info As String = GetVideoDetails(UrlUtils.GetVideoID(strURL))
Dim rawAllData As Dictionary(Of String, String) = ToStringTable(raw_video_info).ToDictionary(Function(entry) entry(0), Function(entry) entry(1))
If Not rawAllData.ContainsKey("errorcode") Then
Return True
End If
End If
Return False
End Function

Private Shared Function ToStringTable(s As String) As IEnumerable(Of String())
Expand Down

0 comments on commit 28e8910

Please sign in to comment.