Get Recently Viewed Movies

This API command is used to get all recently viewed movies from a Plex server.

URL

GET http://{ip_address}:32400/library/sections/{id}/recentlyViewed?X-Plex-Token={plex_token}

Parameters

NameDescription
ip_addressThe IP address of the Plex Media server.
plex_tokenThe Plex token.
idThe key associated with a movies/video library. This key can be found by calling the Libraries API command and using the value of the key attribute associated with the movies library.

Return Status

HTTP CodeDescription
200Success - The request was successful.
401Unauthorized - The Plex token provided was not valid.
404Not Found - The URL path is incorrect. See Remarks below.

Response

XML string value that lists the all the recently added movies in the library. An example of the XML returned from the request is shown below:

<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="100" allowSync="1" art="/:/resources/movie-fanart.jpg" identifier="com.plexapp.plugins.library" librarySectionID="2" librarySectionTitle="Movies" librarySectionUUID="493a64e7-b541-4667-b050-d702beebf2f6" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1713459976" sortAsc="1" thumb="/:/resources/movie.png" title1="Movies" title2="Recently Viewed" viewGroup="movie" viewMode="131624">
    <Video ratingKey="289418" key="/library/metadata/289418" guid="plex://movie/5d7770787a53e9001e7a3b15" slug="they-shall-not-grow-old" studio="Imperial War Museums" type="movie" title="They Shall Not Grow Old" contentRating="R" summary="Through ground breaking computer restoration technology, filmmaker Peter Jackson's team creates a moving real-to-life depiction of the WWI, as never seen before in restored, vivid colorizing & retiming of the film frames, in order to honor those who fought and more accurately depict this historical moment in world history." rating="9.9" audienceRating="9.1" viewOffset="3117216" lastViewedAt="1714352567" year="2018" tagline="A ground-breaking documentary..." thumb="/library/metadata/289418/thumb/1713850166" art="/library/metadata/289418/art/1713850166" duration="5958954" originallyAvailableAt="2018-11-09" addedAt="1686699310" updatedAt="1713850166" audienceRatingImage="rottentomatoes://image.rating.upright" chapterSource="media" primaryExtraKey="/library/metadata/289419" ratingImage="rottentomatoes://image.rating.ripe">
        <Media id="355039" duration="5958954" bitrate="11025" width="1920" height="1040" aspectRatio="1.85" audioChannels="6" audioCodec="dca" videoCodec="h264" videoResolution="1080" container="mkv" videoFrameRate="24p" audioProfile="dts" videoProfile="high">
            <Part id="355439" key="/library/parts/355439/1685130702/file.mkv" duration="5958954" file="M:\Media\Movies\They Shall Not Grow Old (2018)\They Shall Not Grow Old (2018).1080p.x264.dts.mkv" size="8213799279" audioProfile="dts" container="mkv" videoProfile="high" />
        </Media>
        <Genre tag="Documentary" />
        <Genre tag="History" />
        <Country tag="New Zealand" />
        <Country tag="Turkey" />
        <Director tag="Peter Jackson" />
        <Writer tag="Peter Jackson" />
        <Role tag="Thomas Adlam" />
        <Role tag="William Argent" />
        <Role tag="John Ashby" />
    </Video>
    ...
</MediaContainer>

The XML returned provides a list of the all movies in a library that have been recently viewed on the Plex server. The root is the MediaContainer element. This element contains a few attributes that provide overall information about the movies on the server.

MediaContainer Attributes
AttributeDescription
sizeThe number of libraries.
allowSync1 - allow syncing content.
0 - don't allow syncing content.
artBackground artwork used to represent the library.
identifierThe type of item.
librarySectionIDThe unique key associated with the library.
librarySectionTitleThe title of the library.
librarySectionUUIDUnique GUID identifier for the library.
mediaTagPrefixPrefix for the media tag.
mediaTagVersionMedia tag version.
Note: This could be a date and time value.
sortAsc1 - the library is sorted in ascending order.
0 - the library is sorted in descending order.
thumbThe thumbnail for the library.
title1The title of the library.
Note: This appears to be internally created, and can't be changed by the server owner.
title2A descriptive title for the library.
viewGroupThe group type used to view the library.
viewModeUnknown integer value.

Within the MediaContainer there are one or more Video child elements. Each Video element represents one movie available on the Plex server.

Video Attributes
AttributeDescription
ratingKeyA key associated with the movie.
keyThe relative URL of the movie information.
guidThe unique identifier comprised of the Plex agent and movie identifier for the agent.
slugThe short path name for the movie.
editionTitleThe title of the movie edition.
studioThe name of the movie studio.
typeThe type of media.
titleThe title of the movie.
titleSortThe title of the movie used to sort the movies in a collection or list.
contentRatingThe content rating associated with the movie.
summaryA summary of the movie.
ratingThe rating for the movie.
audienceRatingThe audience rating for the movie.
viewOffsetThe current amount of time the movie has been played.
lastViewedAtThe date and time for the last time the movie was viewed.
yearThe year the movie was released.
taglineThe tagline associated with the movie.
thumbThe thumbnail for the movie.
artThe background artwork used to represent the movie.
durationThe length of the movie in milliseconds.
originallyAvailableAtThe original release date of the movie.
addedAtThe date and time, in Unix time, the movie was added to the library.
updatedAtThe date and time in epoch time, the movie was updated in the library.
audienceRatingImageThe image associated with the audience rating.
chapterSourceThe chapter source type.
primaryExtraKeyThe extra key value.
ratingImageThe image associated with the rating.

Within the Video there are one or more Media child elements. Each Media element represents one media file of the movie available on the Plex server.

If there are two media files associated with the movie, such as a 1080p and 480p version, then there would be two Media child elements in the Video element.

Media Attributes
AttributeDescription
idUnique ID associated with the item.
durationThe length of the item in milliseconds.
bitrateThe bitrate of the item.
widthThe width of the item.
heightThe height of the item.
aspectRatioThe aspect ratio of the item.
audioChannelsThe number of audio channels.
audioCodecThe audio codec used to encode the audio.
videoCodecThe video codec used to encode the video.
videoResolutionThe video resolution.
containerThe item container.
videoFrameRateThe framerate standard used for the video.
videoProfileThe video profile of the media.

Within the Media there are one or more Part child elements. Each Part element represents one part of the movie. If the movie has been added to the Plex server as a multi-part movie, then each of those parts will be represented by one Part child element.

Part Attributes
AttributeDescription
idUnique ID associated with the part.
keyThe unique relative path for the part that is used at its key.
durationThe length of the part in milliseconds.
fileThe file associated with the part.
sizeThe file size of the part.
containerThe type of media container.
videoProfileThe video profile associated with the video part.

Also within the Video element there are multiple additional child elements that provide more details about the movie. These child elements include Genre, Director, Writer, Country, Collection, and Role.

Within each of these child elements is a single tag attribute that provides the information for the element. There could be multiple of the same child element within the Video, such as multiple directors or writers.

Genre Attributes
AttributeDescription
tagA genre of the movie.
Director Attributes
AttributeDescription
tagA director of the movie.
Writer Attributes
AttributeDescription
tagA writer for the movie
Country Attributes
AttributeDescription
tagA country of origin for the movie.
Collection Attributes
AttributeDescription
tagThe name of a collection containing the movie.
Role Attributes
AttributeDescription
tagThe name of a person with a role in the movie.

Remarks

When using the command ensure that the 'V' in 'recentlyCdded' is in uppercase. A lowercase 'V' will return a 404 status code.

Examples

curl -X GET http://{ip_address}:32400/library/sections/{id}/recentlyViewed?X-Plex-Token={plex_token}
import requests
plex_url = http://{ip_address}:32400/library/sections/{id}/recentlyViewed?X-Plex-Token={plex_token}
response = requests.get(plex_url)
print(response.text)
$response = Invoke-RestMethod 'http://{ip_address}:32400/library/sections/{id}/recentlyViewed?X-Plex-Token={plex_token}' -Method 'GET'
Write-Output $response
Subscribe
Display