Making Video Play

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
i have started making a karaoke plugin which returns youtube karaoke videos

only problem is when clicked it dont play all i get is this from xbmc log

Code:
DVDPlayer: Opening: http://www.youtube.com/v/O8i4Qw52lv4
15:25:39 T:3820 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
15:25:39 T:3556  NOTICE: Creating InputStream
15:25:40 T:3556  NOTICE: Creating Demuxer
15:25:40 T:3556   ERROR: CDVDDemuxFFmpeg::Open - Error, could not open file http://www.youtube.com/v/O8i4Qw52lv4
this is the only way this site returns the youtube link


how do i get xbmc to know that this is a you tube link to play this is what i have


this returns the youtube link

Code:
def VIDEOLINKS(url,name):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        match=re.compile('<embed src="(.+?)&hl=').findall(link)
        for url in match:
                addLink(name,url,'')
this is what i think i need to change to make it play
Code:
def addLink(name,url,iconimage):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
        return ok
 

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
Once I've sorted that bit out then I can get on with keyboard search

I'm so nearly there just need a helping hand
 

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
You can't play that URL as it's not an actual direct video link

Call the Youtube addon and pass in that link to it
 

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
I'm not near any of my code, but you can check the metahandlers code, in the metahandler.py file I wrote the command right in it

You can also use URLResolver
 

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
and ive sorted the search out to.......only problem i have is that when video is playing if i select back or stop it rescrapes and plays

keeps doing that like a continuous loop....

Code:
import urllib,urllib2,re,xbmcplugin,xbmcgui,xbmcaddon

url= 'http://www.cantanding.com/'
thumbnail= 'icon.png'

def CATEGORIES():
        addDir('Search Mikeys Karaoke','url',1,'icon.png')
                     
def INDEX(url):
        search_entered = ''
        keyboard = xbmc.Keyboard(search_entered, 'Search Mikeys Karaoke')
        keyboard.doModal()
        if keyboard.isConfirmed():
            search_entered = keyboard.getText() .replace(' ','+')  # sometimes you need to replace spaces with + or %20#
	    if search_entered == None:
	        return False
        url = 'http://www.cantanding.com/search/%s/' % (search_entered)        
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        match=re.compile('\t<a href="(.+?)">(.+?)</a>').findall(link)
        for url,name in match:
                addDir(name,url,2,'icon.png')

def VIDEOLINKS(url):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        match=re.search(r'<embed src="http://www.youtube.com/v/(.+?)&hl', link)
        youtube_id = match.group(1)
        xbmc_url = 'plugin://plugin.video.youtube/?path=/root/search/new&action=play_video&videoid=%s' % youtube_id
        xbmc.executebuiltin('XBMC.PlayMedia(%s)' % xbmc_url)

                      
               
def get_params():
        param=[]
        paramstring=sys.argv[2]
        if len(paramstring)>=2:
                params=sys.argv[2]
                cleanedparams=params.replace('?','')
                if (params[len(params)-1]=='/'):
                        params=params[0:len(params)-2]
                pairsofparams=cleanedparams.split('&')
                param={}
                for i in range(len(pairsofparams)):
                        splitparams={}
                        splitparams=pairsofparams[i].split('=')
                        if (len(splitparams))==2:
                                param[splitparams[0]]=splitparams[1]
                                
        return param

def addDir(name,url,mode,iconimage):
        u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
        return ok
        
              
params=get_params()
url=None
name=None
mode=None

try:
        url=urllib.unquote_plus(params["url"])
except:
        pass
try:
        name=urllib.unquote_plus(params["name"])
except:
        pass
try:
        mode=int(params["mode"])
except:
        pass

print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)

if mode==None or url==None or len(url)<1:
        print ""
        CATEGORIES()
       
elif mode==1:
        print ""+url
        INDEX(url)
        
elif mode==2:
        print ""+url
        VIDEOLINKS(url)
        


xbmcplugin.endOfDirectory(int(sys.argv[1]))
 

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
i have sorted the looping now its cause i didnt return back to a directory

i think the website has limited searches how can i get round it

Fatal error: Uncaught exception 'BitlyException' with message 'RATE_LIMIT_EXCEEDED' in /home/cantanding/domains/cantanding.com/public_html/plugins/Bitly.php:196 Stack trace: #0 /home/cantanding/domains/cantanding.com/public_html/plugins/Bitly.php(383): Bitly->doCall('shorten', Array) #1 /home/cantanding/domains/cantanding.com/public_html/controller/Cancion.php(87): Bitly->shorten('http://www.cant...') #2 /home/cantanding/domains/cantanding.com/public_html/core/site.php(27): Cancion->def(NULL) #3 /home/cantanding/domains/cantanding.com/public_html/core/init.php(24): Site->run('Cancion', 'def', NULL) #4 /home/cantanding/domains/cantanding.com/public_html/index.php(2): require_once('/home/cantandin...') #5 {main} thrown in /home/cantanding/domains/cantanding.com/public_html/plugins/Bitly.php on line 196