Giter VIP home page Giter VIP logo

Comments (2)

AgentSmith0 avatar AgentSmith0 commented on June 29, 2024

I can confirm this issue, awards() always returns an empty array.

from imdbphp.

duck7000 avatar duck7000 commented on June 29, 2024

as a courtesy to the users here i will share my awards method that uses GraphQL
I hope that somebody will use it.
If you need additional info i explained it all in my wiki page
https://github.com/duck7000/imdbphp6/wiki/Title-class

Remember that it might be different from the award method use here

    #-------------------------------------------------------[ Awards ]---
    /**
     * Get all awards for a title
     * @param $winsOnly Default: false, set to true to only get won awards
     * @param $event Default: "" fill eventId Example " ev0000003" to only get Oscars
     *  Possible values for $event:
     *  ev0000003 (Oscar)
     *  ev0000223 (Emmy)
     *  ev0000292 (Golden Globe)
     * @return array[festivalName][0..n] of 
     *      array[awardYear,awardWinner(bool),awardCategory,awardName,awardNotes
     *      array awardPerons[creditId,creditName,creditNote],awardOutcome]
     *  Array
            (
                [Academy Awards, USA] => Array
                    (
                        [0] => Array
                            (
                        [awardYear] => 1972
                        [awardWinner] => 
                        [awardCategory] => Best Picture
                        [awardName] => Oscar
                        [awardPerons] => Array
                            (
                                [0] => Array
                                    (
                                        [creditId] => nm0000040
                                        [creditName] => Stanley Kubrick
                                        [creditNote] => screenplay/director
                                    )

                            )
                        [awardNotes] => Based on the novel
                        [awardOutcome] => Nominee
                    )
                    )
            )
     * @see IMDB page / (TitlePage)
     */
    public function award($winsOnly = false, $event = "")
    {
        $winsOnly = $winsOnly === true ? "WINS_ONLY" : "null";
        $event = !empty($event) ? "events: " . '"' . trim($event) . '"' : "";
        
        if (empty($this->awards)) {
            $query = <<<EOF
query Award(\$id: ID!) {
  title(id: \$id) {
    awardNominations(
      first: 9999
      sort: {by: PRESTIGIOUS, order: DESC}
      filter: {wins: $winsOnly $event}
    ) {
      edges {
        node {
          award {
            event {
              text
            }
            text
            category {
              text
            }
            eventEdition {
              year
            }
            notes {
              plainText
            }
          }
          isWinner
          awardedEntities {
            ... on AwardedTitles {
              secondaryAwardNames {
                name {
                  id
                  nameText {
                    text
                  }
                }
                note {
                  plainText
                }
              }
            }
          }
        }
      }
    }
  }
}
EOF;
            $data = $this->graphql->query($query, "Award", ["id" => "tt$this->imdbID"]);
            foreach ($data->title->awardNominations->edges as $edge) {
                $eventName = isset($edge->node->award->event->text) ? $edge->node->award->event->text : '';
                $eventEditionYear = isset($edge->node->award->eventEdition->year) ? $edge->node->award->eventEdition->year : '';
                $awardName = isset($edge->node->award->text) ? $edge->node->award->text : '';
                $awardCategory = isset($edge->node->award->category->text) ? $edge->node->award->category->text : '';
                $awardNotes = isset($edge->node->award->notes->plainText) ? $edge->node->award->notes->plainText : '';
                $awardIsWinner = $edge->node->isWinner;
                $conclusion = $awardIsWinner === true ? "Winner" : "Nominee";
                
                //credited persons
                $persons = array();
                if ($edge->node->awardedEntities->secondaryAwardNames !== null) {
                    foreach ($edge->node->awardedEntities->secondaryAwardNames as $creditor) {
                        $creditName = isset($creditor->name->nameText->text) ? $creditor->name->nameText->text : '';
                        $creditId = isset($creditor->name->id) ? $creditor->name->id : '';
                        $creditNote = isset($creditor->note->plainText) ? $creditor->note->plainText : '';
                        $persons[] = array(
                            'creditId' => str_replace('nm', '', $creditId),
                            'creditName' => $creditName,
                            'creditNote' => trim($creditNote, " ()")
                        );
                    }
                }
                
                $this->awards[$eventName][] = array(
                    'awardYear' => $eventEditionYear,
                    'awardWinner' => $awardIsWinner,
                    'awardCategory' => $awardCategory,
                    'awardName' => $awardName,
                    'awardNotes' => $awardNotes,
                    'awardPerons' => $persons,
                    'awardOutcome' => $conclusion
                );
            }
        }
        return $this->awards;
    }

from imdbphp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.