/
IMDB.rbbas
executable file
·252 lines (221 loc) · 9.04 KB
/
IMDB.rbbas
1
#tag ClassProtected Class IMDBInherits HTTPSocket #tag Event Sub Error(code as integer) SocketError( code, Me ) Exception err as NilObjectException Me.Close End Sub #tag EndEvent #tag Method, Flags = &h0 Sub IMDbFullInfo(XmlContent as String) XmlContent = XmlContent.ReplaceAll("'", "'") XmlContent = XmlContent.ReplaceAll("#039;", "'") XmlContent = XmlContent.ReplaceAll(" & ", " and ") Dim Xml as new XmlDocument Dim xroot as XmlNode Xml.PreserveWhitespace = False Xml.LoadXml( XmlContent ) xroot = Xml.Child(0).FirstChild If xroot.GetAttribute("imdbID") <> "" And xroot.GetAttribute("imdbID") <> "N/A" Then MovieAttr.ID_IMDB = xroot.GetAttribute("imdbID") If xroot.GetAttribute("title") <> "" And xroot.GetAttribute("title") <> "N/A" And MovieAttr.Title = "" Then MovieAttr.Title = xroot.GetAttribute("title") MovieAttr.TitleSort = Articulator( MovieAttr.Title ) End If If xroot.GetAttribute("year") <> "" And xroot.GetAttribute("Year") <> "N/A" Then MovieAttr.DateYear = Val( xroot.GetAttribute("year") ) If xroot.GetAttribute("rated") <> "" And xroot.getAttribute("rated") <> "N/A" Then Dim r as String = xroot.GetAttribute("rated") If r = "R" or r = "PG" or r = "PG-13" or r = "G" or r = "NC-17" Then MovieAttr.RatingMPAA = "Rated " + xroot.GetAttribute("rated") Else MovieAttr.RatingMPAA = xroot.GetAttribute("rated") End If End If If xroot.GetAttribute("released") <> "" And xroot.GetAttribute("released") <> "N/A" Then Dim Date, PrettyMonth, Day, Year as String Date = xroot.GetAttribute("released") PrettyMonth = Date.Right(8).Left(3) Day = Date.Left(2) Year = Date.Right(4) MovieAttr.DatePremiered = Year + "-" + Month2Int( PrettyMonth ) + "-" + Day End If If xroot.GetAttribute("released") <> "" And xroot.GetAttribute("released") <> "N/A" And MovieAttr.DatePremiered = "" Then MovieAttr.DatePremiered = xroot.GetAttribute("released") If xroot.GetAttribute("genre") <> "" And xroot.GetAttribute("genre") <> "N/A" Then Dim Genres() as String = xroot.GetAttribute("genre").Split(", ") 'If Genres.Ubound > MovieAttr.Genres.Ubound Then MovieAttr.Genres = Genres For i as Integer = 0 to Genres.Ubound MovieAttr.Genres.Append Genres(i) Next End If If xroot.GetAttribute("director") <> "" And xroot.GetAttribute("director") <> "N/A" Then MovieAttr.CreditDirector = xroot.GetAttribute("director") If xroot.GetAttribute("writer") <> "" And xroot.GetAttribute("writer") <> "N/A" Then MovieAttr.CreditWriter = xroot.GetAttribute("writer") If xroot.GetAttribute("imdbRating") <> "" And xroot.GetAttribute("imdbRating") <> "N/A" Then MovieAttr.Rating = Val( xroot.GetAttribute("imdbRating") ) If xroot.GetAttribute("imdbVotes") <> "" And xroot.GetAttribute("imdbVotes") <> "N/A" Then MovieAttr.RatingVotes = Val ( xroot.GetAttribute("imdbVotes") ) // IMDB's Formula for Weighted Rating (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × C Dim WeightedRating as Double = ( MovieAttr.RatingVotes / ( MovieAttr.RatingVotes + 3000 ) ) * MovieAttr.Rating + ( 3000 / ( MovieAttr.RatingVotes + 3000 ) ) * 6.9 If MovieAttr.RatingVotes = 3000 and WeightedRating >= 8 then MovieAttr.RatingTop250 = WeightedRating // Plot Dim Plot as String = xroot.GetAttribute("plot") If Plot.Len > MovieAttr.DescriptionPlot.Len and _ Plot <> "" and _ Plot <> "N/A" and _ ( Prefs.textStringForKey("DBLanguage") = "en" OR Prefs.textStringForKey("DBLanguage") = "en-gb" ) then MovieAttr.DescriptionPlot = Trim( RemoveLinks( Plot ) ) End If // Tomato Consensus If xroot.GetAttribute("tomatoConsensus") <> "" And xroot.GetAttribute("tomatoConsensus") <> "N/A" Then MovieAttr.TomatoConcensus = xroot.GetAttribute("tomatoConsensus") If xroot.GetAttribute("poster") <> "" And xroot.GetAttribute("poster") <> "N/A" Then 'Dim s as string = xroot.GetAttribute("poster") 'Dim Poster as FolderItem = FindImagePoster( MovieAttr.FolderParent ) Dim Destination as FolderItem = MovieAttr.DestinationPoster( MovieAttr.FolderParent ) If (Destination <> Nil And NOT Destination.Exists) Then MovieAttr.ART_Poster = URL2Picture( xroot.GetAttribute("poster"), Destination.NameWithoutExtension, Destination.NameExtension, MovieAttr.FolderParent ) CacheImageSet( MovieAttr.ART_Poster, MovieAttr.ID_IMDB + ".movie.poster.jpg" ) End If End If Return End Sub #tag EndMethod #tag Method, Flags = &h0 Sub IMDbShortInfo(XmlContent as String) XmlContent = XmlContent.ReplaceAll("'", "'") XmlContent = XmlContent.ReplaceAll("#039;", "'") XmlContent = XmlContent.ReplaceAll(" & ", " and ") Dim Xml as new XmlDocument Dim xroot as XmlNode Dim Outline as String Xml.PreserveWhitespace = False Xml.LoadXml( XmlContent ) xroot = Xml.Child(0).FirstChild Outline = Trim( xroot.GetAttribute("plot") ) If Outline.Len > MovieAttr.DescriptionOutline.Len and _ Outline <> "" and _ Outline <> "N/A" and _ ( Prefs.textStringForKey("DBLanguage") = "en" OR Prefs.textStringForKey("DBLanguage") = "en-gb" ) then MovieAttr.DescriptionOutline = RemoveLinks( Outline ) End If Return End Sub #tag EndMethod #tag Method, Flags = &h0 Sub UpdateRating(XmlContent as String) XmlContent = XmlContent.ReplaceAll("'", "'") XmlContent = XmlContent.ReplaceAll("#039;", "'") XmlContent = XmlContent.ReplaceAll(" & ", " and ") Dim Xml as new XmlDocument Dim xroot as XmlNode Xml.PreserveWhitespace = False Xml.LoadXml( XmlContent ) xroot = Xml.Child(0).FirstChild // MPAA Rating If xroot.GetAttribute("rated") <> "" And xroot.getAttribute("rated") <> "N/A" Then Dim r as String = xroot.GetAttribute("rated") If r = "R" or r = "PG" or r = "PG-13" or r = "G" or r = "NC-17" Then MovieAttr.RatingMPAA = "Rated " + xroot.GetAttribute("rated") Else MovieAttr.RatingMPAA = xroot.GetAttribute("rated") End If End If // Rating & Votes If xroot.GetAttribute("imdbRating") <> "" And xroot.GetAttribute("imdbRating") <> "N/A" Then MovieAttr.Rating = Val( xroot.GetAttribute("imdbRating") ) If xroot.GetAttribute("imdbVotes") <> "" And xroot.GetAttribute("imdbVotes") <> "N/A" Then MovieAttr.RatingVotes = Val ( xroot.GetAttribute("imdbVotes") ) // IMDB's Formula for Weighted Rating (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × C Dim WeightedRating as Double = ( MovieAttr.RatingVotes / ( MovieAttr.RatingVotes + 3000 ) ) * MovieAttr.Rating + ( 3000 / ( MovieAttr.RatingVotes + 3000 ) ) * 6.9 If MovieAttr.RatingVotes = 3000 and WeightedRating >= 8 then MovieAttr.RatingTop250 = WeightedRating // Tomato Consensus If xroot.GetAttribute("tomatoConsensus") <> "" And xroot.GetAttribute("tomatoConsensus") <> "N/A" Then MovieAttr.TomatoConcensus = xroot.GetAttribute("tomatoConsensus") Return End Sub #tag EndMethod #tag Method, Flags = &h0 Function URL_IMDbApi(IMDbID as String = "", Full as Boolean = True) As String If Full then Return "http://www.omdbapi.com/?i=" + IMDBID + "&r=XML&plot=full&tomatoes=true" Else Return "http://www.omdbapi.com/?i=" + IMDBID + "&r=XML&plot=short&tomatoes=true" End If End Function #tag EndMethod #tag Note, Name = IMDB Api 3th Party Api: http://www.imdbapi.com/ #tag EndNote #tag ViewBehavior #tag ViewProperty Name="Address" Visible=true Group="Behavior" Type="String" InheritedFrom="TCPSocket" #tag EndViewProperty #tag ViewProperty Name="defaultPort" Group="Behavior" InitialValue="0" Type="integer" InheritedFrom="HTTPSocket" #tag EndViewProperty #tag ViewProperty Name="httpProxyAddress" Group="Behavior" Type="string" EditorType="MultiLineEditor" InheritedFrom="HTTPSocket" #tag EndViewProperty #tag ViewProperty Name="httpProxyPort" Group="Behavior" InitialValue="0" Type="integer" InheritedFrom="HTTPSocket" #tag EndViewProperty #tag ViewProperty Name="Index" Visible=true Group="ID" Type="Integer" InheritedFrom="TCPSocket" #tag EndViewProperty #tag ViewProperty Name="Left" Visible=true Group="Position" InheritedFrom="TCPSocket" #tag EndViewProperty #tag ViewProperty Name="Name" Visible=true Group="ID" InheritedFrom="TCPSocket" #tag EndViewProperty #tag ViewProperty Name="Port" Visible=true Group="Behavior" InitialValue="0" Type="Integer" InheritedFrom="TCPSocket" #tag EndViewProperty #tag ViewProperty Name="Super" Visible=true Group="ID" InheritedFrom="TCPSocket" #tag EndViewProperty #tag ViewProperty Name="Top" Visible=true Group="Position" InheritedFrom="TCPSocket" #tag EndViewProperty #tag ViewProperty Name="yield" Group="Behavior" InitialValue="0" Type="boolean" InheritedFrom="HTTPSocket" #tag EndViewProperty #tag EndViewBehaviorEnd Class#tag EndClass