# Mtv2

**URL:** <https://forums.plex.tv/t/mtv2/4253>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [July 8, 2010, 7:48am UTC](https://forums.plex.tv/t/mtv2/4253 "2010-07-08T07:48:12Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![pstarSR](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@pstarSR](https://forums.plex.tv/u/pstarSR)\
**Post date:** [July 12, 2010, 7:14pm UTC](https://forums.plex.tv/t/mtv2/4253/21 "2010-07-12T19:14:44Z")

</div>

what im trying to say is, im having a hard time making code like below work.  
  
  
  
for item in content.xpath(’//div[@class=“mdl mdl-main”]//div[3]//li/div/a’):  
  
  
  
i cant seem to filter my nodes far enough to get what i need. because thats the base for the 3 arguments its searching for. so that has to encompass all the arguments i want to find.  
  
  
  
i always run into the issue of my nodes i CAN filter down enough never have ALL the data in it. ( i.e. url, image, description… i always find 2 but not 3 )  
  
  
  
but ill check out the code. i feel like some how i have gone backwards. now the xpath is really confusing me.

---

<div class="post-metadata">

**Author:** ![hrcolb0](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/hrcolb0/32/380_2.png) [@hrcolb0](https://forums.plex.tv/u/hrcolb0)\
**Post date:** [July 12, 2010, 11:28pm UTC](https://forums.plex.tv/t/mtv2/4253/22 "2010-07-12T23:28:42Z")

</div>

You are able to do multiple main xpath searches. I did it in my fox plugin. here’s my code for the videos page. It sounds very similar to what you are after.

```auto

def VideoPage(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    Log("Hello")<br />
    Log(pageUrl)<br />
    content = XML.ElementFromURL(pageUrl, False)<br />
    for item2 in content.xpath('/rss/channel/item'):<br />
      Log("Hello2")<br />
      Log(item2)<br />
      vidUrl=item2.xpath("link")[0].text<br />
      Log(vidUrl)<br />
      thumb2 = item2.xpath("thumbnail")[0].text<br />
      title2 = item2.xpath("title")[0].text<br />
      <br />
      content2 = XML.ElementFromURL(vidUrl,True)<br />
      publisherId = content2.xpath('//div[@id="player"]//object/param[@name="publisherID"]')[0].get("value")<br />
      Log(publisherId)<br />
      videoId = content2.xpath('//div[@id="player"]//object/param[@name="@videoPlayer"]')[0].get("value")<br />
      playerId = content2.xpath('//div[@id="player"]//object/param[@name="playerID"]')[0].get("value")<br />
      truevidUrl="http://x.brightcove.com/plex/video.php?publisherId=" + publisherId + "%s&playerId=" + playerId + "%s&videoId=" + videoId + "%s"<br />
      dir.Append(WebVideoItem(truevidUrl, title=title2, thumb=thumb2))<br />
    return dir<br />

```

---

<div class="post-metadata">

**Author:** ![pstarSR](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@pstarSR](https://forums.plex.tv/u/pstarSR)\
**Post date:** [July 12, 2010, 11:58pm UTC](https://forums.plex.tv/t/mtv2/4253/23 "2010-07-12T23:58:14Z")

</div>

THATS EXACTLY IT!  
  
  
  
sorry it took so long to explain what i was trying to say.  
  
  
  
thanks!  
  
  
  
I integrated the code from Dbl\_A  
  
  
  
and decided to put this one on hold for a bit. the functionality is there, it works now. and is somewhat organized ( thanks Dbl\_A )  
  
  
  
but it has some quarks, the music video swf player is a different size as the tv show version, so the pause play coordinates arent right.  
  
  
  
im surprised it will play really. even with no width and height designation.  
  
  
  
but yeah. here is my current code. its very similar to Dbl\_A. and the only real different it seems between mine and Dbl\_A mtv shows plugin mentioned earlier. is that the early version only showed current episodes. and I wanted the back seasons also.

```auto

# PMS plugin framework<br />
from PMS import *<br />
from PMS.Objects import *<br />
from PMS.Shortcuts import *<br />
<br />
####################################################################################################<br />
<br />
MTV_PLUGIN_PREFIX = "/video/Mtv2"<br />
MTV_ROOT = "http://www.mtv.com"<br />
MTV_MUSIC = "http://www.mtv.com/music/videos"<br />
MTV_SHOWS = "http://www.mtv.com/ontv"<br />
MTV_MOVIES = "http://www.mtv.com/movies"<br />
MTV_NEWS = "http://www.mtv.com/news"<br />
<br />
####################################################################################################<br />
def Start():<br />
  Plugin.AddPrefixHandler(MTV_PLUGIN_PREFIX, MainMenu, "MTV Shows", "icon-default.png", "art-default.jpg")<br />
  Plugin.AddViewGroup("List", viewMode="InfoList", mediaType="items")<br />
  MediaContainer.art = R('art-default.jpg')<br />
  MediaContainer.title1 = 'Mtv Videos'<br />
  MediaContainer.title2 = 'Shows'<br />
  DirectoryItem.thumb = R('icon-defaultTV.jpg')<br />
  <br />
####################################################################################################<br />
def MainMenu():<br />
    dir = MediaContainer(mediaType='video') <br />
    dir.Append(Function(DirectoryItem(VideoPageMusic, "Music", thumb=R('icon-default.png')), pageUrl = MTV_MUSIC))<br />
    dir.Append(Function(DirectoryItem(MainMenu2, "Popular Shows", thumb=R('icon-defaultTV.jpg'))))<br />
    return dir<br />
    <br />
####################################################################################################<br />
def VideoPageMusic(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//div[@class="mdl"]//ol/li/div'):<br />
        link = MTV_ROOT + item.xpath("a")[0].get('href')<br />
        image = MTV_ROOT + item.xpath("a/img")[0].get('src')<br />
        title = str(item.xpath("a")[0].xpath("child::node()")[3])<br />
        dir.Append(WebVideoItem(link, title=title, thumb=image))<br />
    return dir<br />
    <br />
####################################################################################################<br />
def MainMenu2(sender):<br />
    dir = MediaContainer(mediaType='video')<br />
    dir.Append(Function(DirectoryItem(ShowList, "Recent Full Episodes"), pageUrl = MTV_SHOWS, pageAppend = "video.jhtml?filter=fulleps"))<br />
    dir.Append(Function(DirectoryItem(ShowList, "Clips"), pageUrl = MTV_SHOWS, pageAppend = "video.jhtml?filter=clips"))<br />
    dir.Append(Function(DirectoryItem(ShowList, "Seasons"), pageUrl = MTV_SHOWS, pageAppend = "seasons.jhtml"))<br />
    return dir<br />
<br />
####################################################################################################<br />
def MeatList(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//div[@class="mdl"]/ol/li//li/a'):<br />
        image = MTV_ROOT + content.xpath(".//div/ol/li/ul/li[5]/img")[0].get('src')<br />
        Log(image)<br />
        link = MTV_ROOT + item.get('href')<br />
        title = item.text<br />
        dir.Append(WebVideoItem(link, title=title, thumb=image))<br />
    return dir<br />
        <br />
####################################################################################################<br />
def ShowList(sender, pageUrl, pageAppend):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, isHTML=True)<br />
    for test in content.xpath('//div[@class="mdl mdl-main"]//div[3]//li/div'):<br />
        for item in content.xpath('//div[@class="mdl mdl-main"]//div[3]//li/div/a'):<br />
            link = MTV_ROOT + item.get('href')<br />
            link = link.replace("series.jhtml", pageAppend)<br />
            title = item.text<br />
            if "seasons.jhtml" in link:<br />
                dir.Append(Function(DirectoryItem(SeasonList, title), pageUrl = link))<br />
                continue<br />
            else:<br />
                dir.Append(Function(DirectoryItem(MeatList, title), pageUrl = link))<br />
        return dir <br />
####################################################################################################<br />
def SeasonList(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, isHTML=True)<br />
    for item in content.xpath('//div[@class="mdl"]/ol//li'):<br />
        link = MTV_ROOT + item.xpath('.//a')[0].get('href')<br />
        link = link.replace("series.jhtml", "video.jhtml?filter=fulleps")<br />
        title = item.xpath('.//a/text()[2]')[0]<br />
        title = str(title)<br />
        dir.Append(Function(DirectoryItem(MeatList, title), pageUrl = link))<br />
    return dir

```

  
  
site config  
  

```auto

<?xml version="1.0" encoding="UTF-8"?><br />
<site site="http://www.mtv.com"<br />
	    plugin="http://media.mtvnservices.com/mgid:uma"<br />
			initialState="playing"<br />
			version="1.0"><br />
	<br />
	<pre m="http://media.mtvnservices.com/player/.*" /><br />
	<br />
	<crop x="0" y="0" width="0" height="435" /><br />
	<seekbar type="simple"><br />
		<start x="62" y="445" /><br />
		<end x="642" y="445" /><br />
		<played><br />
				<color rgb="666666" /><br />
		</played><br />
	</seekbar><br />
	<br />
	<!-- PLAYING --><br />
	<state name="playing"><br />
		<event><br />
			<condition><br />
				<command name="pause" /><br />
			</condition><br />
			<action><br />
				<click x="15" y="450" /><br />
				<goto state="paused" /><br />
			</action><br />
		</event><br />
		<br />
		<!-- Video ends --><br />
		<event><br />
			<condition><br />
				<url matches="player/embed/AS3/endslate" /><br />
			</condition><br />
			<action><br />
				<goto state="end" /><br />
			</action><br />
		</event><br />
	</state><br />
	<br />
	<!-- PAUSED --><br />
	<state name="paused"><br />
		<event><br />
			<condition><br />
				<command name="play" /><br />
			</condition><br />
			<action><br />
				<click x="15" y="450" /><br />
				<goto state="playing" /><br />
			</action><br />
		</event><br />
	</state><br />
</site>

```

---

<div class="post-metadata">

**Author:** ![Dbl\_A](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@Dbl\_A](https://forums.plex.tv/u/Dbl_A)\
**Post date:** [July 13, 2010, 1:05am UTC](https://forums.plex.tv/t/mtv2/4253/24 "2010-07-13T01:05:11Z")

</div>

I’m confused, I can’t see a difference from the code I posted to this thread.  
  
I didn’t update the wiki yet, as I was unsure what you were after.  
  
  
  
FYI- There should be a way to make the swf players the same size.  
  
  
  
With all due respect, since there is already a MTV Music Videos plugin, and a MTV Shows plugin, why are you trying to rewrite them? (FYI-the consensus is that they should remain separate plugins)  
  
Is this just academic?

---

<div class="post-metadata">

**Author:** ![pstarSR](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@pstarSR](https://forums.plex.tv/u/pstarSR)\
**Post date:** [July 13, 2010, 6:44am UTC](https://forums.plex.tv/t/mtv2/4253/25 "2010-07-13T06:44:54Z")

</div>

the code you posted was only the video code, i inserted it into the code i had that has the music videos and some other differences.   
  
  
  
im not taking your thunder buddy, i said it was your code.  
  
  
  
now i keep hearing about this mtv shows plugin but yet the one i downloaded didnt have the other seasons. unless there was something wrong with my version, i dont know.  
  
  
  
maybe you could post the direct link to one your talking about. helps me not to search and find the wrong thing.  
  
  
  
in the end, not sure why it matters?  
  
  
  
its mostly acedemic since the documentation on writting apps, and the framework are pretty sparse. so why not write something for a site your a semi familiar with right?  
  
  
  
not trying to ruffle anyones feathers

---

<div class="post-metadata">

**Author:** ![Dbl\_A](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@Dbl\_A](https://forums.plex.tv/u/Dbl_A)\
**Post date:** [July 13, 2010, 2:20pm UTC](https://forums.plex.tv/t/mtv2/4253/26 "2010-07-13T14:20:44Z")

</div>

> [@](#):
>
> the code you posted was only the video code, i inserted it into the code i had that has the music videos and some other differences.   
>   
> im not taking your thunder buddy, i said it was your code.  
>   
> now i keep hearing about this mtv shows plugin but yet the one i downloaded didnt have the other seasons. unless there was something wrong with my version, i dont know.  
>   
> maybe you could post the direct link to one your talking about. helps me not to search and find the wrong thing.  
>   
> in the end, not sure why it matters?  
>   
> its mostly acedemic since the documentation on writting apps, and the framework are pretty sparse. so why not write something for a site your a semi familiar with right?  
>   
> not trying to ruffle anyones feathers

  
Not worried about my thunder level. I'm aware I don't have any anyway. :lol:  
I was just concerned about the "Double work." And I didn't want there to be more confusion out there, by having 10 different MTV plugins.  
  
You're right, the plugin I've posted to the wiki, doesn't have previous seasons.  
  
You're also right, about coding a plugin for a site you know.  
  
No hard feelings. I'm here to help, where I can.  
  
Cheers,  
Dbl\_A

---

<div class="post-metadata">

**Author:** ![pstarSR](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@pstarSR](https://forums.plex.tv/u/pstarSR)\
**Post date:** [July 13, 2010, 9:04pm UTC](https://forums.plex.tv/t/mtv2/4253/27 "2010-07-13T21:04:20Z")

</div>

i understand, just wanted to be clear my intentions  
  
  
  
and i agree having multiple plugins is confusing.

---

<div class="post-metadata">

**Author:** ![combo](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@combo](https://forums.plex.tv/u/combo)\
**Post date:** [June 16, 2012, 2:12am UTC](https://forums.plex.tv/t/mtv2/4253/28 "2012-06-16T02:12:18Z")

</div>

> [@](#):
>
> Good deal. It's a complicated one, but we'll work through it. Also, what site are you trying to get videos from?To start with, it's a Framework version 1 plugin, so there are some extra includes at the top that aren't needed in Framework V2 and ideally new plugins will work with V2, but let's get something working first before we start worrying about framework versions.1. In you ~/Library/Application Support/Plex Media Server/Plug-ins folder, copy the Gametrailers bundle and rename it to the site you want.2. Open up the Info.plist file in the Contents folder of your new plugin. It will look like this:
> 
> ```auto
> 
> <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict>	<key>CFBundleDevelopmentRegion</key>	<string>English</string>	<key>CFBundleExecutable</key>	<string>Hello</string>	<key>CFBundleIdentifier</key>	<string>com.plexapp.plugins.gametrailers</string>	<key>CFBundleInfoDictionaryVersion</key>	<string>6.0</string>	<key>CFBundlePackageType</key>	<string>AAPL</string>	<key>CFBundleSignature</key>	<string>hook</string>	<key>CFBundleVersion</key>	<string>1.0</string>	<key>PlexClientPlatforms</key>	<string>MacOSX</string>	<key>PlexFrameworkVersion</key>	<string>1</string>	<key>PlexPluginDebug</key>	<string>1</string>	<key>PlexPluginMode</key>	<string>AlwaysOn</string>	<key>PlexPluginPrefixes</key>	<array> <string>/video/gametrailers</string>	</array></dict></plist>
> 
> ```
> 
> 1. Change this key and info pair
> 
> ```auto
> 
> <key>CFBundleIdentifier</key>	<string>com.plexapp.plugins.gametrailers</string>
> 
> ```
> 
> by changing .gametrailers to the name of your new plugin.4. Change this key and info pair
> 
> ```auto
> 
> <key>PlexPluginPrefixes</key>	<array> <string>/video/gametrailers</string>	</array>
> 
> ```
> 
> by changing /gametrailers to the name of your new plugin.5. Next open up the _init_.py file inside the Code folder with a text editor. The first part looks like this:
> 
> ```auto
> 
> import refrom PMS import *from PMS.Objects import *from PMS.Shortcuts import *from ScrewAttack import *from InvisibleWalls import *from Countdown import *from Retrospectives import *from Anthology import *from GTTV import *from BonusRound import *from Support import *####################################################################################################GT_PREFIX = '/video/gametrailers'GT_PLAY_PREFIX = '/video/gametrailers-play'GT_URL = 'http://www.gametrailers.com'GT_RSS_BASE = 'http://www.gametrailers.com/rssgenerate.php?s1='GT_SEARCH_URL = 'http://www.gametrailers.com/search.php?page=0&s=%s&str_type=movies&ac=1'GT_SEARCH_BASE = 'http://www.gametrailers.com/search.php'GT_HIGHLIGHTS_URL = 'http://www.gametrailers.com/index_ajaxfuncs.php?do=get_movie_page&type=%s&page=%d&loading=0'GT_TOP20_URL = 'http://www.gametrailers.com/top20.php?toplist=media&topsublist=%s&plattyfilt=all&page=%d'GT_CATEGORIES = ['allcategories', 'review', 'preview', 'interview', 'gameplay', 'trailer', 'feature']# Available platforms. Note: There is a 'classic' platform RSS feed but there is no content in itGT_PLATFORMS = ['allplatforms', 'wii', 'xb360', 'ps3', 'pc', 'xbox', 'gc', 'ps2', 'gba', 'ds', 'psp', 'mob']# Downloadable files are available in these formatsGT_MEDIATYPES = ['mov', 'wmv', 'mp4']MAX_ITEM_COUNT = 20 # Maximum number of items to display per pageDEBUG_XML_RESPONSE = TrueCACHE_INTERVAL = 1800 # Since we are not pre-fetching content this cache time seems reasonable CACHE_RSS_INTERVAL = 1800CACHE_HIGHLIGHTS_INTERVAL = 1800CACHE_SEARCH_INTERVAL = 600RSS_NAMESPACE = {'exInfo':'http://www.gametrailers.com/rssexplained.php'}LOGIN_PREF_KEY = "login"PASSWD_PREF_KEY = "passwd"LOGGED_IN = "loggedIn"####################################################################################################
> 
> ```
> 
> Let’s simplify it to look like this:
> 
> ```auto
> 
> import refrom PMS import *from PMS.Objects import *from PMS.Shortcuts import *
> 
> ```
> 
> That takes out the site specific includes. You won’t need those.6. The next section needs to include your specific info.
> 
> ```auto
> 
> ####################################################################################################GT_PREFIX = '/video/gametrailers'GT_PLAY_PREFIX = '/video/gametrailers-play'GT_URL = 'http://www.gametrailers.com'GT_RSS_BASE = 'http://www.gametrailers.com/rssgenerate.php?s1='GT_SEARCH_URL = 'http://www.gametrailers.com/search.php?page=0&s=%s&str_type=movies&ac=1'GT_SEARCH_BASE = 'http://www.gametrailers.com/search.php'GT_HIGHLIGHTS_URL = 'http://www.gametrailers.com/index_ajaxfuncs.php?do=get_movie_page&type=%s&page=%d&loading=0'GT_TOP20_URL = 'http://www.gametrailers.com/top20.php?toplist=media&topsublist=%s&plattyfilt=all&page=%d'
> 
> ```
> 
> change the prefix to what you put in the info.plist, and delete the play prefix. Put in the base url of your site into GT\_URL, and change the variable name “GT\_URL” to something specific for your site.Next we’ll get into defining the main menu of your plugin, the menu that pops up when you first select it. I actually have to jet for most of the afternoon, but I’ll chime in when I get home. The steps we’re going to take are this:1. Setup your plugin.2. Look at the source code of the site you’re interested in.3. Pull that information into your plugin using python and xpath4. Tell Plex where the video streams are located either with a straight file location if we’re lucky, or the url that has the video in it.5. Play videos in Plex if we can get everything else.

---

<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:40pm UTC](https://forums.plex.tv/t/mtv2/4253/29 "2019-12-20T20:40:11Z")

</div>

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

[Previous page](https://forums.plex.tv/t/mtv2/4253.md?page=1)
