Skip to content

Commit

Permalink
1.36-Pre: TI_MDB 20241130.I
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjswan committed Nov 30, 2024
1 parent 8b334f5 commit 54fab88
Showing 1 changed file with 107 additions and 46 deletions.
153 changes: 107 additions & 46 deletions mediaportal/MediaPortal.Base/scripts/MovieInfo/TI_MDB.csscript
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//css_reference System.Core;
//css_reference System.Core;

//css_reference "core.dll";
//css_reference "Databases.dll";
Expand All @@ -24,7 +24,7 @@ using System.Web;
internal class Grabber : MarshalByRefObject, IIMDBScriptGrabber
{
const string strGrabber = "TI_MDB";
const string strGrabberVersion = "20230430.I";
const string strGrabberVersion = "20241130.I";

public Grabber()
{
Expand Down Expand Up @@ -1099,6 +1099,8 @@ internal class Grabber : MarshalByRefObject, IIMDBScriptGrabber

private static string GetUserReviewIMDB(string IMDBID)
{
string json = string.Empty;

try
{
string _reviewURL = string.Format(IMDB_Review, IMDBID);
Expand All @@ -1108,60 +1110,79 @@ internal class Grabber : MarshalByRefObject, IIMDBScriptGrabber
return string.Empty;
}

string _reviewList = string.Empty;
string regex = @"type=.application\/json.>(?<json>{.+?})<";
json = Regex.Match(_reviewPage, regex, RegexOptions.Singleline | RegexOptions.IgnoreCase).Groups["json"].Value;
if (string.IsNullOrEmpty(json))
{
Log.Debug("{0} IMDB GetUserReview, JSON not found.", strGrabber);
return string.Empty;
}
}
catch (Exception ex)
{
Log.Error("{0} IMDB Script GetUserReview error: {1}", strGrabber, ex.Message);
}

_reviewPage = HttpUtility.HtmlDecode(_reviewPage);
try
{
JsonIMDBUserReview Review = JsonConvert.DeserializeObject<JsonIMDBUserReview>(json);
if (Review == null || Review.props == null || Review.props.pageProps == null || Review.props.pageProps.contentData == null)
{
Log.Debug("{0} IMDB GetUserReview, JSON changed!?.", strGrabber);
return string.Empty;
}

string rx_review_line = @"<span>(?<rating>\d{1,2})<\/span><span[^>]+?>\/(?<maxrating>\d{1,2})<\/span>.+?<a href[^>]+?class=.title[^>]+?>(?<title>[^<]+?)<\/a>.+?<div[^>]+?content.>(?<review>[\s\S]+?)<\/div>";
ArrayList reviewList = Parse(_reviewPage, rx_review_line);
if (reviewList != null && reviewList.Count > 0)
string _reviewList = string.Empty;
if (Review.props.pageProps.contentData.reviews != null && Review.props.pageProps.contentData.reviews.Count > 0)
{
for (int i = 0; i < reviewList.Count; i++)
foreach(JsonIMDBUserReviewReview item in Review.props.pageProps.contentData.reviews)
{
Hashtable reviewMain = (Hashtable)reviewList[i];
string reviewRating = (string)reviewMain["rating"];
string reviewMaxRating = (string)reviewMain["maxrating"];
string reviewTitle = (string)reviewMain["title"];
string reviewText = (string)reviewMain["review"];
string reviewLine = string.Empty;

if (!string.IsNullOrEmpty(reviewTitle))
if (item.review != null)
{
reviewTitle = reviewTitle.Trim().Replace("\n", string.Empty);
reviewTitle = Utils.stripHTMLtags(reviewTitle);
reviewTitle = Regex.Replace(reviewTitle, @"[ ]{2,}", " ").Trim();
}
if (!string.IsNullOrEmpty(reviewText))
{
reviewText = reviewText.Trim().Replace("\n", string.Empty);
reviewText = Utils.stripHTMLtags(reviewText);
reviewText = Regex.Replace(reviewText, @"[ ]{2,}", " ").Trim();
}
if (!string.IsNullOrEmpty(reviewText))
{
if (!string.IsNullOrEmpty(reviewRating))
string reviewRating = item.review.authorRating;
string reviewMaxRating = "10";
string reviewTitle = item.review.reviewSummary;
string reviewText = item.review.reviewText;
string reviewLine = string.Empty;

if (!string.IsNullOrEmpty(reviewTitle))
{
reviewLine = "[" + reviewRating + (!string.IsNullOrEmpty(reviewMaxRating) ? "/" + reviewMaxRating : string.Empty) + "]";
reviewTitle = reviewTitle.Trim().Replace("\n", string.Empty);
reviewTitle = Utils.stripHTMLtags(reviewTitle);
reviewTitle = Regex.Replace(reviewTitle, @"[ ]{2,}", " ").Trim();
}
if (!string.IsNullOrEmpty(reviewTitle))
if (!string.IsNullOrEmpty(reviewText))
{
reviewText = reviewText.Trim().Replace("\n", string.Empty);
reviewText = Utils.stripHTMLtags(reviewText);
reviewText = Regex.Replace(reviewText, @"[ ]{2,}", " ").Trim();
}
if (!string.IsNullOrEmpty(reviewText))
{
reviewLine = reviewLine + " " + reviewTitle + "\n";
if (!string.IsNullOrEmpty(reviewRating))
{
reviewLine = "[" + reviewRating + (!string.IsNullOrEmpty(reviewMaxRating) ? "/" + reviewMaxRating : string.Empty) + "]";
}
if (!string.IsNullOrEmpty(reviewTitle))
{
reviewLine = reviewLine + " " + reviewTitle + "\n";
}
reviewLine = reviewLine + reviewText;
_reviewList = _reviewList + reviewLine + "\n";
}
reviewLine = reviewLine + reviewText;
_reviewList = _reviewList + reviewLine + "\n";
}
}
}

if (!string.IsNullOrEmpty(_reviewList))
{
// Log.Debug("{0} UserReview: {1}", strGrabber, _reviewList.Replace("\n", " "));
//Log.Debug("{0} IMDB GetUserReview: {1}", strGrabber, _reviewList.Replace("\n", " "));
return _reviewList;
}
}
catch (Exception ex)
{
Log.Error("{0} IMDB Script GetUserReview error: {1}", strGrabber, ex.Message);
Log.Debug("{0} IMDB GetUserReview, Exception {1}, JSON changed!?.", strGrabber, ex.Message);
}
return string.Empty;
}
Expand Down Expand Up @@ -1919,6 +1940,16 @@ internal class Grabber : MarshalByRefObject, IIMDBScriptGrabber
public string caption { get; set; }
}

public class JsonIMDBEntityMetadata
{
public string id { get; set; }
public JsonIMDBText titleText { get; set; }
public JsonIMDBText originalTitleText { get; set; }
public JsonIMDBReleaseYear releaseYear { get; set; }
public JsonIMDBPlot plot { get; set; }
public JsonIMDBPrimaryImage primaryImage { get; set; }
}

// Movie
public class JsonIMDBPerson : JsonIMDBBase
{
Expand Down Expand Up @@ -1986,16 +2017,6 @@ internal class Grabber : MarshalByRefObject, IIMDBScriptGrabber
public JsonIMDBSection section { get; set; }
}

public class JsonIMDBEntityMetadata
{
public string id { get; set; }
public JsonIMDBText titleText { get; set; }
public JsonIMDBText originalTitleText { get; set; }
public JsonIMDBReleaseYear releaseYear { get; set; }
public JsonIMDBPlot plot { get; set; }
public JsonIMDBPrimaryImage primaryImage { get; set; }
}

public class JsonIMDBSection
{
public List<JsonIMDBItem> items { get; set; }
Expand Down Expand Up @@ -2081,6 +2102,46 @@ internal class Grabber : MarshalByRefObject, IIMDBScriptGrabber
public string href { get; set; }
}

// User Review

public class JsonIMDBUserReview
{
public JsonIMDBUserReviewProps props { get; set; }
}

public class JsonIMDBUserReviewProps
{
public JsonIMDBUserReviewPageProps pageProps { get; set; }
}

public class JsonIMDBUserReviewPageProps
{
public JsonIMDBUserReviewContentData contentData { get; set; }
}

public class JsonIMDBUserReviewContentData
{
public JsonIMDBEntityMetadata entityMetadata { get; set; }
public List<JsonIMDBUserReviewReview> reviews { get; set; }
}

public class JsonIMDBUserReviewReview
{
public string titleId { get; set; }
public string titleText { get; set; }
public JsonIMDBUserReviewReviewText review { get; set; }
public bool isTopReview { get; set; }
}

public class JsonIMDBUserReviewReviewText
{
public string reviewId { get; set; }
public string authorRating { get; set; }
public string reviewSummary { get; set; }
public string reviewText { get; set; }
public bool spoiler { get; set; }
}

#endregion IMDB JSON Struct

#region Encoder
Expand Down

0 comments on commit 54fab88

Please sign in to comment.