Skip to content

Commit

Permalink
Update MTV content script to accomodate API changes. Patch from Doug …
Browse files Browse the repository at this point in the history
…Vaughan.

git-svn-id: http://svn.mythtv.org/svn/trunk@27260 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
Robert McNamara committed Nov 17, 2010
1 parent 2bccadd commit 695018a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
@@ -0,0 +1,39 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<!-- Author: R.D. Vaughan
Nov 17th, 2010
Purpose: Implement full screen browser video display for MTV Videos
Example:
file:///usr/local/share/mythtv/mythnetvision/scripts/nv_python_libs/configs/HTML/mtv.html?title=We%20Are%20The%20One&videocode=176000
-->
<script type="text/javascript">
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}

var pageTitle = gup( 'title' );
if (pageTitle != "")
pageTitle = 'MTV: '+unescape(pageTitle);
var videocode = gup( 'videocode' );
var image = gup( 'image' );

var embedded = '<object style="visibility: visible;" data="http://media.mtvnservices.com/mgid:uma:video:mtv.com:VIDEOCODE" name="embeddedPlayer" id="embeddedPlayer" type="application/x-shockwave-flash" height="100%" width="100%"><param value="true" name="allowFullScreen"><param value="always" name="allowScriptAccess"><param value="transparent" name="wmode"><param value="true" name="swliveconnect"><param value="#000000" name="bgcolor"><param value="sid=MTV_Videos&amp;configParams=instance%3Dmtv%26vid%3DVIDEOCODE%26id%3D1572737&amp;autoPlay=true" name="flashvars"></object>'

document.write('<title>'+pageTitle+'</title>');
embedded = embedded.replace(/VIDEOCODE/g, videocode)
embedded = embedded.replace(/IMAGE/g, image)

document.write(embedded);

</script>
</head>
</html>
Expand Up @@ -19,7 +19,7 @@
for this api are published at http://developer.mtvnservices.com/docs
'''

__version__="v0.2.4"
__version__="v0.2.5"
# 0.1.0 Initial development
# 0.1.1 Added Tree View Processing
# 0.1.2 Modified Reee view code and structure to be standandized across all grabbers
Expand All @@ -33,6 +33,7 @@
# Removed the import and use of the feedparser library
# 0.2.3 Fixed an exception message output code error in two places
# 0.2.4 Removed the need for python MythTV bindings and added "%SHAREDIR%" to icon directory path
# 0.2.5 Use MTV web page as API not returning valid URLs

import os, struct, sys, re, time
from datetime import datetime, timedelta
Expand Down Expand Up @@ -238,6 +239,8 @@ def __init__(self,
'genres': {'Genres': 'directories/topics/music','world_reggae': 'directories/music_genres/world_reggae', 'pop': 'directories/music_genres/pop', 'metal': 'directories/music_genres/metal', 'environmental': 'directories/music_genres/environmental', 'latin': 'directories/music_genres/latino', 'randb': 'directories/music_genres/rnb', 'rock': 'directories/music_genres/rock', 'easy_listening': 'directories/music_genres/easy_listening', 'jazz': 'directories/music_genres/jazz', 'country': 'directories/music_genres/country', 'hip_hop': 'directories/music_genres/hiphop', 'classical': 'directories/music_genres/classical', 'electronic_dance': 'directories/music_genres/electronic_dance', 'blues_folk': 'directories/music_genres/blues_folk', 'alternative': 'directories/music_genres/alternative', 'soundtracks_musicals': 'directories/music_genres/soundtracks_musicals',
},
}
# Get the absolute path to the mtv.html file
self.mtvHtmlPath = u'file://'+os.path.dirname( os.path.realpath( __file__ )).replace(u'/nv_python_libs/mtv', u'/nv_python_libs/configs/HTML/mtv.html?title=%s&amp;videocode=%s')

# Initialize the tree view flag so that the item parsing code can be used for multiple purposes
self.treeview = False
Expand Down Expand Up @@ -400,7 +403,7 @@ def searchTitle(self, title, pagenumber, pagelen):

video_details = None
try:
video_details = self.videoDetails(item['id'])
video_details = self.videoDetails(item['id'], urllib.quote(item['title'].encode("utf-8")))
except MtvUrlError, msg:
sys.stderr.write(self.error_messages['MtvUrlError'] % msg)
except MtvVideoDetailError, msg:
Expand Down Expand Up @@ -442,7 +445,7 @@ def searchTitle(self, title, pagenumber, pagelen):
# end searchTitle()


def videoDetails(self, url):
def videoDetails(self, url, title=u''):
'''Using the passed URL retrieve the video meta data details
return a dictionary of video metadata details
return
Expand All @@ -463,7 +466,10 @@ def videoDetails(self, url):
cur_size = True
for e in etree:
if e.tag.endswith(u'content') and e.text == None:
metadata['video'] = e.get('url')
index = e.get('url').rindex(u':')
metadata['video'] = self.mtvHtmlPath % (title, e.get('url')[index+1:])
# !! This tag will need to be added at a later date
# metadata['customhtml'] = u'true'
metadata['duration'] = e.get('duration')
if e.tag.endswith(u'player'):
metadata['link'] = e.get('url')
Expand Down Expand Up @@ -745,7 +751,11 @@ def getVideosForURL(self, url, dictionaries):
if not metadata.has_key('video'):
metadata['video'] = metadata['link']
else:
index = metadata['video'].rindex(u':')
metadata['video'] = self.mtvHtmlPath % (urllib.quote(metadata['title'].encode("utf-8")), metadata['video'][index+1:])
metadata['link'] = metadata['video']
# !! This tag will need to be added at a later date
# metadata['customhtml'] = u'true'

if not dictionary_first: # Add the dictionaries display name
dictionaries.append([self.massageDescription(self.feed_names[self.tree_key][self.feed]), self.setTreeViewIcon()])
Expand Down

0 comments on commit 695018a

Please sign in to comment.