Mtv2

shows, movies, news etc. more than just music
so i jumped into another app, just to get me off the other one i was working on.

but here we go again. im stuck.


User-Agent: Plex Firefox/2.0.0.11<br />
Host: localhost:32400<br />
Accept: */*<br />
Connection: keep-alive<br />
X-Plex-Language: en<br />
X-Plex-Version: 0.8.5-f4b13b5<br />
<br />
00:35:59.650654: com.plexapp.plugins.mtv2                :   (Framework) Handling request :  /video/Mtv2/:/function/VideoPageShows2/KGRwMApTJ3ZpZGVvVXJsJwpwMQpTJ2h0dHA6Ly93d3cubXR2LmNvbS8vc2hvd3MvcGFya291ci9zZXJpZXMuamh0bWwnCnAyCnNTJ3NlbmRlcicKcDMKY2NvcHlfcmVnCl9yZWNvbnN0cnVjdG9yCnA0CihjUE1TLk9iamVjdHMKSXRlbUluZm9SZWNvcmQKcDUKY19fYnVpbHRpbl9fCm9iamVjdApwNgpOdHA3ClJwOAooZHA5ClMnaXRlbVRpdGxlJwpwMTAKUyJNVFYncyBVbHRpbWF0ZSBQYXJrb3VyIENoYWxsZW5nZSIKcDExCnNTJ3RpdGxlMScKcDEyClMnU2hvd3MnCnAxMwpzUyd0aXRsZTInCnAxNApTJ1Nob3dzJwpwMTUKc1MnYXJ0JwpwMTYKUycvdmlkZW8vTXR2Mi86L3Jlc291cmNlcy9hcnQtZGVmYXVsdC5qcGcnCnAxNwpzYnMu<br />
00:35:59.651564: com.plexapp.plugins.mtv2                :   (Framework) Calling named function 'VideoPageShows2'<br />
00:35:59.688375: com.plexapp.plugins.mtv2                :   (Framework) HTTPError when requesting 'http://www.mtv.com//shows/parkour/series.jhtml'<br />
00:35:59.688708: com.plexapp.plugins.mtv2                :   (Framework) An exception happened:<br />
Traceback (most recent call last):<br />
  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/1/Python/PMS/Plugin.py", line 640, in __call<br />
    return function(*args, **kwargs)<br />
  File "/Users/sethreid70/Library/Application Support/Plex Media Server/Plug-ins/Mtv2.bundle/Contents/Code/__init__.py", line 57, in VideoPageShows2<br />
    for item2 in content.xpath('//li[@class="list-title"]//a'):<br />
AttributeError: 'NoneType' object has no attribute 'xpath'<br />




nonetype object has no attribute 'xpath'..... hmm, what? xpath is just specific to my code, but what is "nonetype"?

I checked my xpath code with the firefox plugin, its ok. i even changed it a bit and broke it to check. its very similar to the menu before it. so im not sure why its causing such an issue.

this is the current code that is causing the issue


def VideoPageShows2(sender, videoUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(videoUrl, True)<br />
    for item2 in content.xpath('//li[@class="list-title"]//a'):<br />
        vidUrl = item2.xpath(".")[0].get('href')<br />
        vidUrl = MTV_ROOT+vidUrl       <br />
        Log(vidUrl)<br />
        title2 = item2.xpath(".")[0].get('href')<br />
        Log(title2)<br />
        dir.Append(WebVideoItem(vidUrl, title=title2))<br />
    return dir



full code if needed


# 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("Details", viewMode="InfoList", mediaType="items")<br />
  MediaContainer.art = R('art-default.jpg')<br />
  MediaContainer.title1 = 'Shows'<br />
  DirectoryItem.thumb=R("icon-default.png")<br />
  <br />
####################################################################################################<br />
def MainMenu():<br />
    dir = MediaContainer(mediaType='video') <br />
    dir.Append(Function(DirectoryItem(VideoPageMusic, "Music"), pageUrl = MTV_MUSIC))<br />
    dir.Append(Function(DirectoryItem(VideoPageShows, "Shows"), pageUrl = MTV_SHOWS))<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(DirectoryItem(link, title=title, thumb=image))<br />
    return dir<br />
    <br />
####################################################################################################<br />
def VideoPageShows(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//ul[@class="centerCol wide"]//a'):<br />
        videoUrl = item.xpath(".")[0].get('href')<br />
        Log(videoUrl)<br />
        title = item.xpath(".")[0].text<br />
        Log(title)<br />
        dir.Append(Function(DirectoryItem(VideoPageShows2, title), videoUrl = MTV_ROOT+videoUrl))<br />
    return dir<br />
<br />
####################################################################################################<br />
def VideoPageShows2(sender, videoUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(videoUrl, True)<br />
    for item2 in content.xpath('//li[@class="list-title"]//a'):<br />
        vidUrl = item2.xpath(".")[0].get('href')<br />
        vidUrl = MTV_ROOT+vidUrl       <br />
        Log(vidUrl)<br />
        title2 = item2.xpath(".")[0].get('href')<br />
        Log(title2)<br />
        dir.Append(WebVideoItem(vidUrl, title=title2))<br />
    return dir



yes i have more menu items listed at the beginning, but they arent called in the code. i will get to those later.

Not too sure, but:



There is another tag in the HTML that = li[@class=“list-title”]

I think you might need to use a parent or grandparent tag…



-Dbl_A




that seems to be my issue more and more. finding a tag that is unique.

but i will check that dbl_a thanks

Somwhow opening the webpage has gone wrong, your log says:

“HTTPError when requesting ‘http://www.mtv.com//shows/parkour/series.jhtml’”

That’s why the value of content is None and the xpath query fails.




well thats because there is an extra / in the url in that error

could have sworn i took that out, and tried it.

but i will check into that also.

alright, seems it was the extra /



and some syntax in the xpath



# 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("Details", viewMode="InfoList", mediaType="items")<br />
  MediaContainer.art = R('art-default.jpg')<br />
  MediaContainer.title1 = 'Shows'<br />
  DirectoryItem.thumb=R("icon-default.png")<br />
  <br />
####################################################################################################<br />
def MainMenu():<br />
    dir = MediaContainer(mediaType='video') <br />
    dir.Append(Function(DirectoryItem(VideoPageMusic, "Music"), pageUrl = MTV_MUSIC))<br />
    dir.Append(Function(DirectoryItem(VideoPageShows, "Shows"), pageUrl = MTV_SHOWS))<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(DirectoryItem(link, title=title, thumb=image))<br />
    return dir<br />
    <br />
####################################################################################################<br />
def VideoPageShows(sender, pageUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//ul[@class="centerCol wide"]//a'):<br />
        videoUrl = item.xpath(".")[0].get('href')<br />
        Log(videoUrl)<br />
        title = item.xpath(".")[0].text<br />
        Log(title)<br />
        dir.Append(Function(DirectoryItem(VideoPageShows2, title), videoUrl = MTV_ROOT+videoUrl))<br />
    return dir<br />
<br />
####################################################################################################<br />
def VideoPageShows2(sender, videoUrl):<br />
    dir = MediaContainer(title2=sender.itemTitle)<br />
    content = XML.ElementFromURL(videoUrl, True)<br />
    for item2 in content.xpath('//div[@class="marquee_list_horizontal"]//a'):<br />
        vidUrl = item2.xpath(".")[0].get('href')<br />
        vidUrl = vidUrl       <br />
        Log(vidUrl)<br />
        title2 = item2.xpath("./img")[0].get('alt')<br />
        Log(title2)<br />
        thumb3 = MTV_ROOT+item2.xpath("./img")[0].get('src')<br />
        Log(thumb3)<br />
        dir.Append(WebVideoItem(vidUrl, title=title2, thumb=thumb3))<br />
    return dir



its working, and i can watch video. but for some reason it doesnt show video right away. i have to pause, then restart and i will see it.

also, im having some issues getting the season list i want. oh well. still working on it.

thanks again guys

im linking to the new version of this app.



its been fine tuned, with some more code. but it still needs work.



im having a hard time finding a tag with everything in it. and i havent found a way to call two different xpaths for one container.



but oh well. it works. but i want to get the seasons working, so you can watch the older stuff



http://cars.wheresbetter.com/plexapps/



Mtv2.plexapp

Hey,



what do you mean by this:



im having a hard time finding a tag with everything in it. and i havent found a way to call two different xpaths for one container.



Sounds like you want to parse two xpaths and add to one container? The containers are just lists. Go through one xpath then the next adding your items and they should all be added. Let us know if you mean something different.



Jonny



I'm probably using the wrong terminology, more than likely actuallly.

But what I'm trying to say is that I find the code in the HTML, but the div, or the ul, or li, p, h etc. Class. I seem to find them in separates classes, and or I can't filter the xosth enough to get the data i need.

So I'm seeing in the daily show app they have the path search call twice. But I can't seem to implement it in my code, it breaks the app immediately.

So I can't filter the bigger parent class's so I end up finding the code in separate smaller classes. But I'm stuck on how to make othe xpath search in two different class tags for my info


Wow, I think I understood the previous post better than this...

What page are you trying to parse, and what elements are you trying to parse off that page?

FYI- I'm think you're trying to do something different, but the there is a MTV Shows plugin... as well as a MTV Music Videos plugin.



haha sorry, I was replying on an ipad last night. and i wasnt quite coherent. so i was trying to make it as simple as possible. but it looks like that didnt happen. so i will explain a bit more.

ok, heres a real life example from mtv


<br />
<div class="group-ab"><br />
<div class="group-a"><br />
<div class=" mT10p showsNav"><br />
<ul class=" section-nav"><br />
<li class="active"><br />
<div class="title2"><br />
<a href="/shows/fantasy_factory/season_3/series.jhtml">Main</a><br />
</div><br />
</li><br />
<li class=""><br />
<div class="title2"><br />
<a href="/shows/fantasy_factory/season_3/video.jhtml">Watch Video</a><br />
</div><br />
<br />
</li><br />
<li class=""><br />
<div class="title2"><br />
<a href="/shows/fantasy_factory/season_3/photos.jhtml">Photos</a><br />
</div><br />
</li><br />
<li class=""><br />
<div class="title2"><br />
<a href="/shows/fantasy_factory/season_3/seasons.jhtml">Other Seasons</a><br />
</div><br />
</li><br />
<li class=""><br />
<div class="title2"><br />
<a href="/shows/fantasy_factory/season_3/cast.jhtml">Cast Bios</a><br />
<br />
</div><br />
</li><br />
<li class=""><br />
<div class="title2"><br />
<a href="/shows/fantasy_factory/season_3/message_boards.jhtml">Message Boards</a><br />
</div><br />
</li><br />
<li class=" last last"><br />
<div class="title2"><br />
<a href="javascript:openAndFocus('http://exodus.mtv.com/site/signup', 'alertsPop', 'width=545,height=595,resizable=true,scrollbars=1');">Insider Alerts</a><br />
</div><br />
</li><br />
</ul><br />
</div><br />
<div class="mdl mL10p"><br />
<br />
<div class="h-wrap group "><br />
<h2 class="h-sub2 group"><br />




from the fantasy factory series page. i want to get the season link so you can go see all the past season. but i dont want to not show the current ones also.

so lets just start with getting the title and link. simple enough.

over simplifying the code real quick

//div[@class='group-ab']//div/div/ul/li/div/a



so, i want to filter it down to just the URL, and just the Text

in this code, the first thing it looks for is div class='goup-ab', then looks ANYWHERE in that class for another DIV class. then a direct child of that DIV/ DIV again. then direct child UL, direct child li, direct child div, direct child a.

so that i can filter down to the urls i want in that section, and the text i want. but i cant get that far in this code. it still gives me 48 results for the page.

so what im stuck on is this.

i want whats in group-ab, but i only want the stuff that is the href in the the section i quoted above.

so how i think it goes is as so

group-ab is the parent to all under it ( if i follow the div class right it should be enclosing all of it )
ok so that should be fine for a general start, then i need to narrow the search down. ok, look for Div, too much again
ok so look for div again, since its inclosed in the class and looks to be a child of some, still too much
ok so look for ul again, still too much
ok look at li/div/a etc

but i dont get the links i want, they are still 48 found.

so what i think is happening with the xpath searches is this. using this is an example.

i think

grou-ab
group-a
mT10p showsNav
section-nav
active
div
a

or

group-ab
group-a
mT10p showsNav
""
div
a

as i dont want the last javascript in that section. but i cant get it to filter down to Just that section. i think im using the xpath wrong.

*****************************

ok wait, there is an mtv shows app? i looked and didnt see one other than the music videos one

ok, i searched and did not see one in the app store. and i searched “MTV” , “MTV shows” MTV TV shows"



on the forum and didnt see anything conclusive. do you know where it is? if its already around ill stop, but i still dont see it.



your not talking about the MTV UK? are you?

the mtv_shows app is in the forum and created by Dbl_A i think.

It looks that the class group-ab isn’t specific enough for what you want. Luckily xpath also has some “advanced” features to find the element(s) you want.



To grab the main navigation elements you need a more specific class name. In combination with “contains” you can easily grab exactly that what you want:


//div[contains(@class, "showsNav")]//li



Here's another example of a somewhat more "advanced" xpath query where you retrieve the link element where the link text is "Other Seasons":

//div[contains(@class, "showsNav")]//a[text()="Other Seasons"]



Handy XPath resources:
[list][*][BIT-101 XPath Query Tool](http://www.bit-101.com/xpath/) (test XPath queries online)
[*][W3Schools XPath Tutorial](http://www.w3schools.com/XPath/xpath_nodes.asp)
[/list]

Thanks for the plug, Harley.;) I did write the MTV Shows plugin here:
http://wiki.plexapp.com/index.php/Unsupported_plugins


I wasn't trying to dissuade you, Pstar. Just wanted to let you know that there may be code in there that you could use, or even help you understand better. (I only coded for "Featured" shows and Not multiple seasons.)

you could possibly also build your own link... by simply substituting "/seasons.jhtml"


thanks guys, i will look into that. but yeah i have read those articles on xpath. and i got the code to work in xpath in firefox but had issues getting it working in plex

and dbl_as no disrespecty at all i just didnt see it so i decided to try. ill check yours out. haha

the search function on this forum leaves a bit to be desired


"That's "Dbl_A" not "Dbl_as"!" Ha! Just kidding.
(you're prolly on your ipad)

No disrespect taken, I'm not very proud of the MTV Shows plugin. It was just a quick-fix so the wifey could watch her guilty pleasures.
And again it's not fully functional.

I know what you mean about the forum search. (It seems to only like simple "one-word" searches)



With the new season of the Real World starting, and the challeenge finishing up when you posted, it was perfect timing.


thinking more about this code, those xpath searces would be great but thats still not fixing my issue.

its not that i cant GET the data in a specific xpath search. its i cant get ALL the data in one search.

so like above, where you have two lines of different code to search for different parts.

i would need to have the code be the first short one, then the call outs under it

vidUrl= item2.xpath(....... etc

but can i put your advanced code in the call out?

vidUrl= item2.xpath(//a[text()="Other Seasons"]) etc?????

the part where you say the class is not specific enough is exactly right. so i then filter it down with the individual call outs for the Url and title etc. because i want to find them all in one section. as i cant "restart" the search, or can I?

I’m having a hard time understanding what you’re after.



The only thing I can tell is that you want past seasons…

Try this:



#!/usr/bin/env python2.3<br />
#<br />
#  _MTVSHOWS__.py<br />
#  <br />
#<br />
<br />
<br />
from PMS import *<br />
from PMS.Objects import *<br />
from PMS.Shortcuts import *<br />
<br />
MTV_PLUGIN_PREFIX   = "/video/MTVSHOWS"<br />
<br />
MTV_ROOT            = "http://www.mtv.com"<br />
MTV_SHOWS_LIST      = "http://www.mtv.com/ontv/"<br />
<br />
####################################################################################################<br />
def Start():<br />
  Plugin.AddPrefixHandler(MTV_PLUGIN_PREFIX, MainMenu, "MTV Shows", "icon-default.png", "art-default.jpg")<br />
  Plugin.AddViewGroup("Details", viewMode="InfoList", mediaType="items")<br />
  MediaContainer.art = R('art-default.jpg')<br />
  MediaContainer.title1 = 'MTV Shows'<br />
  DirectoryItem.thumb=R("icon-default.png")<br />
  <br />
####################################################################################################<br />
def MainMenu():<br />
    dir = MediaContainer(mediaType='video')<br />
    dir.Append(Function(DirectoryItem(ShowList, "Full Episodes"), pageUrl = MTV_SHOWS_LIST, pageAppend = "video.jhtml?filter=fulleps"))<br />
    dir.Append(Function(DirectoryItem(ShowList, "Clips"), pageUrl = MTV_SHOWS_LIST, pageAppend = "video.jhtml?filter=clips"))<br />
    dir.Append(Function(DirectoryItem(ShowList, "Seasons"), pageUrl = MTV_SHOWS_LIST, 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