# Callback for Media Items

**URL:** <https://forums.plex.tv/t/callback-for-media-items/5175>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [September 10, 2010, 6:16pm UTC](https://forums.plex.tv/t/callback-for-media-items/5175 "2010-09-10T18:16:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![breakmedia](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@breakmedia](https://forums.plex.tv/u/breakmedia)\
**Post date:** [September 10, 2010, 6:16pm UTC](https://forums.plex.tv/t/callback-for-media-items/5175/1 "2010-09-10T18:16:17Z")

</div>

Howdy,  
  
  
  
We’d like to track the total number of video/picture views from the Plex plug-in. From the documentation, it appears that it’s possible to assign a callback function for an individual PhotoItem or VideoItem but my attempt down this road has failed.  
  
  
  
Anyone know how to accomplish this?  
  
  
  
Thanks!

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [September 10, 2010, 7:17pm UTC](https://forums.plex.tv/t/callback-for-media-items/5175/2 "2010-09-10T19:17:36Z")

</div>

Hi! You can do some things before starting the video by using a Function with the (Web)VideoItem, like so:  
  
  
  
For a WebVideoItem:

```auto

<br />
  # ...building a list with items here<br />
  dir.Append(Function(VideoItem(PlayVideo, title=title), url=url))<br />
<br />
####################################################################################################<br />
<br />
def PlayVideo(sender, url):<br />
  Log('Hey, were in PlayVideo!')<br />
  # Find the final video, and/or do some tracking/logging stuff here<br />
<br />
  return Redirect(url)<br />

```

  
  
For a VideoItem:  
  

```auto

<br />
  # ...building a list with items here<br />
  dir.Append(Function(WebVideoItem(PlayVideo, title=title), url=url))<br />
<br />
####################################################################################################<br />
<br />
def PlayVideo(sender, url):<br />
  Log('Hey, were in PlayVideo!')<br />
  # Find the final video, and/or do some tracking/logging stuff here<br />
<br />
  return Redirect(WebVideoItem(url))<br />

```

---

<div class="post-metadata">

**Author:** ![breakmedia](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@breakmedia](https://forums.plex.tv/u/breakmedia)\
**Post date:** [September 10, 2010, 9:52pm UTC](https://forums.plex.tv/t/callback-for-media-items/5175/3 "2010-09-10T21:52:05Z")

</div>

Works perfectly - Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 20, 2019, 8:45pm UTC](https://forums.plex.tv/t/callback-for-media-items/5175/4 "2019-12-20T20:45:14Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
