Exemple #1
0
def build_sub_directory(url, thumb):
	saveurl = url
	html = getUrl('http://espn.go.com/video/')
	menu = common.parseDOM(html, "div", attrs = { "id": url })
	channel = common.parseDOM(menu, "li", attrs = { "class": "channel" })
	title = common.parseDOM(channel, "a")
	id = common.parseDOM(menu, "li", attrs = { "class": "channel" }, ret = "id")
	item_count = 0
	if saveurl == 'menu2949050':
		shows=[
			( settings.getLocalizedString( 30009 ), 'sportscenter' ),
			( settings.getLocalizedString( 30010 ), 'first%20take' ),
			( settings.getLocalizedString( 30011 ), 'pti' ),
			( settings.getLocalizedString( 30012 ), 'ath' )
			]	
		for name, search in shows:
			url = 'http://search.espn.go.com/results?searchString=' + search + '&start=0&dims=6'
			u = { 'mode': '2', 'name': settings.getLocalizedString( 30005 ), 'url': url, 'type': 'history' }
			infoLabels = { "Title": name, "Plot": name }
			addListItem(label = name, image = tvshows_thumb, url = u, isFolder = True, infoLabels = infoLabels)
	for name in title:
		name = name.rsplit('(')[0]
		url = 'http://espn.go.com/video/format/libraryPlaylist?categoryid=' + id[item_count].replace('channel','')
		u = { 'mode': '2', 'name': name, 'url': url, 'type': 'null' }
		infoLabels = { "Title": name, "Plot": name }
		addListItem(label = name, image = thumb, url = u, isFolder = True, infoLabels = infoLabels)
		item_count += 1	
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_video_directory(url, page, section):
    if url == "search":
        search = True
        text = common.getUserInput(settings.getLocalizedString(30003), "")
        if text == None:
            return
        url = "channels%2F*%7Cgames%2F*%7Cflip_video_diaries%7Cfiba&text=" + urllib.quote(text)
    else:
        search = False
    save_url = url
    if page == 1 and search != True:
        base = "http://www.nba.com/.element/ssi/auto/2.0/aps/video/playlists/" + section + ".html?section="
    else:
        base = "http://searchapp2.nba.com/nba-search/query.jsp?section="
    url = base + url + "&season=1213&sort=recent&hide=true&type=advvideo&npp=15&start=" + str(1 + (15 * (page - 1)))
    html = getUrl(url)
    textarea = common.parseDOM(html, "textarea", attrs={"id": "jsCode"})[0]
    content = (
        textarea.replace("\\'", "\\\\'")
        .replace('\\\\"', '\\\\\\"')
        .replace("\\n", "")
        .replace("\\t", "")
        .replace("\\x", "")
    )
    query = json.loads(content)
    data = query["results"][0]
    count = query["metaResults"]["advvideo"]
    if len(data) == 0:
        dialog = xbmcgui.Dialog()
        ok = dialog.ok(plugin, settings.getLocalizedString(30004) + "\n" + settings.getLocalizedString(30005))
        return
    for results in data:
        mediaDateUts = time.ctime(float(results["mediaDateUts"]))
        date = datetime.datetime.fromtimestamp(
            time.mktime(time.strptime(mediaDateUts, "%a %b %d %H:%M:%S %Y"))
        ).strftime("%d.%m.%Y")
        title = results["title"].replace("\\", "")
        thumb = results["metadata"]["media"]["thumbnail"]["url"].replace("136x96", "576x324")
        length = results["metadata"]["video"]["length"].split(":")
        duration = int(length[0]) * 60 + int(length[1])
        plot = results["metadata"]["media"]["excerpt"].replace("\\", "")
        url = results["id"].replace("/video/", "").replace("/index.html", "")
        infoLabels = {"Title": title, "Plot": plot, "Aired": date}
        u = {"mode": "3", "name": title, "url": url, "thumb": thumb, "plot": plot}
        addListItem(
            label=title, image=thumb, url=u, isFolder=False, infoLabels=infoLabels, fanart=fanart, duration=duration
        )
    if int(page) * 15 < int(count):
        u = {"mode": "0", "page": str(int(page) + 1), "url": save_url, "section": section}
        addListItem(
            label="[Next Page (" + str(int(page) + 1) + ")]",
            image=next_thumb,
            url=u,
            isFolder=True,
            infoLabels=False,
            fanart=fanart,
        )
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_NONE)
    setViewMode("503")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_main_directory():
	main=[
		( settings.getLocalizedString(30000), search_thumb, '0' ),
		( settings.getLocalizedString(30001), film_reel_thumb, '1' ),
		( settings.getLocalizedString(30002), clapperboard_thumb, '2' ),
		( settings.getLocalizedString(30003), oscar_thumb, '3' ),
		( settings.getLocalizedString(30004), popcorn_thumb, '6' ),
		( settings.getLocalizedString(30015), library_thumb, '7' )
		]
	for name, thumbnailImage, mode in main:
		listitem = xbmcgui.ListItem( label = name, iconImage = "DefaultVideo.png", thumbnailImage = thumbnailImage )
		u = { 'mode': mode, 'name': name }
		addListItem(label = name, image = thumbnailImage, url = u, isFolder = True, totalItems = 0, infoLabels = False)
	data = getUrl( 'http://www.traileraddict.com' )
	url_thumb_x_title = re.compile( '<a href="/trailer/(.+?)"><img src="(.+?)" border="0" alt="(.+?)" title="(.+?)" style="margin:2px 10px 8px 10px;">' ).findall( data )
	totalItems = len(url_thumb_x_title)
	for url, thumb, x, title in url_thumb_x_title:
		title = title.rsplit( ' - ' )
		name1 = clean( title[0] )
		if len( title ) > 1:
			name2 = clean( title[0] ) + ' (' + clean( title[1] ) + ')'
		else:
			name2 = clean( title[0] )
		url = 'http://www.traileraddict.com/trailer/' + url
		thumb = 'http://www.traileraddict.com' + thumb
		cm = []
		run = sys.argv[0] + '?' + urllib.urlencode({ 'mode': '5', 'name': name2, 'url': url, 'download': 'True' })
		cm.append( (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run) )
		cm.append( (settings.getLocalizedString(30014), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)" % name1) )
		u = { 'mode': '5', 'name': name2, 'url': url }
		addListItem(label = name1, image = thumb, url = u, isFolder = False, totalItems = totalItems, infoLabels = False, cm = cm)
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("500", "movies")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_featured_directory( page ):
	save_page = page
	data = getUrl( 'http://www.traileraddict.com/attraction/' + str( int( page ) + 1) )
	url_thumb_x_title = re.compile( '<a href="/trailer/(.+?)"><img src="(.+?)" border="0" alt="(.+?)" title="(.+?)" style="margin:8px 5px 2px 5px;"></a>' ).findall( data )
	totalItems = len(url_thumb_x_title)
	for url, thumb, x, title in url_thumb_x_title:
		title = title.rsplit( ' - ' )
		name1 = clean( title[0] )
		if len( title ) > 1:
			name2 = clean( title[0] ) + ' (' + clean( title[1] ) + ')'
		else:
			name2 = clean( title[0] )
		url = 'http://www.traileraddict.com/trailer/' + url
		thumb = 'http://www.traileraddict.com' + thumb
		cm = []
		run = sys.argv[0] + '?' + urllib.urlencode({ 'mode': '5', 'name': name2, 'url': url, 'download': 'True' })
		cm.append( (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run) )
		cm.append( (settings.getLocalizedString(30014), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)" % name1) )
		u = { 'mode': '5', 'name': name2, 'url': url }
		addListItem(label = name1, image = thumb, url = u, isFolder = False, totalItems = totalItems, infoLabels = False, cm = cm)
	u = { 'mode': '6', 'page': str( int( save_page ) + 1 ) }
	addListItem(label = '[ Next Page (' + str( int( save_page ) + 2 ) + ') ]', image = next_thumb, url = u, isFolder =  True, totalItems = 0, infoLabels = False)
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("500", "movies")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_search_directory( url, page ):
	save_url = url.replace( ' ', '%20' )
	url = 'http://www.pbs.org/search/?q=' + url.replace( ' ', '%20' ) + '&ss=pbs&mediatype=Video&start=' + str( page * 10 )
	data = getUrl( url )
	title_id_thumb = re.compile('<a title="(.*?)" target="" rel="nofollow" onclick="EZDATA\.trackGaEvent\(\'search\', \'navigation\', \'external\'\);" href="(.*?)"><img src="(.*?)" class="ez-primaryThumb"').findall(data)
	program = re.compile('<p class="ez-metaextra1 ez-icon">(.*?)</p>').findall(data)
	plot = re.compile('<p class="ez-desc">(.*?)<div class="(ez-snippets|ez-itemUrl)">', re.DOTALL).findall(data)
	video_count = re.compile('<b class="ez-total">(.*?)</b>').findall(data)
	if len(title_id_thumb) == 0:
		dialog = xbmcgui.Dialog()
		ok = dialog.ok( plugin , settings.getLocalizedString( 30004 ) + '\n' + settings.getLocalizedString( 30005 ) )
		return
	item_count = 0
	for title, id, thumb in title_id_thumb:
		infoLabels = { "Title": clean( title ) , "Director": "PBS", "Studio": clean( program[item_count] ), "Plot": clean( plot[item_count][0] ) }
		u = { 'mode': '0', 'name': urllib.quote_plus( clean( program[item_count] ) ), 'program_id': urllib.quote_plus( id.rsplit('/')[4] ), 'topic': urllib.quote_plus( 'False' ) }
		addListItem(label = clean( title ), image = thumb, url = u, isFolder = False, infoLabels = infoLabels, fanart = fanart)
		item_count += 1	
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_STUDIO )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LABEL )
	if page == 0:
		build_programs_directory( save_url.replace( '%20', ' ' ), 0 )
	if ( int( video_count[0] ) - ( 10 * int( page ) ) ) > 10:
		u = { 'mode': '6', 'page': str( int( page ) + 1 ), 'url': urllib.quote_plus( save_url ) }
		addListItem(label = '[Next Page (' + str( int( page ) + 2 ) + ')]', image = next_thumb, url = u, isFolder = True, infoLabels = False, fanart = fanart)
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_STUDIO )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LABEL )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
Exemple #6
0
def build_video_directory(name, url):
    if name == settings.getLocalizedString(30012):
        searchr = common.getUserInput(settings.getLocalizedString(30001), "")
        if searchr == None:
            build_main_directory()
            return
        url = "http://g4tv.com/videos/?sort=mostrecent&q=" + searchr.replace(" ", "%20") + "&ajax=true"
    nexturl = url
    html = getUrl(url + "&page=" + str(page))
    wrap1 = common.parseDOM(html, "div", attrs={"class": "li-wrap-1"})
    wrap2 = common.parseDOM(html, "div", attrs={"class": "li-wrap-2"})
    desc = common.parseDOM(wrap1, "p", attrs={"class": "desc"})
    info = common.parseDOM(wrap1, "p", attrs={"class": "meta-info"})
    h4 = common.parseDOM(wrap1, "h4")
    title = common.parseDOM(h4, "a")
    href = common.parseDOM(h4, "a", ret="href")
    img = common.parseDOM(wrap2, "img", ret="src")
    if len(img) == 0:
        dialog = xbmcgui.Dialog()
        ok = dialog.ok(plugin, settings.getLocalizedString(30002) + "\n" + settings.getLocalizedString(30003))
        build_main_directory()
        return
    for item_count in range(len(img)):
        if common.stripTags(info[item_count]).find("Views") == -1:
            length = common.stripTags(info[item_count]).rsplit("|")[1].replace(" ", "").split(":")
        else:
            length = common.stripTags(info[item_count]).rsplit("|")[2].replace(" ", "").split(":")
        duration = int(length[0]) * 60 + int(length[1])
        thumb = img[item_count].replace("138x78", "256x256")
        plot = common.stripTags(clean(desc[item_count]))
        name = common.stripTags(clean(title[item_count]))
        try:
            posted = common.stripTags(info[item_count]).rsplit("|")[0].rsplit(":")[1].strip()
            if "ago" in posted:
                days = int(posted.rsplit(" ")[0])
                aired = (datetime.date.today() - datetime.timedelta(days=days)).strftime("%d.%m.%Y")
            else:
                aired = datetime.datetime.fromtimestamp(time.mktime(time.strptime(posted, "%b %d, %Y"))).strftime(
                    "%d.%m.%Y"
                )
            infoLabels = {"Title": name, "Plot": plot, "Aired": aired}
        except:
            infoLabels = {"Title": name, "Plot": plot}
        url = href[item_count]
        u = {"mode": "3", "name": name, "url": url, "plot": plot, "thumb": thumb}
        addListItem(
            label=name, image=thumb, url=u, isFolder=False, infoLabels=infoLabels, fanart=False, duration=duration
        )
    if len(img) >= 15:
        u = {"mode": "2", "name": name, "url": nexturl, "page": str(int(page) + 1)}
        infoLabels = {"Title": settings.getLocalizedString(30019), "Plot": settings.getLocalizedString(30019)}
        addListItem(
            label=settings.getLocalizedString(30019), image=next_thumb, url=u, isFolder=True, infoLabels=infoLabels
        )
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
    setViewMode("503")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_topics_directory():
	data = cove.categories.filter(order_by='name',filter_namespace__name='COVE Taxonomy')
	item = None
	for results in data:
		if item != results['name']:
			u = { 'mode': '0', 'name': urllib.quote_plus( results['name'] ), 'topic': urllib.quote_plus( 'True' ) }
			addListItem(label = results['name'], image = topics_thumb, url = u, isFolder = True, infoLabels = False, fanart = fanart)
			item = results['name']
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("515")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_main_directory(url):
	data = json.loads(getUrl(url))['shows']
	if settings.getSetting('folder') == 'true' and settings.getSetting( 'downloadPath' ) and url == BASE + 'getShows' + KEY:
		u = { 'mode': None, 'url': settings.getSetting( 'downloadPath' ) }
		infoLabels = { "Title": settings.getLocalizedString( 30012 ), "Plot": settings.getLocalizedString( 30022 ) }
		addListItem('[ ' + settings.getLocalizedString( 30012 ) + ' ]', downloads_thumb, u, True, 0, infoLabels, fanart_bg)
	if url == BASE + 'getShows' + KEY:
		#Featured
		u = { 'mode': '1', 'name': settings.getLocalizedString( 30023 ), 'url': BASE + 'getEpisodes' + KEY + '&grouping=featured', 'slug': 'None' }
		infoLabels = { "Title": settings.getLocalizedString( 30023 ), "Plot": settings.getLocalizedString( 30024 ) }
		addListItem('[ ' + settings.getLocalizedString( 30023 ) + ' ]', featured_thumb, u, True, 0, infoLabels, fanart_bg)
		#Most Recent
		u = { 'mode': '1', 'name': settings.getLocalizedString( 30013 ), 'url': BASE + 'getEpisodes' + KEY + '&grouping=latest', 'slug': 'None' }
		infoLabels = { "Title": settings.getLocalizedString( 30013 ), "Plot": settings.getLocalizedString( 30018 ) }
		addListItem('[ ' + settings.getLocalizedString( 30013 ) + ' ]', recent_thumb, u, True, 0, infoLabels, fanart_bg)
		#Networks
		u = { 'mode': '4' }
		infoLabels = { "Title": settings.getLocalizedString( 30027 ), "Plot": settings.getLocalizedString( 30028 ) }
		addListItem('[ ' + settings.getLocalizedString( 30027 ) + ' ]', networks_thumb, u, True, 0, infoLabels, fanart_bg)
		#Archived Shows
		u = { 'mode': '3', 'url': BASE + 'getShows' + KEY + '&grouping=archived' }
		infoLabels = { "Title": settings.getLocalizedString( 30014 ), "Plot": settings.getLocalizedString( 30019 ) }
		addListItem('[ ' + settings.getLocalizedString( 30014 ) + ' ]', archived_thumb, u, True, 0, infoLabels, fanart_bg)
	daily_data = {}
	for daily_show in data:
		if daily_show['parent_id'] != None:
			name = daily_show['name']
			thumb = daily_show['images']['logo'].replace('\\','')
			url = BASE + 'getEpisodes' + KEY + '&show_id=' + daily_show['id']
			daily_data[daily_show['parent_id']] = { 'name': name, 'url': url, 'plot': daily_show['summary'], 'thumb': thumb}
	totalItems = len(data) - len(daily_data)
	for show in data:
		if show['parent_id'] == None:
			if show['id'] in daily_data:
				daily_info = daily_data[show['id']]
			else:
				daily_info = 'None'
			slug = show['slug']
			if not settings.getSetting(slug):
				fanart = fanart_bg
			else:
				fanart = settings.getSetting(slug)
			name = show['name']
			#fanart = show['images']['hero'].replace('\\','')
			url = BASE + 'getEpisodes' + KEY + '&show_id=' + show['id']
			u = { 'mode': '1', 'name': name, 'url': url, 'slug': slug, 'daily_info': daily_info }
			infoLabels = { "Title": name, "Plot": show['summary'] }
			addListItem(name, show['images']['logo'].replace('\\',''), u, True, totalItems, infoLabels, fanart)
	xbmcplugin.addSortMethod( handle = int(sys.argv[ 1 ]), sortMethod = xbmcplugin.SORT_METHOD_UNSORTED )
	setViewMode("515")
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
def getMovieLibrary():
	try:
		if common.getXBMCVersion() >= 12.0:
			properties = ['year', 'imdbnumber', 'thumbnail', 'plot', 'dateadded', 'rating']
		else:
			properties = ['year', 'imdbnumber', 'thumbnail', 'plot', 'rating']
	except:
		properties = ['year', 'imdbnumber', 'thumbnail', 'plot', 'rating']
	rpccmd = json.dumps({'jsonrpc': '2.0', 'method': 'VideoLibrary.GetMovies', 'params':{'properties': properties, "sort": { "order": "ascending", "method": "label", "ignorearticle": True } }, "id": "libMovies"})
	result = xbmc.executeJSONRPC(rpccmd)
	result = json.loads(result)
	if 'error' in result:
		dialog = xbmcgui.Dialog()
		ok = dialog.ok(plugin, settings.getLocalizedString( 30018 ))
		build_main_directory()
		return	
	if (result['result']['limits']['total'] == 0):
		dialog = xbmcgui.Dialog()
		ok = dialog.ok(plugin, settings.getLocalizedString( 30016 ))
		build_main_directory()
		return
	totalItems = len(result['result']['movies'])
	for movie in result['result']['movies']:
		label = movie['label'].encode('ascii', 'ignore')
		plot = movie['plot'].encode('ascii', 'ignore')
		if 'dateadded' in movie:
			day = movie['dateadded'].split(' ')[0].split('-')
			date = day[2] + '.' + day[1] + '.' + day[0]
		else:
			date = '0000.00.00'
		thumbnail = movie['thumbnail']
		year = movie['thumbnail']
		url = movie['imdbnumber'].rsplit('tt')
		if len(url) == 2:
			url = url[1]
		else:
			url = '1'
		listitem = xbmcgui.ListItem( label = label, iconImage = thumbnail, thumbnailImage = thumbnail )
		u = { 'mode': '8', 'name': label, 'url': url }
		cm = []
		run = sys.argv[0] + '?' + urllib.urlencode({ 'mode': '8', 'name': label, 'url': url, 'download': 'True' })
		cm.append( (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run) )
		infoLabels = { "Title": label, "Plot": plot, "date": date, "Year": movie['year'], "Rating": movie['rating'] }
		addListItem(label = label, image = thumbnail, url = u, isFolder = False, totalItems = totalItems, infoLabels = infoLabels, cm = cm)
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_TITLE )
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_DATE )
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_VIDEO_YEAR )
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_VIDEO_RATING )
	setViewMode("500", "movies")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
Exemple #10
0
def build_main_directory():
	main=[
		( settings.getLocalizedString( 30007 ), '2' ),
		( settings.getLocalizedString( 30000 ), '0' ),
		( settings.getLocalizedString( 30001 ), '0' ),
		( settings.getLocalizedString( 30002 ), '0' ),
		( settings.getLocalizedString( 30003 ), '0' )
		]
	for name, mode in main:
		u = { 'mode': mode, 'name': name }
		addListItem(label = name, image = icon, url = u, isFolder = True, totalItems = 5, infoLabels = False, fanart = fanart)
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("515")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
Exemple #11
0
def build_featured_directory(page):
    save_page = page
    data = getUrl('http://www.traileraddict.com/attraction/' +
                  str(int(page) + 1))
    url_thumb_x_title = re.compile(
        '<a href="/trailer/(.+?)"><img src="(.+?)" border="0" alt="(.+?)" title="(.+?)" style="margin:8px 5px 2px 5px;"></a>'
    ).findall(data)
    totalItems = len(url_thumb_x_title)
    for url, thumb, x, title in url_thumb_x_title:
        title = title.rsplit(' - ')
        name1 = clean(title[0])
        if len(title) > 1:
            name2 = clean(title[0]) + ' (' + clean(title[1]) + ')'
        else:
            name2 = clean(title[0])
        url = 'http://www.traileraddict.com/trailer/' + url
        thumb = 'http://www.traileraddict.com' + thumb
        cm = []
        run = sys.argv[0] + '?' + urllib.urlencode({
            'mode': '5',
            'name': name2,
            'url': url,
            'download': 'True'
        })
        cm.append(
            (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run))
        cm.append((settings.getLocalizedString(
            30014
        ), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)"
                   % name1))
        u = {'mode': '5', 'name': name2, 'url': url}
        addListItem(label=name1,
                    image=thumb,
                    url=u,
                    isFolder=False,
                    totalItems=totalItems,
                    infoLabels=False,
                    cm=cm)
    u = {'mode': '6', 'page': str(int(save_page) + 1)}
    addListItem(label='[ Next Page (' + str(int(save_page) + 2) + ') ]',
                image=next_thumb,
                url=u,
                isFolder=True,
                totalItems=0,
                infoLabels=False)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_NONE)
    setViewMode("500", "movies")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_main_directory():
    main = [
        (settings.getLocalizedString(30000), highlights_thumb, "games%2F*%7Cchannels%2Fplayoffs", "0", "highlights"),
        (settings.getLocalizedString(30001), topplays_thumb, "channels%2Ftop_plays", "0", "top_plays"),
        (settings.getLocalizedString(30002), teams_thumb, "null", "1", "null"),
        (settings.getLocalizedString(30003), search_thumb, "search", "0", "null"),
    ]
    for name, thumbnailImage, url, mode, section in main:
        u = {"mode": mode, "url": url, "section": section}
        infoLabels = {"Title": name, "Plot": name}
        addListItem(
            label="[ " + name + " ]", image=thumbnailImage, url=u, isFolder=True, infoLabels=infoLabels, fanart=fanart
        )
    build_video_directory("channels%2F*%7Cgames%2F*%7Cflip_video_diaries%7Cfiba", 1, "all_videos")
    setViewMode("503")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_networks_directory():
	html = getUrl('http://revision3.com/networks')
	cards = common.parseDOM(html, "ul", attrs = { "class": "Cards show-grid" })
	item = common.parseDOM(cards, "li", attrs = { "class": "Grid2 Card item" })
	for network in item:
		image = common.parseDOM(network, "img", attrs = { "class": "thumbnail" }, ret="src")[0]
		url = common.parseDOM(network, "a", ret="href")[0]
		meta = common.parseDOM(network, "div", attrs = { "class": "meta" })
		name = common.parseDOM(meta, "strong")[0]
		plot = common.parseDOM(meta, "p")[0].rsplit('\n        ')[1]
		u = { 'mode': '5', 'url': url }
		infoLabels = { "Title": name, "Plot": plot }
		addListItem(name, image, u, True, len(item), infoLabels, fanart_bg)
	xbmcplugin.addSortMethod( handle = int(sys.argv[ 1 ]), sortMethod = xbmcplugin.SORT_METHOD_UNSORTED )
	setViewMode("515")
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_teams_directory():
    html = getUrl("http://www.nba.com/video/")
    team_names = common.parseDOM(html, "a", attrs={"id": "nbaVidSelectLk"})
    team_nicks = common.parseDOM(html, "a", attrs={"id": "nbaVidSelectLk"}, ret="onclick")
    item_count = 0
    for title in team_names:
        nick = re.compile("\('teams/(.+?)'").findall(team_nicks[item_count])[0]
        url = (
            "teams%2F" + nick + "%7Cgames%2F*%7Cchannels%2F*&team=" + title.replace(" ", "%20") + "&site=nba%2C" + nick
        )
        u = {"mode": "0", "url": url, "section": nick + "_all"}
        addListItem(label=title, image=teams_thumb, url=u, isFolder=True, infoLabels=False, fanart=fanart)
        item_count += 1
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_LABEL)
    setViewMode("515")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Exemple #15
0
def build_sub_directory(name, type):
    html = getUrl("http://g4tv.com/videos/index.html")
    content = common.parseDOM(html, "div", attrs={"id": "search_" + type})
    filter = common.parseDOM(content, "a", attrs={"href": "#"})
    count = common.parseDOM(content, "span", attrs={"class": "count"})
    for item_count in range(len(filter) - 1):
        name = filter[item_count]
        url = "http://g4tv.com/videos/?sort=mostrecent&q=null&ajax=true&" + type + "=" + name.replace(" ", "+")
        u = {"mode": "2", "name": name, "url": url}
        infoLabels = {"Title": name, "Plot": name}
        addListItem(
            label=name + " " + count[item_count + 1], image=eval(type), url=u, isFolder=True, infoLabels=infoLabels
        )
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
    setViewMode("503")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_main_directory():
	main=[
		( settings.getLocalizedString( 30000 ), programs_thumb, '1' ),
		( settings.getLocalizedString( 30001 ), topics_thumb, '2' ),
		( settings.getLocalizedString( 30003 ), search_thumb, '4' ),
		( settings.getLocalizedString( 30014 ), pbskids_thumb, '1' )
		]
	for name, thumbnailImage, mode in main:
		u = { 'mode': mode, 'name': name }
		addListItem(label = name, image = thumbnailImage, url = u, isFolder = True, infoLabels = False, fanart = fanart)
	try:
		build_most_watched_directory()
	except:
		pass
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("501")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_main_directory():
	main=[
		( settings.getLocalizedString( 30000 ), tvshows_thumb, 'menu2949050', '1' ),
		#( settings.getLocalizedString( 30001 ), original_thumb, 'menu3385449', '1' ),
		( settings.getLocalizedString( 30002 ), categories_thumb, 'menu2949049', '1' ),
		( settings.getLocalizedString( 30005 ), search_thumb, 'search', '2' )
		]
	for name, thumbnailImage, url, mode in main:
		u = { 'mode': mode, 'thumb': thumbnailImage, 'url': url, 'name': name }
		infoLabels = { "Title": name, "Plot": name }
		addListItem(label = '[ ' + name + ' ]', image = thumbnailImage, url = u, isFolder = True, infoLabels = infoLabels)
	if settings.getSetting('presets_search') != '' and settings.getSetting('history') == 'true':
		u = { 'mode': '4' }
		infoLabels = { "Title": settings.getLocalizedString( 30006 ), "Plot": settings.getLocalizedString( 30006 ) }
		addListItem(label = '[ ' + settings.getLocalizedString( 30006 ) + ' ]', image = history_thumb, url = u, isFolder = True, infoLabels = infoLabels)
	build_video_directory('http://espn.go.com/video/format/libraryPlaylist?categoryid=2378529', 'The Latest', 'null')
	setViewMode("503")
def build_search_directory(url):
	if url == 'search':
		try:
			search = common.getUserInput("Enter search term", "").replace(' ','+')
			url = 'http://revision3.com/search/page?type=video&q=' + search + '&limit=10&page=1'
		except:
			return
	html = getUrl(url).encode('ascii', 'ignore')
	current = common.parseDOM(html, "span", attrs = { "class": "active" })
	pageLoad = common.parseDOM(html, "a", ret = "onclick")
	try:
		strs = 'http://revision3.com' + pageLoad[-1:][0].rsplit('\'')[1]
		params = getParameters(strs)
		saveurl = strs.rstrip('&page=' + params['page']) + '&page=' + str( int(current[0]) + 1 )
		if int(params['page']) > int(current[0]):
			next = True
		else:
			next = False
	except:
		next = False
	episodes = common.parseDOM(html, "li", attrs = { "class": "video" })
	if len(episodes) == 0:
		dialog = xbmcgui.Dialog()
		ok = dialog.ok( plugin , settings.getLocalizedString( 30009 ) + '\n' + settings.getLocalizedString( 30010 ) )
		return
	for data in episodes:
		thumb = common.parseDOM(data, "img", ret = "src")[0]
		url = common.parseDOM(data, "a", attrs = { "class": "thumbnail" }, ret = "href" )[0]
		url = clean(url.replace('http://www.videosurf.com/webui/inc/go.php?redirect=','')).replace('&client_id=revision3','')
		title = clean(common.parseDOM(data, "a", attrs = { "class": "title" })[0])
		plot = clean(common.stripTags(common.parseDOM(data, "div", attrs = { "class": "description" })[0]))
		try:
			studio = title.rsplit(' - ')[1]
		except:
			studio = 'Search'
		infoLabels = { "Title": title, "Studio": studio, "Plot": plot, "Episode": 0, "Aired": "0000-00-00" }
		u = { 'mode': '2', 'name': urllib.quote_plus(title), 'url': urllib.quote_plus(url), 'plot': urllib.quote_plus(infoLabels['Plot']), 'studio': urllib.quote_plus(infoLabels['Studio']), 'episode': urllib.quote_plus(str(infoLabels['Episode'])), 'thumb': urllib.quote_plus(thumb), 'date': urllib.quote_plus(infoLabels['Aired']) }
		addListItem(title, thumb, u, False, infoLabels, fanart_bg)
	if next == True:
		u = { 'mode': '4', 'url': urllib.quote_plus(saveurl), 'name': urllib.quote_plus(studio) }
		infoLabels = { "Title": settings.getLocalizedString( 30016 ), "Plot": settings.getLocalizedString( 30016 ) }
		addListItem(settings.getLocalizedString( 30016 ) + ' (' + str( int(current[0]) + 1 ) + ')', next_thumb, u, True, infoLabels, fanart_bg)
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED )
	setViewMode("503")
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
Exemple #19
0
def build_main_directory():
    main = [
        (settings.getLocalizedString(30011), recent, "2", "recent"),
        (settings.getLocalizedString(30012), search, "2", "search"),
        (settings.getLocalizedString(30013), showName, "1", "showName"),
        (settings.getLocalizedString(30014), subType, "1", "subType"),
        (settings.getLocalizedString(30015), eventName, "1", "eventName"),
        (settings.getLocalizedString(30016), platform, "1", "platform"),
        (settings.getLocalizedString(30017), genre, "1", "genre"),
    ]
    for name, thumbnailImage, mode, type in main:
        url = "http://g4tv.com/videos/?sort=mostrecent&q=null&ajax=true"
        u = {"mode": mode, "name": name, "type": type, "url": url}
        infoLabels = {"Title": name, "Plot": name}
        addListItem(label=name, image=thumbnailImage, url=u, isFolder=True, infoLabels=infoLabels)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_NONE)
    setViewMode("503")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_programs_directory( name, page ):
	checking = True
	while checking:
		start = str( 200 * page )
		#data = cove.programs.filter(fields='associated_images,mediafiles,categories',filter_categories__namespace__name='COVE Taxonomy',order_by='title',limit_start=start)
		if name != settings.getLocalizedString( 30014 ) and name != settings.getLocalizedString( 30000 ):
			data = cove.programs.filter(fields='associated_images',order_by='title',limit_start=start,filter_title=name)
		else:
			data = cove.programs.filter(fields='associated_images',order_by='title',limit_start=start)
		if ( len(data) ) == 200:
			page = page + 1
		else:
			checking = False
		for results in data:
			if len(results['nola_root'].strip()) != 0:
				if name == settings.getLocalizedString( 30014 ):
					if results['tp_account'] == 'PBS DP KidsGo':
						process_list = True
					else:
						process_list = False
				else:
					if results['tp_account'] == 'PBS DP KidsGo':
						process_list = False
					else:
						process_list = True
				if process_list:
					if len(results['associated_images']) >= 2:
						thumb = results['associated_images'][1]['url']
					else:
						thumb = programs_thumb
					program_id = re.compile( '/cove/v1/programs/(.*?)/' ).findall( results['resource_uri'] )[0]
					infoLabels = { "Title": results['title'].encode('utf-8'), "Plot": clean(results['long_description']) }
					u = { 'mode': '0', 'name': urllib.quote_plus( results['title'].encode('utf-8') ), 'program_id': urllib.quote_plus( program_id ) }
					addListItem(label = results['title'], image = thumb, url = u, isFolder = True, infoLabels = infoLabels, fanart = fanart)
	# if ( len(data) ) == 200:
		# u = { 'mode': '1', 'page': str( int( page ) + 1 ) }
		# addListItem(label = '[Next Page (' + str( int( page ) + 2 ) + ')]', image = next_thumb, url = u, isFolder = True, infoLabels = False)
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	if name == settings.getLocalizedString( 30014 ):
		setViewMode("500")
	else:
		setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_history_directory():
	presets = settings.getSetting( "presets_search" )
	if presets != '':
		save = presets.split( " | " )
	else:
		save = []
	cm = []
	for name in save:
		url = 'http://search.espn.go.com/results?searchString=' + name + '&start=0&dims=6'
		name = name.replace('%20', ' ')
		cm = [ ( 'Remove', "XBMC.RunPlugin(%s?mode=5&name=%s&url=%s)" % ( sys.argv[ 0 ], urllib.quote_plus(name), urllib.quote_plus('search') ), ) ]
		cm += [ ( 'Edit', "XBMC.RunPlugin(%s?mode=6&name=%s&url=%s)" % ( sys.argv[ 0 ], urllib.quote_plus(name), urllib.quote_plus('search') ), ) ]
		listitem = xbmcgui.ListItem( label = name, iconImage = "DefaultFolder.png", thumbnailImage = history_thumb )
		listitem.setInfo(type = 'video', infoLabels = { "Title": name, "Plot": name })
		listitem.addContextMenuItems( cm, replaceItems = False )
		u = sys.argv[0] + "?mode=2" + "&name=" + urllib.quote_plus( settings.getLocalizedString( 30005 ) ) + "&url=" + urllib.quote_plus( url ) + "&type=" + urllib.quote_plus( 'history' )
		ok = xbmcplugin.addDirectoryItem( handle = int( sys.argv[1] ), url = u, listitem = listitem, isFolder = True )	
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_networks_directory():
    html = getUrl('http://testtube.com/networks')
    cards = common.parseDOM(html, "ul", attrs={"class": "Cards show-grid"})
    item = common.parseDOM(cards, "li", attrs={"class": "Grid2 Card item"})
    for network in item:
        image = common.parseDOM(network,
                                "img",
                                attrs={"class": "thumbnail"},
                                ret="src")[0]
        url = common.parseDOM(network, "a", ret="href")[0]
        meta = common.parseDOM(network, "div", attrs={"class": "meta"})
        name = common.parseDOM(meta, "strong")[0]
        plot = common.parseDOM(meta, "p")[0].rsplit('\n        ')[1]
        u = {'mode': '5', 'url': url}
        infoLabels = {"Title": name, "Plot": plot}
        addListItem(name, image, u, True, len(item), infoLabels, fanart_bg)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
    setViewMode("515")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Exemple #23
0
def build_search_directory():
	page = 1
	checking = True
	string = common.getUserInput(settings.getLocalizedString( 30007 ), "")
	if not string:
		build_main_directory()
		return
	if settings.getSetting('playall') == 'true':
		playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
		playlist.clear()
		u = { 'mode': '4' }
		infoLabels = { "Title": '* ' + settings.getLocalizedString( 30030 ) + ' *', "Plot": settings.getLocalizedString( 30031 ) }
		addListItem('* ' + settings.getLocalizedString( 30030 ) + ' *', icon, u, False, 0, infoLabels, fanart)
	while checking:
		url = 'http://www.tmz.com/search/json/videos/' + urllib.quote(string) + '/' + str(page) + '.json'
		data = getPage(url)
		if data['error'] == 'HTTP Error 404: Not Found':
			dialog = xbmcgui.Dialog()
			ok = dialog.ok( plugin , settings.getLocalizedString( 30009 ) + '\n' + settings.getLocalizedString( 30010 ) )
			return
		elif data['error'] != None:
			text = getUrl( url, True )
		else:
			text = data['content']
		jdata = json.loads(text)
		total = int(jdata['total'])
		if ((total - page * 25) > 0):
			page = page + 1
		else:
			checking = False
		for results in jdata['results']:
			title = results['title'].encode('ascii', 'ignore')
			videoUrl = results['URL'].replace("\\", "")
			thumb = results['thumbnailUrl'].replace("\\", "") + '/width/490/height/266/type/3'
			infoLabels = { "Title": title, "Plot": title }
			u = { 'mode': '3', 'name': title, 'url': videoUrl, 'thumb': thumb }
			addListItem(label = title, image = thumb, url = u, isFolder = False, totalItems = total, infoLabels = infoLabels, fanart = fanart)
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
Exemple #24
0
def build_video_directory( name ):
	data = getUrl( 'http://www.tmz.com/videos/', True )
	textarea = '[{' + re.compile('{ name: \'' + name.upper() + '\',( )?\n         allInitialJson: {(.+?)},\n         (slug|noPaging)?', re.DOTALL).findall( data )[0][1].replace('\n', '').replace('results:','"results":') + '}]'
	query = json.loads(textarea)[0]["results"]
	totalItems = len(query)
	if settings.getSetting('playall') == 'true':
		playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
		playlist.clear()
		u = { 'mode': '4' }
		infoLabels = { "Title": '* ' + settings.getLocalizedString( 30030 ) + ' *', "Plot": settings.getLocalizedString( 30031 ) }
		addListItem('* ' + settings.getLocalizedString( 30030 ) + ' *', icon, u, False, 0, infoLabels, fanart)
	for videos in query:
		title = clean(videos['title'].replace("\\", "")).encode('ascii', 'ignore')
		duration = videos['duration'].replace("\\", "")
		videoUrl = videos['videoUrl'].replace("\\", "")
		thumb = videos['thumbnailUrl'].replace("\\", "") + '/width/490/height/266/type/3'
		try:
			if name == settings.getLocalizedString( 30003 ):
				time = title.rsplit(': ')[1].rsplit(' ')[1].rsplit('/')
				date = '20' + time[2] + '.' + time[0].zfill(2)  + '.' + time[1]
			else:
				date = videos['activeDate'].rsplit('T')[0]
		except:
			date = '0000.00.00'
		if videoUrl.find('http://cdnbakmi.kaltura.com') == -1:
			low_id =  videoUrl.split('_')[0].split('/')[-1:][0] + '_' + videoUrl.split('_')[1]
			high_id = videoUrl.split('_')[0].split('/')[-1:][0] + '_' + videoUrl.split('_')[1] + '/flavorId/0_' + videoUrl.split('_')[3]
		else:
			low_id = videoUrl.split('/')[9]
			high_id = videoUrl.split('/')[9] + '/flavorId/' + videoUrl.split('/')[11]
		if settings.getSetting("quality") == '0':
			url = 'http://cdnapi.kaltura.com/p/' + thumb.split('/')[4] + '/sp/' + thumb.split('/')[6] + '/playManifest/entryId/' + low_id
		else:
			url = 'http://cdnapi.kaltura.com/p/' + thumb.split('/')[4] + '/sp/' + thumb.split('/')[6] + '/playManifest/entryId/' + high_id
		infoLabels = { "Title": title, "Plot": title, "Duration": str(int(duration)/60), "aired": str(date) }
		u = { 'mode': '1', 'name': title, 'url': url, 'studio': name, 'thumb': thumb }
		addListItem(label = title, image = thumb, url = u, isFolder = False, totalItems = totalItems, infoLabels = infoLabels, fanart = fanart, duration = duration)
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_main_directory(url):
	path = url
	html = getUrl(url)
	shows = common.parseDOM(html, "ul", attrs = { "id": "shows" })[0]
	url_name = re.compile('<h3><a href="(.+?)">(.+?)</a></h3>').findall(shows)
	image = re.compile('class="thumbnail"><img src="(.+?)" /></a>').findall(shows)
	plot = common.parseDOM(shows, "p", attrs = { "class": "description" })
	if settings.getSetting('folder') == 'true' and settings.getSetting( 'downloadPath' ) and path == 'http://revision3.com/shows/':
		u = { 'mode': None, 'url': settings.getSetting("downloadPath") }
		infoLabels = { "Title": settings.getLocalizedString( 30012 ), "Plot": settings.getLocalizedString( 30022 ) }
		addListItem('[ ' + settings.getLocalizedString( 30012 ) + ' ]', downloads_thumb, u, True, infoLabels, fanart_bg)
	if path == 'http://revision3.com/shows/':
		u = { 'mode': '1', 'name': urllib.quote_plus(settings.getLocalizedString( 30013 )), 'url': urllib.quote_plus('http://revision3.com/episodes/page?&hideArrows=1&type=recent&page=1') }
		infoLabels = { "Title": settings.getLocalizedString( 30013 ), "Plot": settings.getLocalizedString( 30018 ) }
		addListItem('[ ' + settings.getLocalizedString( 30013 ) + ' ]', current_thumb, u, True, infoLabels, fanart_bg)
		u = { 'mode': '3', 'url': urllib.quote_plus('http://revision3.com/shows/archive') }
		infoLabels = { "Title": settings.getLocalizedString( 30014 ), "Plot": settings.getLocalizedString( 30019 ) }
		addListItem('[ ' + settings.getLocalizedString( 30014 ) + ' ]', old_thumb, u, True, infoLabels, fanart_bg)
		u = { 'mode': '4', 'url': urllib.quote_plus('search') }
		infoLabels = { "Title": settings.getLocalizedString( 30015 ), "Plot": settings.getLocalizedString( 30020 ) }
		addListItem('[ ' + settings.getLocalizedString( 30015 ) + ' ]', search_thumb, u, True, infoLabels, fanart_bg)
	count = 0
	for url, name in url_name:
		fanart = url.replace('/','')
		if not settings.getSetting(fanart):
			fanart = fanart_bg
		else:
			fanart = settings.getSetting(fanart)
		url = 'http://revision3.com' + url + '/episodes'
		u = { 'mode': '1', 'name': urllib.quote_plus(name), 'url': urllib.quote_plus(url) }
		infoLabels = { "Title": name, "Plot": clean(plot[count]) }
		addListItem(name, image[count].replace('160x160','200x200'), u, True, infoLabels, fanart)
		count += 1
	xbmcplugin.addSortMethod( handle = int(sys.argv[ 1 ]), sortMethod = xbmcplugin.SORT_METHOD_UNSORTED )
	setViewMode("515")
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_networks_sub_directory(url, offset):
	saveurl = url
	html = getUrl('http://revision3.com' + url + '/episodePage?limit=25&offset=' + str(offset * 25))
	networkItem = common.parseDOM(html, "li", attrs = { "class": "networkItem" })
	if len(networkItem) == 0:
		dialog = xbmcgui.Dialog()
		ok = dialog.ok( plugin , settings.getLocalizedString( 30026 ) + ' this page.' )
		return
	if settings.getSetting('download') == '' or settings.getSetting('download') == 'false':
		if settings.getSetting('playall') == 'true':
			playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
			playlist.clear()
			u = { 'mode': '6' }
			infoLabels = { "Title": settings.getLocalizedString( 30030 ), "Plot": settings.getLocalizedString( 30031 ) }
			addListItem('* ' + settings.getLocalizedString( 30030 ) + ' *', play_thumb, u, True, 0, infoLabels, fanart_bg)
	for item in networkItem:
		url = common.parseDOM(item, "a", attrs = { "class": "playlistPlay clear" }, ret = "href")[0][1:]
		thumbnail = common.parseDOM(item, "div", attrs = { "class": "thumbnail" })
		image = common.parseDOM(thumbnail, "img", ret = "src")[0].replace('small.thumb.jpg','medium.thumb.jpg')
		meta = common.parseDOM(item, "div", attrs = { "class": "meta" })
		name = common.parseDOM(meta, "div", attrs = { "class": "title" })[0]
		studio = common.parseDOM(meta, "div", attrs = { "class": "showtitle" })[0]
		plot = common.parseDOM(meta, "div", attrs = { "class": "itemPreview" })[0].encode('ascii', 'ignore')
		infoLabels = { "Title": name, "Studio": studio, "Plot": plot }
		u = { 'mode': '2', 'name': name, 'url': url, 'plot': plot, 'studio': studio, 'episode': '0', 'thumb': image, 'date': '0000-00-00' }
		addListItem(name, image, u, False, len(networkItem), infoLabels, fanart_bg)
	if len(networkItem) == 25:
		u = { 'mode': '5', 'url': saveurl, 'offset': offset + 1 }
		infoLabels = { "Title": settings.getLocalizedString( 30016 ), "Plot": settings.getLocalizedString( 30016 ) }
		addListItem(settings.getLocalizedString( 30016 ) + ' (' + str( offset + 2 ) + ')', next_thumb, u, True, 0, infoLabels, fanart_bg)
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_EPISODE )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_STUDIO )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME )
	setViewMode("503")
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_networks_sub_directory(url, offset):
    saveurl = url
    html = getUrl('http://testtube.com' + url +
                  '/episodePage?limit=25&offset=' + str(offset * 25))
    networkItem = common.parseDOM(html, "li", attrs={"class": "networkItem"})
    if len(networkItem) == 0:
        dialog = xbmcgui.Dialog()
        ok = dialog.ok(plugin,
                       settings.getLocalizedString(30026) + ' this page.')
        return
    if settings.getSetting('download') == '' or settings.getSetting(
            'download') == 'false':
        if settings.getSetting('playall') == 'true':
            playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
            playlist.clear()
            u = {'mode': '6'}
            infoLabels = {
                "Title": settings.getLocalizedString(30030),
                "Plot": settings.getLocalizedString(30031)
            }
            addListItem('* ' + settings.getLocalizedString(30030) + ' *',
                        play_thumb, u, True, 0, infoLabels, fanart_bg)
    for item in networkItem:
        url = common.parseDOM(item,
                              "a",
                              attrs={"class": "playlistPlay clear"},
                              ret="href")[0][1:]
        thumbnail = common.parseDOM(item, "div", attrs={"class": "thumbnail"})
        image = common.parseDOM(thumbnail, "img",
                                ret="src")[0].replace('small.thumb.jpg',
                                                      'medium.thumb.jpg')
        meta = common.parseDOM(item, "div", attrs={"class": "meta"})
        name = common.parseDOM(meta, "div",
                               attrs={"class":
                                      "title"})[0].encode('ascii', 'ignore')
        studio = common.parseDOM(meta, "div", attrs={"class": "showtitle"})[0]
        plot = common.parseDOM(meta, "div",
                               attrs={"class": "itemPreview"
                                      })[0].encode('ascii', 'ignore')
        infoLabels = {"Title": name, "Studio": studio, "Plot": plot}
        u = {
            'mode': '2',
            'name': name,
            'url': url,
            'plot': plot,
            'studio': studio,
            'episode': '0',
            'thumb': image,
            'date': '0000-00-00'
        }
        addListItem(name, image, u, False, len(networkItem), infoLabels,
                    fanart_bg)
    if len(networkItem) == 25:
        u = {'mode': '5', 'url': saveurl, 'offset': offset + 1}
        infoLabels = {
            "Title": settings.getLocalizedString(30016),
            "Plot": settings.getLocalizedString(30016)
        }
        addListItem(
            settings.getLocalizedString(30016) + ' (' + str(offset + 2) + ')',
            next_thumb, u, True, 0, infoLabels, fanart_bg)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_EPISODE)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_STUDIO)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
    setViewMode("503")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_main_directory(url):
    data = json.loads(getUrl(url))['shows']
    if settings.getSetting('folder') == 'true' and settings.getSetting(
            'downloadPath') and url == BASE + 'getShows' + KEY:
        u = {'mode': None, 'url': settings.getSetting('downloadPath')}
        infoLabels = {
            "Title": settings.getLocalizedString(30012),
            "Plot": settings.getLocalizedString(30022)
        }
        addListItem('[ ' + settings.getLocalizedString(30012) + ' ]',
                    downloads_thumb, u, True, 0, infoLabels, fanart_bg)
    if url == BASE + 'getShows' + KEY:
        #Featured
        u = {
            'mode': '1',
            'name': settings.getLocalizedString(30023),
            'url': BASE + 'getEpisodes' + KEY + '&grouping=featured',
            'slug': 'None'
        }
        infoLabels = {
            "Title": settings.getLocalizedString(30023),
            "Plot": settings.getLocalizedString(30024)
        }
        addListItem('[ ' + settings.getLocalizedString(30023) + ' ]',
                    featured_thumb, u, True, 0, infoLabels, fanart_bg)
        #Most Recent
        u = {
            'mode': '1',
            'name': settings.getLocalizedString(30013),
            'url': BASE + 'getEpisodes' + KEY + '&grouping=latest',
            'slug': 'None'
        }
        infoLabels = {
            "Title": settings.getLocalizedString(30013),
            "Plot": settings.getLocalizedString(30018)
        }
        addListItem('[ ' + settings.getLocalizedString(30013) + ' ]',
                    recent_thumb, u, True, 0, infoLabels, fanart_bg)
        # #Networks
        # u = { 'mode': '4' }
        # infoLabels = { "Title": settings.getLocalizedString( 30027 ), "Plot": settings.getLocalizedString( 30028 ) }
        # addListItem('[ ' + settings.getLocalizedString( 30027 ) + ' ]', networks_thumb, u, True, 0, infoLabels, fanart_bg)
        # #Archived Shows
        # u = { 'mode': '3', 'url': BASE + 'getShows' + KEY + '&grouping=archived' }
        # infoLabels = { "Title": settings.getLocalizedString( 30014 ), "Plot": settings.getLocalizedString( 30019 ) }
        # addListItem('[ ' + settings.getLocalizedString( 30014 ) + ' ]', archived_thumb, u, True, 0, infoLabels, fanart_bg)
    daily_data = {}
    for daily_show in data:
        if daily_show['parent_id'] != None:
            name = daily_show['name']
            thumb = daily_show['images']['logo'].replace('\\', '')
            url = BASE + 'getEpisodes' + KEY + '&show_id=' + daily_show['id']
            daily_data[daily_show['parent_id']] = {
                'name': name,
                'url': url,
                'plot': daily_show['summary'],
                'thumb': thumb
            }
    totalItems = len(data) - len(daily_data)
    for show in data:
        if show['parent_id'] == None:
            if show['id'] in daily_data:
                daily_info = daily_data[show['id']]
            else:
                daily_info = 'None'
            slug = show['slug']
            if not settings.getSetting(slug):
                fanart = fanart_bg
            else:
                fanart = settings.getSetting(slug)
            name = show['name']
            #fanart = show['images']['hero'].replace('\\','')
            url = BASE + 'getEpisodes' + KEY + '&show_id=' + show['id']
            u = {
                'mode': '1',
                'name': name,
                'url': url,
                'slug': slug,
                'daily_info': daily_info
            }
            infoLabels = {"Title": name, "Plot": show['summary']}
            addListItem(name, show['images']['logo'].replace('\\', ''), u,
                        True, totalItems, infoLabels, fanart)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
    setViewMode("515")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def find_videos( name, program_id, topic, page ):
	if settings.getSetting("video") == '0':
		type = ['MP4 800k', 'Legacy KIDS encoding', HIGH]
	else:
		type = [HIGH, 'MP4 800k', 'Legacy KIDS encoding']
	start = str( 200 * page )
	url = 'None'
	backup_url = None
	if topic == 'True':
		program_id = 'program_id'
		data = cove.videos.filter(fields='associated_images,mediafiles,categories',filter_categories__name=name,order_by='-airdate',filter_availability_status='Available',limit_start=start,exclude_type__in='Chapter,Promotion')
	elif topic == 'False':
		data = cove.videos.filter(fields='associated_images,mediafiles',filter_tp_media_object_id=program_id,limit_start=start)
		print "PBS - Video ID: " + program_id
		if len(data) == 0:
			dialog = xbmcgui.Dialog()
			ok = dialog.ok( plugin , settings.getLocalizedString( 30009 ) + '\n' + 'http://video.pbs.org/video/' + program_id )
			return
	elif topic == 'search':
		data = cove.videos.filter(fields='associated_images,mediafiles',filter_title__contains=name,order_by='-airdate',filter_availability_status='Available',limit_start=start)
		if len(data) == 0:
			data = cove.videos.filter(fields='associated_images,mediafiles',filter_title__contains=string.capwords(name),order_by='-airdate',filter_availability_status='Available',limit_start=start)
	else:
		topic = 'topic'
		data = cove.videos.filter(fields='associated_images,mediafiles',filter_program=program_id,order_by='-airdate',filter_availability_status='Available',limit_start=start,exclude_type__in='Chapter,Promotion')
		if len(data) <= 1:
			data = cove.videos.filter(fields='associated_images,mediafiles',filter_program=program_id,order_by='-airdate',filter_availability_status='Available',limit_start=start)
	for results in data:
		if len(results['mediafiles']) != 0:
			encoding = {}
			if results['associated_images'] != None and len(results['associated_images']) > 0:
				thumb = results['associated_images'][0]['url']
			else:
				thumb = 'None'
			for videos in results['mediafiles']:
				encoding[clean_type(videos['video_encoding']['name'])] = { 'url': videos['video_data_url'], 'backup_url': videos['video_download_url'] }
			cycle = 0
			while cycle <= 2:
				if type[cycle] in encoding:
					url = str(encoding[type[cycle]]['url'])
					backup_url = str(encoding[type[cycle]]['backup_url'])
					break
				cycle += 1
			if cycle == 3:
				url = str(encoding.items()[0][1]['url'])
				backup_url = str(encoding.items()[0][1]['backup_url'])
			infoLabels = { "Title": results['title'].encode('utf-8'), "Director": "PBS", "Studio": name, "Plot": results['long_description'].encode('utf-8'), "Aired": results['airdate'].rsplit(' ')[0], "Duration": str((int(results['mediafiles'][0]['length_mseconds'])/1000)/60) }
			u = { 'mode': '5', 'name': results['title'].encode('utf-8'), 'url': url, 'thumb': thumb, 'plot': results['long_description'].encode('utf-8'), 'studio': name, 'backup_url': backup_url }
			addListItem(label = results['title'].encode('utf-8'), image = thumb, url = u, isFolder = False, infoLabels = infoLabels, fanart = fanart, duration = str(int(results['mediafiles'][0]['length_mseconds'])/1000))
	if topic == 'False':
		play_video( results['title'].encode('utf-8'), url, thumb, results['long_description'].encode('utf-8'), name.encode('utf-8'), None, backup_url )
		return
	if len(data) == 0:
		dialog = xbmcgui.Dialog()
		ok = dialog.ok( plugin , settings.getLocalizedString( 30012 ) + ' ' + name + '.' )
		return
	if ( len(data) ) == 200:
		u = { 'mode': '0', 'name': name, 'program_id': program_id, 'topic': topic, 'page': str( int( page ) + 1 ) }
		addListItem(label = '[Next Page (' + str( int( page ) + 2 ) + ')]', image = next_thumb, url = u, isFolder = True, infoLabels = False, fanart = fanart)
	if topic == 'search':
		build_programs_directory( name, 0 )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LABEL )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
Exemple #30
0
def build_features_list(save_page):
    metaget = metahandlers.MetaData()
    form_data = {'page': save_page}
    data = getUrl('http://www.traileraddict.com/ajax/features_home.php',
                  form_data=form_data)
    movie_info = re.compile(
        'class="featured_box[ sp rb]*">(.+?)</a>[\\r\\n\\t]+</div>',
        re.DOTALL).findall(data)
    for movie in movie_info:
        url_thumb_x_title = re.compile(
            '<a href="(.+?)" class="movie_img" title="(.+?)"><img alt=".+?" src="(.+?)" />'
        ).findall(movie)
        totalItems = len(url_thumb_x_title)
        for url, title, thumb in url_thumb_x_title:
            title = title.rsplit(' - ')
            name1 = clean(title[0])
            if len(title) > 1:
                name2 = clean(title[0]) + ' (' + clean(title[1]) + ')'
            else:
                name2 = clean(title[0])
            url = 'http://www.traileraddict.com' + url
            thumb = 'http:' + thumb
            cm = []
            run = sys.argv[0] + '?' + urllib.urlencode({
                'mode': '5',
                'name': name2,
                'url': url,
                'download': 'True'
            })
            cm.append((settings.getLocalizedString(30059),
                       "XBMC.RunPlugin(%s)" % run))
            cm.append((settings.getLocalizedString(
                30014
            ), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)"
                       % name1))
            cm.append(('Show Information', 'XBMC.Action(Info)'))
            u = {'mode': '5', 'name': name2, 'url': url}

            #Try to clean up the name as best we can before grabbing meta data
            scrape_name = name1.lower().replace(
                'theatrical trailer',
                '').replace('feature trailer',
                            '').replace('international trailer', '').replace(
                                'final trailer',
                                '').replace('red band', '').replace(
                                    'feature red band',
                                    '').replace('international red band ',
                                                '').replace('trailer', '')
            meta = metaget.get_meta('movie', scrape_name)
            meta['title'] = name1
            meta['trailer'] = ''

            addListItem(label=name1,
                        image=thumb,
                        url=u,
                        isFolder=False,
                        totalItems=totalItems,
                        infoLabels=meta,
                        cm=cm)
    if save_page < 94:
        u = {'mode': '6', 'page': str(int(save_page) + 1)}
        addListItem(label='[Next Page (' + str(int(save_page) + 1) + ')]',
                    image=next_thumb,
                    url=u,
                    isFolder=True,
                    totalItems=0,
                    infoLabels=False)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_NONE)
    setViewMode("500", "movies")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def find_trailers( url, name, page, library ):
	save_name = name
	save_page = page
	data = getUrl( url ).decode('ascii', 'ignore')
	link_thumb = re.compile( '<a href="(.+?)"><img src="(.+?)" name="thumb' ).findall( data )
	thumbs = re.compile( 'img src="/psize\.php\?dir=(.+?)" style' ).findall( data )
	if len( thumbs ) == 0:
		thumb = "DefaultVideo.png"
	else:
		thumb = 'http://www.traileraddict.com/' + thumbs[0]
	title = re.compile( '<div class="abstract"><h2><a href="(.+?)">(.+?)</a></h2><br />', re.DOTALL ).findall( data )
	trailers = re.compile( '<dl class="dropdown">(.+?)</dl>', re.DOTALL ).findall( data )
	if len(title) == 0 and len(trailers) == 0:
		list = common.parseDOM(data, "div", attrs = { "class": "info" })
		header = common.parseDOM(data, "div", attrs = { "class": "trailerheader" })
		nexturl = common.parseDOM(header, "a", attrs = { "title": "Next Page" }, ret = "href")
		totalItems = len(list)
		if totalItems == 0:
			dialog = xbmcgui.Dialog()
			ok = dialog.ok(plugin, settings.getLocalizedString( 30012 ))
			ok = dialog.ok(plugin, settings.getLocalizedString( 30051 ))
			buggalo.addExtraData('url', url)
			buggalo.addExtraData('name', name)
			raise Exception('find_trailers Error A')
			return
		for video in list:
			h2 = common.parseDOM(video, "h2")
			title = common.parseDOM(h2, "a")[0]
			url = 'http://www.traileraddict.com' + common.parseDOM(h2, "a", ret = "href")[0]
			thumb = 'http://www.traileraddict.com' + common.parseDOM(video, "img", attrs = { "class": "dimmer" }, ret = "src")[0].replace('-t.jpg','.jpg')
			#infoLabels = { "Title": title, "Plot": save_name + ' (' + clean( title ) + ')' }
			cm = []
			run = sys.argv[0] + '?' + urllib.urlencode({ 'mode': '5', 'name': save_name + ' (' + clean( title ) + ')', 'url': url, 'download': 'True' })
			cm.append( (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run) )
			cm.append( (settings.getLocalizedString(30014), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)" % save_name) )
			u = { 'mode': '5', 'name': save_name + ' (' + clean( title ) + ')', 'url': url }
			addListItem(label = clean( title ), image = thumb, url = u, isFolder = False, totalItems = totalItems, infoLabels = False, cm = cm)
		if len(nexturl) > 0:
			url = 'http://www.traileraddict.com' + nexturl[0]
			u = { 'mode': '4', 'name': save_name, 'url': url, 'page': str( int( save_page ) + 1 ) }
			addListItem(label = '[Next Page (' + str( int( save_page ) + 2 ) + ')]', image = next_thumb, url = u, isFolder = True, totalItems = 0, infoLabels = False)
		xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
		setViewMode("502", "movies")
		xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
		return
	item_count = 0
	if len( trailers ) > 0:
		check1 = re.compile( '<a href="(.+?)"><img src="\/images\/usr\/arrow\.png" border="0" style="float:right;" \/>(.+?)</a>' ).findall( trailers[0] )
		check2 = re.compile( '<a href="(.+?)"( style="(.*?)")?>(.+?)<br />' ).findall( trailers[0] )
		totalItems = len( check1 )
		totalItems2 = len( check2 )
		if totalItems > 0:
			url_title = check1
			if library == True:
				return url_title[0][0]
			for url, title in url_title:
				url = 'http://www.traileraddict.com' + url
				cm = []
				run = sys.argv[0] + '?' + urllib.urlencode({ 'mode': '5', 'name': save_name + ' (' + clean( title ) + ')', 'url': url, 'download': 'True' })
				cm.append( (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run) )
				cm.append( (settings.getLocalizedString(30014), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)" % save_name) )
				infoLabels = { "Title": title, "Plot": save_name + ' (' + clean( title ) + ')' }
				u = { 'mode': '5', 'name': save_name + ' (' + clean( title ) + ')', 'url': url }
				addListItem(label = clean( title ), image = thumb, url = u, isFolder = False, totalItems = totalItems, infoLabels = False, cm = cm)
			xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
			setViewMode("502", "movies")
			xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
		elif totalItems2 > 0:
			url_title = check2
			if library == True:
				return url_title[0][0]
			for url, trash1, trash2, title in url_title:
				url = 'http://www.traileraddict.com' + url
				#infoLabels = { "Title": title, "Plot": save_name + ' (' + clean( title ) + ')' }
				cm = []
				run = sys.argv[0] + '?' + urllib.urlencode({ 'mode': '5', 'name': save_name.decode('ascii', 'ignore') + ' (' + clean( title ) + ')', 'url': url, 'download': 'True' })
				cm.append( (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run) )
				cm.append( (settings.getLocalizedString(30014), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)" % save_name.decode('ascii', 'ignore')) )
				u = { 'mode': '5', 'name': save_name.decode('ascii', 'ignore') + ' (' + clean( title ) + ')', 'url': url }
				addListItem(label = clean( title ), image = thumb, url = u, isFolder = False, totalItems = totalItems2, infoLabels = False, cm = cm)
			xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
			setViewMode("502", "movies")
			xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
		else:
			# dia = xbmcgui.Dialog()
			# ok = dia.ok(plugin, settings.getLocalizedString(30006) )
			# ok = dia.ok(plugin, settings.getLocalizedString( 30051 ))
			# buggalo.addExtraData('url', url)
			# buggalo.addExtraData('name', save_name)
			# raise Exception('find_trailers Error 2')
			# xbmc.executebuiltin('Notification('+plugin+',Only video clips were found!,5000,'+icon_thumb+')')
			list = common.parseDOM(data, "div", attrs = { "class": "info" })
			header = common.parseDOM(data, "div", attrs = { "class": "trailerheader" })
			nexturl = common.parseDOM(header, "a", attrs = { "title": "Next Page" }, ret = "href")
			totalItems = len(list)
			if totalItems == 0:
				dialog = xbmcgui.Dialog()
				ok = dialog.ok(plugin, settings.getLocalizedString( 30012 ))
				ok = dialog.ok(plugin, settings.getLocalizedString( 30051 ))
				buggalo.addExtraData('url', url)
				buggalo.addExtraData('name', name)
				raise Exception('find_trailers Error B')
				return
			for video in list:
				h2 = common.parseDOM(video, "h2")
				title = common.parseDOM(h2, "a")[0]
				url = 'http://www.traileraddict.com' + common.parseDOM(h2, "a", ret = "href")[0]
				thumb = 'http://www.traileraddict.com' + common.parseDOM(video, "img", attrs = { "class": "dimmer" }, ret = "src")[0].replace('-t.jpg','.jpg')
				#infoLabels = { "Title": title, "Plot": save_name + ' (' + clean( title ) + ')' }
				cm = []
				run = sys.argv[0] + '?' + urllib.urlencode({ 'mode': '5', 'name': save_name + ' (' + clean( title ) + ')', 'url': url, 'download': 'True' })
				cm.append( (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run) )
				cm.append( (settings.getLocalizedString(30014), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)" % save_name) )
				u = { 'mode': '5', 'name': save_name + ' (' + clean( title ) + ')', 'url': url }
				addListItem(label = clean( title ), image = thumb, url = u, isFolder = False, totalItems = totalItems, infoLabels = False, cm = cm)
			if len(nexturl) > 0:
				url = 'http://www.traileraddict.com' + nexturl[0]
				u = { 'mode': '4', 'name': save_name, 'url': url, 'page': str( int( save_page ) + 1 ) }
				addListItem(label = '[Next Page (' + str( int( save_page ) + 2 ) + ')]', image = next_thumb, url = u, isFolder = True, totalItems = 0, infoLabels = False)
			xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
			setViewMode("502", "movies")
			xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
	else:
		totalItems = len(link_thumb)
		for url, thumb2 in link_thumb:
			if clean( title[item_count][1] ).find( 'Trailer' ) > 0: 
				url = 'http://www.traileraddict.com' + url
				cm = []
				run = sys.argv[0] + '?' + urllib.urlencode({ 'mode': '5', 'name': save_name + ' (' + clean( title[item_count][1] ) + ')', 'url': url, 'download': 'True' })
				cm.append( (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run) )
				cm.append( (settings.getLocalizedString(30014), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)" % save_name) )
				infoLabels = { "Title": title[item_count][1], "Plot": save_name + ' (' + clean( title[item_count][1] ) + ')' }
				u = { 'mode': '5', 'name': save_name + ' (' + clean( title[item_count][1] ) + ')', 'url': url }
				addListItem(label = clean( title[item_count][1] ), image = thumb, url = u, isFolder = False, totalItems = totalItems, infoLabels = False, cm = cm)
			item_count = item_count + 1
		xbmcplugin.addSortMethod( handle = int( sys.argv[1] ), sortMethod = xbmcplugin.SORT_METHOD_NONE )
		setViewMode("502", "movies")
		xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
Exemple #32
0
def getMovieLibrary():
    try:
        if common.getXBMCVersion() >= 12.0:
            properties = [
                'year', 'imdbnumber', 'thumbnail', 'plot', 'dateadded',
                'rating'
            ]
        else:
            properties = ['year', 'imdbnumber', 'thumbnail', 'plot', 'rating']
    except:
        properties = ['year', 'imdbnumber', 'thumbnail', 'plot', 'rating']
    rpccmd = json.dumps({
        'jsonrpc': '2.0',
        'method': 'VideoLibrary.GetMovies',
        'params': {
            'properties': properties,
            "sort": {
                "order": "ascending",
                "method": "label",
                "ignorearticle": True
            }
        },
        "id": "libMovies"
    })
    result = xbmc.executeJSONRPC(rpccmd)
    result = json.loads(result)
    if 'error' in result:
        dialog = xbmcgui.Dialog()
        ok = dialog.ok(plugin, settings.getLocalizedString(30018))
        build_main_directory()
        return
    if (result['result']['limits']['total'] == 0):
        dialog = xbmcgui.Dialog()
        ok = dialog.ok(plugin, settings.getLocalizedString(30016))
        build_main_directory()
        return
    totalItems = len(result['result']['movies'])
    for movie in result['result']['movies']:
        label = movie['label'].encode('ascii', 'ignore')
        plot = movie['plot'].encode('ascii', 'ignore')
        if 'dateadded' in movie:
            day = movie['dateadded'].split(' ')[0].split('-')
            date = day[2] + '.' + day[1] + '.' + day[0]
        else:
            date = '0000.00.00'
        thumbnail = movie['thumbnail']
        year = movie['thumbnail']
        url = movie['imdbnumber'].rsplit('tt')
        if len(url) == 2:
            url = url[1]
        else:
            url = '1'
        listitem = xbmcgui.ListItem(label=label,
                                    iconImage=thumbnail,
                                    thumbnailImage=thumbnail)
        u = {'mode': '8', 'name': label, 'url': url}
        cm = []
        run = sys.argv[0] + '?' + urllib.urlencode({
            'mode': '8',
            'name': label,
            'url': url,
            'download': 'True'
        })
        cm.append(
            (settings.getLocalizedString(30059), "XBMC.RunPlugin(%s)" % run))
        infoLabels = {
            "Title": label,
            "Plot": plot,
            "date": date,
            "Year": movie['year'],
            "Rating": movie['rating']
        }
        addListItem(label=label,
                    image=thumbnail,
                    url=u,
                    isFolder=False,
                    totalItems=totalItems,
                    infoLabels=infoLabels,
                    cm=cm)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_TITLE)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_DATE)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_VIDEO_YEAR)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RATING)
    setViewMode("500", "movies")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_sub_directory(url, thumb):
	saveurl = url
	html = getUrl('http://espn.go.com/video/')
	html = html.decode('UTF-8','ignore') #Swedemon/Mrdally204 Change 2015-08-31
	menu = common.parseDOM(html, "div", attrs = { "id": url })
	channel = common.parseDOM(menu, "li", attrs = { "class": "channel" })
	title = common.parseDOM(channel, "a")
	id = common.parseDOM(menu, "li", attrs = { "class": "channel" }, ret = "id")
	item_count = 0
	if saveurl == 'menu2949050':
		shows=[
			( settings.getLocalizedString( 30009 ), 'sportscenter' ),
			( settings.getLocalizedString( 30010 ), 'first%20take' ),
			( settings.getLocalizedString( 30011 ), 'pti' ),
			( settings.getLocalizedString( 30012 ), 'ath' ),
			( 'Mike and Mike', 'mike%20and%20mike' ),
			( 'Outside the Lines', 'outside%the%lines' ),
			( 'E:60', 'e:60' ),
			( 'Olbermann', 'olbermann' ),
			( 'SC Featured', 'sc%20featured' ),
			( 'Wider World of Sports', 'wider%20world%20of%20sports' ),
			( 'This is Sportscenter', 'this%20is%20sportscenter' ),
			( 'Grantland', 'grantland' )
			]	
		for name, search in shows:
			url = 'http://search.espn.go.com/results?searchString=' + search + '&start=0&dims=6'
			u = { 'mode': '2', 'name': settings.getLocalizedString( 30005 ), 'url': url, 'type': 'history' }
			infoLabels = { "Title": name, "Plot": name }
			addListItem(label = name, image = tvshows_thumb, url = u, isFolder = True, infoLabels = infoLabels)
	if saveurl == 'menu2949049':
		categories=[
			( 'The Latest', 'the%20latest' ),
			( 'NFL', 'nfl' ),
			( 'NBA', 'nba' ),
			( 'NHL', 'nhl' ),
			( 'MLB', 'mlb' ),
			( 'Tennis', 'tennis' ),
			( 'NASCAR', 'nascar' ),
			( 'Golf', 'golf' ),
			( 'Boxing', 'boxing' ),
			( 'MMA', 'mma' ),
			( 'Action Sports', 'action%20sports' ),
			( 'College Football', 'college%20football' ),
			( 'College Hoops', 'college%20hoops' ),
			( 'ESPN FC', 'espn%20fc' ),
			( 'ESPNcricinfo', 'espncricinfo' ),
			( 'ESPNU', 'espnu' ),
			( 'Fantasy', 'fantasy' ),
			( 'Racing', 'racing' ),
			( 'Sport Science', 'sport%20science' ),
			( "Women's Basketball", "women's%20basketball" )
			]	
		for name, search in categories:
			url = 'http://search.espn.go.com/results?searchString=' + search + '&start=0&dims=6'
			u = { 'mode': '2', 'name': settings.getLocalizedString( 30005 ), 'url': url, 'type': 'history' }
			infoLabels = { "Title": name, "Plot": name }
			addListItem(label = name, image = tvshows_thumb, url = u, isFolder = True, infoLabels = infoLabels)
	for name in title:
		name = name.rsplit('(')[0]
		url = 'http://espn.go.com/video/format/libraryPlaylist?categoryid=' + id[item_count].replace('channel','')
		u = { 'mode': '2', 'name': name, 'url': url, 'type': 'null' }
		infoLabels = { "Title": name, "Plot": name }
		addListItem(label = name, image = thumb, url = u, isFolder = True, infoLabels = infoLabels)
		item_count += 1	
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def build_sub_directory(url, name, slug, offset, daily_info):
	if slug == None:
		dialog = xbmcgui.Dialog()
		ok = dialog.ok( plugin , settings.getLocalizedString( 30029 ) )
		build_main_directory(BASE + 'getShows' + KEY)
		return
	saveurl = url
	data = json.loads(getUrl(url + '&offset=' + str(offset * 25)))
	if len(data['episodes']) == 0:
		dialog = xbmcgui.Dialog()
		ok = dialog.ok( plugin , settings.getLocalizedString( 30026 ) + ' ' + name + '.' )
		return
	if slug != 'None':
		try:
			downloads = 'http://revision3.com/' + slug + '/' + slug + '_downloads'
			fresult = getPage(downloads)['content']
			match = re.compile( '<a href="(.+?)" target="_blank">1920x1200</a>' ).findall(fresult)
			if len(match) > 1:
				fanart = match[1]
			else:
				fanart = match[0]
			settings.setSetting(slug, fanart)
		except:
			fanart = 'http://videos.revision3.com/revision3/images/shows/%s/%s_hero.jpg' % (slug, slug)
			if getPage(fanart)['error'] == 'HTTP Error 404: Not Found':
				fanart = fanart_bg
				settings.setSetting(slug, fanart)
			else:
				settings.setSetting(slug, fanart)
	else:
		fanart = fanart_bg
	if daily_info != 'None' and settings.getSetting('daily') == 'true':
		daily_info = ast.literal_eval(daily_info)
		u = { 'mode': '1', 'name': daily_info['name'], 'url': daily_info['url'], 'slug': slug, 'daily_info': 'None' }
		infoLabels = { "Title": daily_info['name'], "Plot": daily_info['plot'] }
		addListItem('[ ' + daily_info['name'] + ' ]', daily_info['thumb'], u, True, 0, infoLabels, fanart)
	if settings.getSetting('download') == '' or settings.getSetting('download') == 'false':
		if settings.getSetting('playall') == 'true':
			playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
			playlist.clear()
			u = { 'mode': '6' }
			infoLabels = { "Title": settings.getLocalizedString( 30030 ), "Plot": settings.getLocalizedString( 30031 ) }
			addListItem('* ' + settings.getLocalizedString( 30030 ) + ' *', play_thumb, u, True, 0, infoLabels, fanart)
	for episode in data['episodes']:
		studio = episode['show']['name']
		thumb = episode['images']['medium']
		url = episode['media']
		plot = episode['summary'].encode('ascii', 'ignore')
		name = episode['name'].encode('ascii', 'ignore')
		episodenum = episode['number']
		date = episode['published'].rsplit('T')[0]
		duration = int(episode['duration'])
		infoLabels = { "Title": name, "Studio": studio, "Plot": plot, "Episode": int(episodenum), "Aired": date }
		u = { 'mode': '2', 'name': name, 'url': url, 'plot': plot, 'studio': studio, 'episode': episodenum, 'thumb': thumb, 'date': date }
		addListItem(plot, thumb, u, False, len(data['episodes']), infoLabels, fanart, duration)
	if (int(data['total']) - ((offset + 1) * 25)) > 0:
		u = { 'mode': '1', 'name': studio, 'url': saveurl, 'slug': slug, 'offset': offset + 1, 'daily_info': 'None' }
		infoLabels = { "Title": settings.getLocalizedString( 30016 ), "Plot": settings.getLocalizedString( 30016 ) }
		addListItem(settings.getLocalizedString( 30016 ) + ' (' + str( offset + 2 ) + ')', next_thumb, u, True, 0, infoLabels, fanart)
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_EPISODE )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_STUDIO )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME )
	setViewMode("503")
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_sub_directory(url, name, slug, offset, daily_info):
    if slug == None:
        dialog = xbmcgui.Dialog()
        ok = dialog.ok(plugin, settings.getLocalizedString(30029))
        build_main_directory(BASE + 'getShows' + KEY)
        return
    saveurl = url
    data = json.loads(getUrl(url + '&offset=' + str(offset * 25)))
    if len(data['episodes']) == 0:
        dialog = xbmcgui.Dialog()
        ok = dialog.ok(plugin,
                       settings.getLocalizedString(30026) + ' ' + name + '.')
        return
    if slug != 'None':
        try:
            downloads = 'http://testtube.com/' + slug + '/' + slug + '_downloads'
            fresult = getPage(downloads)['content']
            match = re.compile('<a href="(.+?)" target="_blank">1920x1200</a>'
                               ).findall(fresult)
            if len(match) > 1:
                fanart = match[1]
            else:
                fanart = match[0]
            settings.setSetting(slug, fanart)
        except:
            fanart = 'http://videos.testtube.com/revision3/images/shows/%s/%s_hero.jpg' % (
                slug, slug)
            if getPage(fanart)['error'] == 'HTTP Error 404: Not Found':
                fanart = fanart_bg
                settings.setSetting(slug, fanart)
            else:
                settings.setSetting(slug, fanart)
    else:
        fanart = fanart_bg
    if daily_info != 'None' and settings.getSetting('daily') == 'true':
        daily_info = ast.literal_eval(daily_info)
        u = {
            'mode': '1',
            'name': daily_info['name'],
            'url': daily_info['url'],
            'slug': slug,
            'daily_info': 'None'
        }
        infoLabels = {"Title": daily_info['name'], "Plot": daily_info['plot']}
        addListItem('[ ' + daily_info['name'] + ' ]', daily_info['thumb'], u,
                    True, 0, infoLabels, fanart)
    if settings.getSetting('download') == '' or settings.getSetting(
            'download') == 'false':
        if settings.getSetting('playall') == 'true':
            playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
            playlist.clear()
            u = {'mode': '6'}
            infoLabels = {
                "Title": settings.getLocalizedString(30030),
                "Plot": settings.getLocalizedString(30031)
            }
            addListItem('* ' + settings.getLocalizedString(30030) + ' *',
                        play_thumb, u, True, 0, infoLabels, fanart)
    for episode in data['episodes']:
        studio = episode['show']['name']
        thumb = episode['images']['medium']
        url = episode['media']
        plot = episode['summary'].encode('ascii', 'ignore')
        name = episode['name'].encode('ascii', 'ignore')
        episodenum = episode['number']
        date = episode['published'].rsplit('T')[0]
        duration = int(episode['duration'])
        infoLabels = {
            "Title": name,
            "Studio": studio,
            "Plot": plot,
            "Episode": int(episodenum),
            "Aired": date
        }
        u = {
            'mode': '2',
            'name': name,
            'url': url,
            'plot': plot,
            'studio': studio,
            'episode': episodenum,
            'thumb': thumb,
            'date': date
        }
        addListItem(plot, thumb, u, False, len(data['episodes']), infoLabels,
                    fanart, duration)
    if (int(data['total']) - ((offset + 1) * 25)) > 0:
        u = {
            'mode': '1',
            'name': studio,
            'url': saveurl,
            'slug': slug,
            'offset': offset + 1,
            'daily_info': 'None'
        }
        infoLabels = {
            "Title": settings.getLocalizedString(30016),
            "Plot": settings.getLocalizedString(30016)
        }
        addListItem(
            settings.getLocalizedString(30016) + ' (' + str(offset + 2) + ')',
            next_thumb, u, True, 0, infoLabels, fanart)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_EPISODE)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_STUDIO)
    xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                             sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
    setViewMode("503")
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Exemple #36
0
def find_trailers(url, name, page, library):
    save_name = name
    save_page = page
    data = getUrl(url).decode('ascii', 'ignore')
    link_thumb = re.compile(
        '<a href="(.+?)"><img src="(.+?)" name="thumb').findall(data)
    thumbs = re.compile('img src="/psize\.php\?dir=(.+?)" style').findall(data)
    if len(thumbs) == 0:
        thumb = "DefaultVideo.png"
    else:
        thumb = 'http://www.traileraddict.com/' + thumbs[0]
    title = re.compile(
        '<div class="abstract"><h2><a href="(.+?)">(.+?)</a></h2><br />',
        re.DOTALL).findall(data)
    trailers = re.compile('<dl class="dropdown">(.+?)</dl>',
                          re.DOTALL).findall(data)
    if len(title) == 0 and len(trailers) == 0:
        list = common.parseDOM(data, "div", attrs={"class": "info"})
        header = common.parseDOM(data, "div", attrs={"class": "trailerheader"})
        nexturl = common.parseDOM(header,
                                  "a",
                                  attrs={"title": "Next Page"},
                                  ret="href")
        totalItems = len(list)
        if totalItems == 0:
            dialog = xbmcgui.Dialog()
            ok = dialog.ok(plugin, settings.getLocalizedString(30012))
            ok = dialog.ok(plugin, settings.getLocalizedString(30051))
            buggalo.addExtraData('url', url)
            buggalo.addExtraData('name', name)
            raise Exception('find_trailers Error A')
            return
        for video in list:
            h2 = common.parseDOM(video, "h2")
            title = common.parseDOM(h2, "a")[0]
            url = 'http://www.traileraddict.com' + common.parseDOM(
                h2, "a", ret="href")[0]
            thumb = 'http://www.traileraddict.com' + common.parseDOM(
                video, "img", attrs={"class": "dimmer"}, ret="src")[0].replace(
                    '-t.jpg', '.jpg')
            #infoLabels = { "Title": title, "Plot": save_name + ' (' + clean( title ) + ')' }
            cm = []
            run = sys.argv[0] + '?' + urllib.urlencode(
                {
                    'mode': '5',
                    'name': save_name + ' (' + clean(title) + ')',
                    'url': url,
                    'download': 'True'
                })
            cm.append((settings.getLocalizedString(30059),
                       "XBMC.RunPlugin(%s)" % run))
            cm.append((settings.getLocalizedString(
                30014
            ), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)"
                       % save_name))
            u = {
                'mode': '5',
                'name': save_name + ' (' + clean(title) + ')',
                'url': url
            }
            addListItem(label=clean(title),
                        image=thumb,
                        url=u,
                        isFolder=False,
                        totalItems=totalItems,
                        infoLabels=False,
                        cm=cm)
        if len(nexturl) > 0:
            url = 'http://www.traileraddict.com' + nexturl[0]
            u = {
                'mode': '4',
                'name': save_name,
                'url': url,
                'page': str(int(save_page) + 1)
            }
            addListItem(label='[Next Page (' + str(int(save_page) + 2) + ')]',
                        image=next_thumb,
                        url=u,
                        isFolder=True,
                        totalItems=0,
                        infoLabels=False)
        xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                                 sortMethod=xbmcplugin.SORT_METHOD_NONE)
        setViewMode("502", "movies")
        xbmcplugin.endOfDirectory(int(sys.argv[1]))
        return
    item_count = 0
    if len(trailers) > 0:
        check1 = re.compile(
            '<a href="(.+?)"><img src="\/images\/usr\/arrow\.png" border="0" style="float:right;" \/>(.+?)</a>'
        ).findall(trailers[0])
        check2 = re.compile(
            '<a href="(.+?)"( style="(.*?)")?>(.+?)<br />').findall(
                trailers[0])
        totalItems = len(check1)
        totalItems2 = len(check2)
        if totalItems > 0:
            url_title = check1
            if library == True:
                return url_title[0][0]
            for url, title in url_title:
                url = 'http://www.traileraddict.com' + url
                cm = []
                run = sys.argv[0] + '?' + urllib.urlencode(
                    {
                        'mode': '5',
                        'name': save_name + ' (' + clean(title) + ')',
                        'url': url,
                        'download': 'True'
                    })
                cm.append((settings.getLocalizedString(30059),
                           "XBMC.RunPlugin(%s)" % run))
                cm.append((settings.getLocalizedString(
                    30014
                ), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)"
                           % save_name))
                infoLabels = {
                    "Title": title,
                    "Plot": save_name + ' (' + clean(title) + ')'
                }
                u = {
                    'mode': '5',
                    'name': save_name + ' (' + clean(title) + ')',
                    'url': url
                }
                addListItem(label=clean(title),
                            image=thumb,
                            url=u,
                            isFolder=False,
                            totalItems=totalItems,
                            infoLabels=False,
                            cm=cm)
            xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                                     sortMethod=xbmcplugin.SORT_METHOD_NONE)
            setViewMode("502", "movies")
            xbmcplugin.endOfDirectory(int(sys.argv[1]))
        elif totalItems2 > 0:
            url_title = check2
            if library == True:
                return url_title[0][0]
            for url, trash1, trash2, title in url_title:
                url = 'http://www.traileraddict.com' + url
                #infoLabels = { "Title": title, "Plot": save_name + ' (' + clean( title ) + ')' }
                cm = []
                run = sys.argv[0] + '?' + urllib.urlencode({
                    'mode':
                    '5',
                    'name':
                    save_name.decode('ascii', 'ignore') + ' (' + clean(title) +
                    ')',
                    'url':
                    url,
                    'download':
                    'True'
                })
                cm.append((settings.getLocalizedString(30059),
                           "XBMC.RunPlugin(%s)" % run))
                cm.append((settings.getLocalizedString(
                    30014
                ), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)"
                           % save_name.decode('ascii', 'ignore')))
                u = {
                    'mode':
                    '5',
                    'name':
                    save_name.decode('ascii', 'ignore') + ' (' + clean(title) +
                    ')',
                    'url':
                    url
                }
                addListItem(label=clean(title),
                            image=thumb,
                            url=u,
                            isFolder=False,
                            totalItems=totalItems2,
                            infoLabels=False,
                            cm=cm)
            xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                                     sortMethod=xbmcplugin.SORT_METHOD_NONE)
            setViewMode("502", "movies")
            xbmcplugin.endOfDirectory(int(sys.argv[1]))
        else:
            # dia = xbmcgui.Dialog()
            # ok = dia.ok(plugin, settings.getLocalizedString(30006) )
            # ok = dia.ok(plugin, settings.getLocalizedString( 30051 ))
            # buggalo.addExtraData('url', url)
            # buggalo.addExtraData('name', save_name)
            # raise Exception('find_trailers Error 2')
            # xbmc.executebuiltin('Notification('+plugin+',Only video clips were found!,5000,'+icon_thumb+')')
            list = common.parseDOM(data, "div", attrs={"class": "info"})
            header = common.parseDOM(data,
                                     "div",
                                     attrs={"class": "trailerheader"})
            nexturl = common.parseDOM(header,
                                      "a",
                                      attrs={"title": "Next Page"},
                                      ret="href")
            totalItems = len(list)
            if totalItems == 0:
                dialog = xbmcgui.Dialog()
                ok = dialog.ok(plugin, settings.getLocalizedString(30012))
                ok = dialog.ok(plugin, settings.getLocalizedString(30051))
                buggalo.addExtraData('url', url)
                buggalo.addExtraData('name', name)
                raise Exception('find_trailers Error B')
                return
            for video in list:
                h2 = common.parseDOM(video, "h2")
                title = common.parseDOM(h2, "a")[0]
                url = 'http://www.traileraddict.com' + common.parseDOM(
                    h2, "a", ret="href")[0]
                thumb = 'http://www.traileraddict.com' + common.parseDOM(
                    video, "img", attrs={"class": "dimmer"},
                    ret="src")[0].replace('-t.jpg', '.jpg')
                #infoLabels = { "Title": title, "Plot": save_name + ' (' + clean( title ) + ')' }
                cm = []
                run = sys.argv[0] + '?' + urllib.urlencode(
                    {
                        'mode': '5',
                        'name': save_name + ' (' + clean(title) + ')',
                        'url': url,
                        'download': 'True'
                    })
                cm.append((settings.getLocalizedString(30059),
                           "XBMC.RunPlugin(%s)" % run))
                cm.append((settings.getLocalizedString(
                    30014
                ), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)"
                           % save_name))
                u = {
                    'mode': '5',
                    'name': save_name + ' (' + clean(title) + ')',
                    'url': url
                }
                addListItem(label=clean(title),
                            image=thumb,
                            url=u,
                            isFolder=False,
                            totalItems=totalItems,
                            infoLabels=False,
                            cm=cm)
            if len(nexturl) > 0:
                url = 'http://www.traileraddict.com' + nexturl[0]
                u = {
                    'mode': '4',
                    'name': save_name,
                    'url': url,
                    'page': str(int(save_page) + 1)
                }
                addListItem(label='[Next Page (' + str(int(save_page) + 2) +
                            ')]',
                            image=next_thumb,
                            url=u,
                            isFolder=True,
                            totalItems=0,
                            infoLabels=False)
            xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                                     sortMethod=xbmcplugin.SORT_METHOD_NONE)
            setViewMode("502", "movies")
            xbmcplugin.endOfDirectory(int(sys.argv[1]))
    else:
        totalItems = len(link_thumb)
        for url, thumb2 in link_thumb:
            if clean(title[item_count][1]).find('Trailer') > 0:
                url = 'http://www.traileraddict.com' + url
                cm = []
                run = sys.argv[0] + '?' + urllib.urlencode(
                    {
                        'mode': '5',
                        'name':
                        save_name + ' (' + clean(title[item_count][1]) + ')',
                        'url': url,
                        'download': 'True'
                    })
                cm.append((settings.getLocalizedString(30059),
                           "XBMC.RunPlugin(%s)" % run))
                cm.append((settings.getLocalizedString(
                    30014
                ), "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add?title=%s)"
                           % save_name))
                infoLabels = {
                    "Title": title[item_count][1],
                    "Plot":
                    save_name + ' (' + clean(title[item_count][1]) + ')'
                }
                u = {
                    'mode': '5',
                    'name':
                    save_name + ' (' + clean(title[item_count][1]) + ')',
                    'url': url
                }
                addListItem(label=clean(title[item_count][1]),
                            image=thumb,
                            url=u,
                            isFolder=False,
                            totalItems=totalItems,
                            infoLabels=False,
                            cm=cm)
            item_count = item_count + 1
        xbmcplugin.addSortMethod(handle=int(sys.argv[1]),
                                 sortMethod=xbmcplugin.SORT_METHOD_NONE)
        setViewMode("502", "movies")
        xbmcplugin.endOfDirectory(int(sys.argv[1]))
def build_video_directory(url, name, type):
	nextname = name
	if name == settings.getLocalizedString( 30005 ):
		if page == 0 and type != 'history':
			try:
				newStr = common.getUserInput(settings.getLocalizedString( 30005 ), '').replace(' ','%20')
			except:
				return
			presets = settings.getSetting( "presets_search" )
			if presets == '':
				save_str = newStr
			else:
				if presets.find(newStr + ' |') == -1:
					save_str = presets + ' | ' + newStr
				else:
					save_str = presets
			settings.setSetting("presets_search", save_str)
		else:
			newStr = getParameters(url)["searchString"]
		url = 'http://search.espn.go.com/results?searchString=' + newStr + '&start=' + str(int(page) * 16) + '&dims=6'
		nexturl = url
		html = getUrl(url).decode('ascii', 'ignore')
		html = html.decode('UTF-8','ignore') #Swedemon/Mrdally204 Change 2015-08-31
		results = common.parseDOM(html, "li", attrs = { "class": "result video-result" })
		titledata = common.parseDOM(results, "h3")
		title = common.parseDOM(titledata, "a", attrs = { "rel": "nofollow" })
		if len(title) == 0:
			dialog = xbmcgui.Dialog()
			ok = dialog.ok( plugin , settings.getLocalizedString( 30013 ) + '\n' + settings.getLocalizedString( 30014 ) )
			remove_menu(newStr,'search')
			return
		img = common.parseDOM(results, "a", attrs = { "class": "list-thumb" })
		desc = common.parseDOM(results, "p")
		thumb = common.parseDOM(img, "img", ret = "src" )
		pagenum = common.parseDOM(html, "div", attrs = { "class": "page-numbers" })[0]
		maxlength = common.parseDOM(pagenum, "span")[1].replace('of ','')
		value = common.parseDOM(pagenum, "input", attrs = { "id": "page-number" }, ret = "value" )[0]
		pagecount = [ value, maxlength ]
	else:
		nexturl = url
		html = getUrl(url + "&pageNum=" + str(int(page)) + "&sortBy=&assetURL=http://assets.espn.go.com&module=LibraryPlaylist&pagename=vhub_index")
		html = html.decode('UTF-8','ignore') #Swedemon/Mrdally204 Change 2015-08-31
		videocell = common.parseDOM(html, "div", attrs = { "class": "video-cell" })
		title = common.parseDOM(videocell, "h5")
		thumb = common.parseDOM(videocell, "img", ret = "src")
		desc = common.parseDOM(common.parseDOM(videocell, "p", attrs = { "class": "watch-now" }), "a", ret = "href")
		try:
			pagecount = common.parseDOM(html, "div", attrs = { "class": "page-numbers" })[0].rsplit(' of ')
		except:
			pagecount = ''
	item_count = 0
	#print 'videocell='+str(videocell)+'title='+str(title)+'thumb='+str(thumb)+'desc='+str(desc)+'pagecount='+str(pagecount)
	for name in title:
		if '/espn360/' not in thumb[item_count]:
			if 'http://' in desc[item_count]:
				plot = name
			else:
				plot = desc[item_count]
			try:
				data = thumb[item_count].replace('_thumdnail_wbig.jpg','').replace('.jpg','').rsplit('motion/')
				url = data[1]
			except:
				data = thumb[item_count].replace('_thumdnail_wbig.jpg','').replace('.jpg','').rsplit('/')[-4:]
				if len(data) >= 4:
					url = data[0] + '/' + data[1] + '/' + data[2] + '/' + data[3]
				else:
					url = 'null'
			thumbnailImage = thumb[item_count].replace('_thumdnail_wbig','')
			u = { 'mode': '3', 'name': name, 'url': url.replace('motion/',''), 'thumb': thumbnailImage, 'plot': plot }
			infoLabels = { "Title": name, "Plot": plot }
			addListItem(label = name, image = thumbnailImage, url = u, isFolder = False, infoLabels = infoLabels)
		item_count += 1
	if pagecount and pagecount[0] != pagecount[1]:
		u = { 'mode': '2', 'name': nextname, 'url': nexturl, 'page': str(int(page) + 1), 'type': 'null' }
		infoLabels = { "Title": settings.getLocalizedString( 30003 ), "Plot": settings.getLocalizedString( 30003 ) }
		addListItem(label = settings.getLocalizedString( 30003 ), image = next_thumb, url = u, isFolder = True, infoLabels = infoLabels)
	xbmcplugin.addSortMethod( handle = int(sys.argv[1]), sortMethod = xbmcplugin.SORT_METHOD_NONE )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )
def find_videos( name, program_id, topic, page ):
	start = str( 200 * page )
	url = 'None'
	backup_url = None
	if topic == 'True':
		program_id = 'program_id'
		data = cove.videos.filter(fields='associated_images,mediafiles,categories',filter_categories__name=name,order_by='-airdate',filter_availability_status='Available',limit_start=start,exclude_type__in='Chapter,Promotion')
	elif topic == 'False':
		data = cove.videos.filter(fields='associated_images,mediafiles',filter_tp_media_object_id=program_id,limit_start=start)
		print "PBS - Video ID: " + program_id
		if len(data) == 0:
			dialog = xbmcgui.Dialog()
			ok = dialog.ok( plugin , settings.getLocalizedString( 30009 ) + '\n' + 'http://video.pbs.org/video/' + program_id )
			return
	elif topic == 'search':
		data = cove.videos.filter(fields='associated_images,mediafiles',filter_title__contains=name,order_by='-airdate',filter_availability_status='Available',limit_start=start)
		if len(data) == 0:
			data = cove.videos.filter(fields='associated_images,mediafiles',filter_title__contains=string.capwords(name),order_by='-airdate',filter_availability_status='Available',limit_start=start)
	else:
		topic = 'topic'
		data = cove.videos.filter(fields='associated_images,mediafiles',filter_program=program_id,order_by='-airdate',filter_availability_status='Available',limit_start=start,exclude_type__in='Chapter,Promotion')
		if len(data) <= 1:
			data = cove.videos.filter(fields='associated_images,mediafiles',filter_program=program_id,order_by='-airdate',filter_availability_status='Available',limit_start=start)
	for results in data:
		playable = None
		if results['associated_images'] != None and len(results['associated_images']) > 0:
			thumb = results['associated_images'][0]['url']
		else:
			thumb = 'None'
		count = 0
		for videos in results['mediafiles']:
			if results['mediafiles'][count]['video_encoding']['name'] == 'MPEG-4 500kbps':
				playable = count
			count += 1
		if playable == None:
			playable = count - 1
		if playable != -1:
			if results['mediafiles'][playable]['video_data_url'] != None:
				url = results['mediafiles'][playable]['video_data_url']
				mode = '5'
				if results['mediafiles'][playable]['video_download_url'] != None:
					backup_url = results['mediafiles'][playable]['video_download_url']
				else:
					backup_url = 'None'	
			elif results['mediafiles'][playable]['video_data_url'] == None and results['mediafiles'][playable]['video_download_url'] == None:
				url = 'None'
				mode = '5'
			else:
				url = results['mediafiles'][playable]['video_download_url']
				mode = '7'
			infoLabels = { "Title": results['title'].encode('utf-8'), "Director": "PBS", "Studio": name, "Plot": results['long_description'].encode('utf-8'), "Aired": results['airdate'].rsplit(' ')[0], "Duration": str((int(results['mediafiles'][0]['length_mseconds'])/1000)/60) }
			u = { 'mode': mode, 'name': urllib.quote_plus( results['title'].encode('utf-8') ), 'url': urllib.quote_plus( url ), 'thumb': urllib.quote_plus( thumb ), 'plot': urllib.quote_plus( results['long_description'].encode('utf-8') ), 'studio': urllib.quote_plus( name ), 'backup_url': urllib.quote_plus( backup_url ) }
			addListItem(label = results['title'].encode('utf-8'), image = thumb, url = u, isFolder = False, infoLabels = infoLabels, fanart = fanart, duration = str(int(results['mediafiles'][0]['length_mseconds'])/1000))
	if topic == 'False':
		play_video( results['title'].encode('utf-8'), url, thumb, results['long_description'].encode('utf-8'), name.encode('utf-8'), None, backup_url )
		return
	if len(data) == 0:
		dialog = xbmcgui.Dialog()
		ok = dialog.ok( plugin , settings.getLocalizedString( 30012 ) + ' ' + name + '.' )
		return
	if ( len(data) ) == 200:
		u = { 'mode': '0', 'name': urllib.quote_plus( name ), 'program_id': urllib.quote_plus( program_id ), 'topic': urllib.quote_plus( topic ), 'page': str( int( page ) + 1 ) }
		addListItem(label = '[Next Page (' + str( int( page ) + 2 ) + ')]', image = next_thumb, url = u, isFolder = True, infoLabels = False, fanart = fanart)
	if topic == 'search':
		build_programs_directory( name, 0 )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME )
	xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LABEL )
	setViewMode("503")
	xbmcplugin.endOfDirectory( int( sys.argv[1] ) )