tboothman / imdbphp

PHP library for retrieving film and tv information from IMDb
253 stars 84 forks source link

Add rating and number of votes to movie_recommendations() #175

Closed mam4dali closed 5 years ago

mam4dali commented 5 years ago

Add rating and number of votes To recommended movies List

jreklund commented 5 years ago

Hi, thanks for the code. I will review it in the weekend if not tboothman grabs it first. On a quick look this one are incorrect, we need a tv-show that are still on air. testYearspan_for_a_tv_show_that_havent_ended

duck7000 commented 5 years ago

Mm we had a big discussion at #157 about adding more fields to recommendations.. and now @M0H4MM4D0UTIS wants to add rating and votes to this method..

Just my thoughts about this

mam4dali commented 5 years ago

Hi, thanks for the code. I will review it in the weekend if not tboothman grabs it first. On a quick look this one are incorrect, we need we need a tv-show that are still on air. testYearspan_for_a_tv_show_that_havent_ended

Thank you for this information I solved it The previous series was replaced by the new series

jreklund commented 5 years ago

Mm we had a big discussion at #157 about adding more fields to recommendations.. and now @M0H4MM4D0UTIS wants to add rating and votes to this method..

In this particular thread you code weren't backwards compatible as year started returning something else. At a later date your pull-request for adding endyear got accepted. This pull-request adds more fields and therefor dosen't break anything.

duck7000 commented 5 years ago

@jreklund Okay fair enough. I do have other questions though Where did @M0H4MM4D0UTIS get the votes from the recommended movies? If i go to imdb, lets say this movie: https://www.imdb.com/title/tt0450385/ There are no votes available from any of the recommended movies? Screenshot from 2019-09-08 18-59-59

Maybe i don't understand what @M0H4MM4D0UTIS means?

And maybe @M0H4MM4D0UTIS can add plotoutline, directors and stars too?

jreklund commented 5 years ago

@duck7000 Place your cursor over the stars. It's a title field that will be displayed on hover. It's possible to add that information too, it's technically there.

duck7000 commented 5 years ago

@jreklund Ah now i see how it works, never thought about it this way

mam4dali commented 5 years ago

I have now looked over your modifications to movie_recommendations() and there are some changes needed for me to be able to accept this additional code.

  1. You are indenting with 2 spaces instead of 4
  2. You need a space between ){ at the end of an if statement, and the beginning.
  3. You should only use $get_rating[0]->getAttribute('title') ones like this example $cell->getElementsByTagName('a')->item(0)->getAttribute('href'). Right now you are fetching the div and fetching the attribute title three times.
  4. Make a regex that matches both rating and votes e.g. And use -1 as default, as 0 could be a valid number of votes.
if (regex_match(regex, ...getAttribute('title'), $matches) {
    $movie['rating'] = $matches[1];
    $movie['votes'] = $matches[2];
} else {
    $movie['rating'] = -1;
    $movie['votes'] = -1;
}
  1. If could make the regex without including the word this and votes it would be great, it may differ depending on language preference.
  2. This is just an edge-case and I can't replicate it on a server at the moment. But I'm viewing the site itself (imdb.com) like this; Users rated this 9,4/10 (1 584 353 votes) - click stars to rate and therefor your regex don't work. I haven't been able to replicate this problem with proxies, but there may be some servers displaying it like this. And then it won't work. I think we can ignore this.
  3. You got three line breaks between $this->movierecommendations[] = $movie; and your code. There should be a maximum of one.
  4. @return array recommendations (array[title,imdbid,year,endyear]) should include the two new fields.

Thanks for the tips I solved them all please check it