Given an IMDB movie id, how do I programmatically get its poster image?

前端 未结 17 691
礼貌的吻别
礼貌的吻别 2020-12-08 03:17

movie id tt0438097 can be found at http://www.imdb.com/title/tt0438097/

What\'s the url for its poster image?

相关标签:
17条回答
  • 2020-12-08 03:54

    You can use imdb-cli tool to download movie's poster, e.g.

    omdbtool -t "Ice Age: The Meltdown" | wget `sed -n '/^poster/{n;p;}'`
    
    0 讨论(0)
  • 2020-12-08 03:55
    $Movies = Get-ChildItem -path "Z:\MOVIES\COMEDY" | Where-Object {$_.Extension -eq ".avi" -or $_.Extension -eq ".mp4" -or $_.Extension -eq ".mkv" -or $_.Extension -eq<br>  <br>".flv" -or $_.Extension -eq ".xvid" -or $_.Extension -eq ".divx"} | Select-Object Name, FullName | Sort Name <br>
    #Grab all the extension types and filter the ones I ONLY want <br>
    <br>
    $COMEDY = ForEach($Movie in $Movies) <br>
    {<br>
            $Title = $($Movie.Name)<br>
            #Remove the file extension<br>
            $Title = $Title.split('.')[0] <br>       
    <br>
            #Changing the case to all lower <br>       
            $Title = $Title.ToLower()<br>
    <br>
            #Replace a space w/ %20 for the search structure<br>
            $searchTitle = $Title.Replace(' ','%20')       <br>
    <br>
            #Fetching search results<br>
            $moviesearch = Invoke-WebRequest "http://www.imdb.com/search/title?title=$searchTitle&title_type=feature"<br>
             <br>
            #Moving html elements into variable<br>
            $titleclassarray = $moviesearch.AllElements | where Class -eq 'title' | select -First 1<br>
    <br>
            #Checking if result contains movies<br>
            try<br><br>
            {
                $titleclass = $titleclassarray[0]<br>
            }<br>
            catch<br>
            {<br>
                Write-Warning "No movie found matching that title http://www.imdb.com/search/title?title=$searchTitle&title_type=feature"<br>
            }      <br>
                       <br>
            #Parcing HTML for movie link<br>
            $regex = "<\s*a\s*[^>]*?href\s*=\s*[`"']*([^`"'>]+)[^>]*?>"<br>
            $linksFound = [Regex]::Matches($titleclass.innerHTML, $regex, "IgnoreCase")<br>
             <br><br>
    
            #Fetching the first result from <br>
            $titlelink = New-Object System.Collections.ArrayList<br>
            foreach($link in $linksFound)<br>
            {<br>
                $trimmedlink = $link.Groups[1].Value.Trim()<br>
                if ($trimmedlink.Contains('/title/'))<br>
                {<br>
                    [void] $titlelink.Add($trimmedlink)<br>
                }<br>
            }<br>
            #Fetching movie page<br>
            $movieURL = "http://www.imdb.com$($titlelink[0])"<br>
            <br>
            #Grabbing the URL for the Movie Poster<br>
            $MoviePoster = ((Invoke-WebRequest –Uri $movieURL).Images | Where-Object {$_.title -like "$Title Poster"} | Where src -like "http:*").src  <br> 
    <br>
            $MyVariable = "<a href=" + '"' + $($Movie.FullName) + '"' + " " + "title='$Title'" + ">"<br>
            $ImgLocation = "<img src=" + '"' + "$MoviePoster" + '"' + "width=" + '"' + "225" + '"' + "height=" + '"' + "275" + '"' + "border=" + '"' + "0" + '"' + "alt=" +<br> '"' + $Title + '"' + "></a>" + "&nbsp;" + "&nbsp;" + "&nbsp;"+ "&nbsp;" + "&nbsp;" + "&nbsp;"+ "&nbsp;" + "&nbsp;" + "&nbsp;"<br>
            <br>
            Write-Output $MyVariable, $ImgLocation<br>
           <br>
        }$COMEDY | Out-File z:\db\COMEDY.htm  <br>
    <br>
        $after = Get-Content z:\db\COMEDY.htm <br>
    <br>
        #adding a back button to the Index <br>
        $before = Get-Content z:\db\before.txt<br>
    <br>
        #adding the back button prior to the poster images content<br>
        Set-Content z:\db\COMEDY.htm –value $before, $after<br>
    
    0 讨论(0)
  • 2020-12-08 03:56

    Check out http://www.imdbapi.com/, It returns Poster url in string.

    For example, check http://www.imdbapi.com/?i=&t=inception and you'll get the poster address: Poster":"http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1._SX320.jpg"

    Update: Seems like the site owner had some arguments with IMDB legal staff. As mentioned in the original site, new site's address is http://www.omdbapi.com/

    0 讨论(0)
  • 2020-12-08 03:58

    The URL is a random string as far as I can tell.

    It can still be easily retrieved. It is the only img inside the anchor named poster.

    So, if you are reading the source, simply search for <a name="poster" and it will be the text following the first src=" from there.

    However, you will need to keep the screen scraping code updated because that will probably change.


    You should also be aware that the images are copyrighted, so be careful to only use the image under a good "fair use" rationale.

    0 讨论(0)
  • 2020-12-08 04:01

    Be aware tough, that the terms of service explicitly forbid screenscraping. You can download the IMDB database as a set of text files, but as I understand it, the IMDB movie ID is nowhere to be found in these text files.

    0 讨论(0)
提交回复
热议问题