Example #1
0
def listen_live(label='', url=None):
    
    if not url:
        return
    
    txt = iplayer.httpget(url)
    
    # some of the the urls passed in are .asx. These are text files with multiple mss stream hrefs
    stream = re.compile('href\="(mms.*?)"', re.IGNORECASE)
    match  = stream.search(txt) 
    stream_url = None
    if match:
        stream_url = match.group(1)
    else:
        # pass it to xbmc and see if it is directly supported 
        stream_url = url
        
    listitem = xbmcgui.ListItem(label=label, label2=label)
    if thumbnail: listitem.setThumbnailImage(thumbnail)
    
    play=xbmc.PlayList(xbmc.PLAYLIST_MUSIC)

    play.clear()
    play.add(stream_url,listitem)
        
    player = xbmc.Player(xbmc.PLAYER_CORE_AUTO)

    player.play(play)
Example #2
0
def listen_live(label='', url=None):

    if not url:
        return

    txt = iplayer.httpget(url)

    # some of the the urls passed in are .asx. These are text files with multiple mss stream hrefs
    stream = re.compile('href\="(mms.*?)"', re.IGNORECASE)
    match = stream.search(txt)
    stream_url = None
    if match:
        stream_url = match.group(1)
    else:
        # pass it to xbmc and see if it is directly supported
        stream_url = url

    listitem = xbmcgui.ListItem(label=label, label2=label)
    if thumbnail: listitem.setThumbnailImage(thumbnail)

    play = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)

    play.clear()
    play.add(stream_url, listitem)

    player = xbmc.Player(xbmc.PLAYER_CORE_AUTO)

    player.play(play)
def parse_asx(radio_url):
    txt = iplayer.httpget(radio_url)
    match_mms  = re_stream_mms.search(txt)
    if  match_mms:
        stream_url = match_mms.group(1)
    else:
        stream_url = radio_url

    return stream_url
Example #4
0
def parse_asx(radio_url):
    txt = iplayer.httpget(radio_url)
    match_mms = re_stream_mms.search(txt)
    if match_mms:
        stream_url = match_mms.group(1)
    else:
        stream_url = radio_url

    return stream_url
def parse_asx(radio_url):
    stream_mms  = re.compile('href\s*\=\s*"(mms.*?)"', re.IGNORECASE)
    txt = iplayer.httpget(radio_url)
    match_mms  = stream_mms.search(txt)
    if  match_mms:
        stream_url = match_mms.group(1)
    else:
        stream_url = radio_url

    return stream_url
def parse_asx(radio_url):
    stream_mms = re.compile('href\s*\=\s*"(mms.*?)"', re.IGNORECASE)
    txt = iplayer.httpget(radio_url)
    match_mms = stream_mms.search(txt)
    if match_mms:
        stream_url = match_mms.group(1)
    else:
        stream_url = radio_url

    return stream_url
Example #7
0
def list_live_feeds(feeds, tvradio='tv'):
    #print 'list_live_feeds %s' % feeds
    xbmcplugin.setContent(__plugin_handle__, 'songs')
    xbmcplugin.addSortMethod(handle=__plugin_handle__,
                             sortMethod=xbmcplugin.SORT_METHOD_TRACKNUM)

    if tvradio == 'tv':
        return

    i = 0

    for j, f in enumerate(feeds):
        if not iplayer.stations.live_radio_stations.has_key(f.name):
            #print "no key for %s" % f.name
            continue
        listitem = xbmcgui.ListItem(label=f.name)
        listitem.setIconImage('defaultFolder.png')
        if iplayer.stations.live_webcams.has_key(f.name):
            listitem.setThumbnailImage(iplayer.stations.live_webcams[f.name])
        else:
            listitem.setThumbnailImage(get_feed_thumbnail(f))
        listitem.setProperty('tracknumber', str(i + j))

        # Real & ASX url's are just redirects that are not always well
        # handled by XBMC so if present load and process redirect
        radio_url = iplayer.stations.live_radio_stations[f.name]
        stream_asx = re.compile('\.asx$', re.IGNORECASE)
        stream_mms = re.compile('href\s*\=\s*"(mms.*?)"', re.IGNORECASE)

        match_asx = stream_asx.search(radio_url)

        if match_asx:
            txt = iplayer.httpget(radio_url)
            match_mms = stream_mms.search(txt)
            if match_mms:
                stream_url = match_mms.group(1)
            else:
                stream_url = radio_url
        else:
            stream_url = radio_url

        listitem.setPath(stream_url)

        ok = xbmcplugin.addDirectoryItem(
            handle=__plugin_handle__,
            url=stream_url,
            listitem=listitem,
            isFolder=False,
        )

    xbmcplugin.endOfDirectory(handle=__plugin_handle__, succeeded=True)
Example #8
0
def list_live_feeds(feeds, tvradio='tv'):
    #print 'list_live_feeds %s' % feeds
    xbmcplugin.setContent(PLUGIN_HANDLE, 'songs')
    xbmcplugin.addSortMethod(handle=PLUGIN_HANDLE, sortMethod=xbmcplugin.SORT_METHOD_TRACKNUM)

    if tvradio == 'tv':
        return
        
    i = 0        
    
    for j, f in enumerate(feeds):
        if not iplayer.stations.live_radio_stations.has_key(f.name):
            #print "no key for %s" % f.name
            continue
        listitem = xbmcgui.ListItem(label=f.name)
        listitem.setIconImage('defaultFolder.png')
        if iplayer.stations.live_webcams.has_key(f.name):
            listitem.setThumbnailImage(iplayer.stations.live_webcams[f.name])
        else:
            listitem.setThumbnailImage(get_feed_thumbnail(f))
        listitem.setProperty('tracknumber', str(i + j))
        
        # Real & ASX url's are just redirects that are not always well
        # handled by XBMC so if present load and process redirect
        radio_url   = iplayer.stations.live_radio_stations[f.name]
        stream_asx  = re.compile('\.asx$', re.IGNORECASE)
        stream_mms  = re.compile('href\s*\=\s*"(mms.*?)"', re.IGNORECASE)
               
        match_asx   = stream_asx.search(radio_url) 
        
        if match_asx:
            txt = iplayer.httpget(radio_url)
            match_mms  = stream_mms.search(txt)
            if  match_mms:
                stream_url = match_mms.group(1)
            else:
                stream_url = radio_url
        else:
            stream_url = radio_url
        
        listitem.setPath(stream_url)
                          
        ok = xbmcplugin.addDirectoryItem(
            handle=PLUGIN_HANDLE,
            url=stream_url,
            listitem=listitem,
            isFolder=False,
        )
    
    xbmcplugin.endOfDirectory(handle=PLUGIN_HANDLE, succeeded=True)
Example #9
0
def play_stream(channel, bitrate, showDialog):
    bitrate = int(bitrate)
    # check to see if bbcthree/cbbc or bbcfour/cbeebies is on the air?    
    if channel == 'bbc_three' or channel == 'bbc_four' or channel == 'cbeebies' or channel == 'cbbc':
        surl = 'http://www.bbc.co.uk/iplayer/tv/'+channel
        cstr = httpget(surl)
        off_air_message = re.compile('<h2 class="off-air">.+?</span>(.+?)</a></h2>').findall(cstr)
        if off_air_message:
            pDialog = xbmcgui.Dialog()
            pDialog.ok('IPlayer', 'Channel is currently Off Air')
            return

    provider = get_provider()
    
    # check for red button usage
    if channel == 'bbc_redbutton':
        pDialog = xbmcgui.Dialog()
        if not pDialog.yesno("BBC Red Button Live Stream", "This will only work when the stream is broadcasting.", "If it is not on, xbmc may retry indefinately (crash)", "Do you want to try anyway?"):
            return

    url = fetch_stream_info(channel, bitrate, provider)

    if url == "":
        Dialog = xbmcgui.Dialog()
        pDialog.ok('IPlayer', "Sorry, stream is currently unavailable")

    if showDialog:
        pDialog = xbmcgui.DialogProgress()
        pDialog.create('IPlayer', 'Loading live stream info')
        xbmc.sleep(50)

    if showDialog: pDialog.update(50, 'Starting Stream')
    # build listitem to display whilst playing
    (sort, stream_id, label, thumb) = live_tv_channels[channel]
    listitem = xbmcgui.ListItem(label = label + ' - Live')
    listitem.setIconImage('defaultVideo.png')
    listitem.setThumbnailImage(os.path.join(get_thumb_dir(), thumb))

    play = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
    play.clear()
    play.add(url,listitem)
    player = xbmc.Player(xbmc.PLAYER_CORE_DVDPLAYER)
    player.play(play)
    if showDialog: pDialog.close()
Example #10
0
def play_stream(channel, bitrate, showDialog):
    bitrate = int(bitrate)
    # check to see if bbcthree/cbbc or bbcfour/cbeebies is on the air?    
    if channel == 'bbc_three' or channel == 'bbc_four' or channel == 'cbeebies' or channel == 'cbbc':
        surl = 'http://www.bbc.co.uk/iplayer/tv/'+channel
        cstr = httpget(surl)
        off_air_message = re.compile('<h2 class="off-air">.+?</span>(.+?)</a></h2>').findall(cstr)
        if off_air_message:
            pDialog = xbmcgui.Dialog()
            pDialog.ok('IPlayer', 'Channel is currently Off Air')
            return

    provider = get_provider()
    
    # check for red button usage
    if channel == 'bbc_redbutton':
        pDialog = xbmcgui.Dialog()
        if not pDialog.yesno("BBC Red Button Live Stream", "This will only work when the stream is broadcasting.", "If it is not on, xbmc may retry indefinately (crash)", "Do you want to try anyway?"):
            return

    url = fetch_stream_info(channel, bitrate, provider)

    if url == "":
        pDialog = xbmcgui.Dialog()
        pDialog.ok('IPlayer', "Sorry, stream is currently unavailable")

    if showDialog:
        pDialog = xbmcgui.DialogProgress()
        pDialog.create('IPlayer', 'Loading live stream info')
        xbmc.sleep(50)

    if showDialog: pDialog.update(50, 'Starting Stream')
    # build listitem to display whilst playing
    (sort, stream_id, label, thumb) = live_tv_channels[channel]
    listitem = xbmcgui.ListItem(label = label + ' - Live')
    listitem.setIconImage('defaultVideo.png')
    listitem.setThumbnailImage(os.path.join(get_thumb_dir(), thumb))

    play = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
    play.clear()
    play.add(url,listitem)
    player = xbmc.Player(xbmc.PLAYER_CORE_AUTO)
    player.play(play)
    if showDialog: pDialog.close()
Example #11
0
def download_subtitles(url):
    # Download and Convert the TTAF format to srt
    # SRT:
    #1
    #00:01:22,490 --> 00:01:26,494
    #Next round!
    #
    #2
    #00:01:33,710 --> 00:01:37,714
    #Now that we've moved to paradise, there's nothing to eat.
    #
    
    # TT:
    #<p begin="0:01:12.400" end="0:01:13.880">Thinking.</p>
    
    logging.info('subtitles at =%s' % url)
    outfile = os.path.join(SUBTITLES_DIR, 'iplayer.srt')
    fw = open(outfile, 'w')
    
    if not url:
        fw.write("1\n0:00:00,001 --> 0:01:00,001\nNo subtitles available\n\n")
        fw.close() 
        return
    
    txt = iplayer.httpget(url)
        
    p= re.compile('^\s*<p.*?begin=\"(.*?)\.([0-9]+)\"\s+.*?end=\"(.*?)\.([0-9]+)\"\s*>(.*?)</p>')
    i=0
    prev = None

    # some of the subtitles are a bit rubbish in particular for live tv
    # with lots of needless repeats. The follow code will collapse sequences
    # of repeated subtitles into a single subtitles that covers the total time
    # period. The downside of this is that it would mess up in the rare case
    # where a subtitle actually needs to be repeated 
    for line in txt.split('\n'):
        entry = None
        m = p.match(line)
        if m:
            start_mil = "%s000" % m.group(2) # pad out to ensure 3 digits
            end_mil   = "%s000" % m.group(4)
            
            ma = {'start'     : m.group(1), 
                  'start_mil' : start_mil[:3], 
                  'end'       : m.group(3), 
                  'end_mil'   : start_mil[:3], 
                  'text'      : m.group(5)}
    
            ma['text'] = ma['text'].replace('&amp;', '&')
            ma['text'] = ma['text'].replace('&gt;', '>')
            ma['text'] = ma['text'].replace('&lt;', '<')
            ma['text'] = ma['text'].replace('<br />', '\n')
            ma['text'] = ma['text'].replace('<br/>', '\n')
            ma['text'] = re.sub('<.*?>', '', ma['text'])
            ma['text'] = re.sub('&#[0-9]+;', '', ma['text'])
            #ma['text'] = ma['text'].replace('<.*?>', '')
    
            if not prev:
                # first match - do nothing wait till next line
                prev = ma
                continue
            
            if prev['text'] == ma['text']:
                # current line = previous line then start a sequence to be collapsed
                prev['end'] = ma['end']
                prev['end_mil'] = ma['end_mil']
            else:
                i += 1
                entry = "%d\n%s,%s --> %s,%s\n%s\n\n" % (i, prev['start'], prev['start_mil'], prev['end'], prev['end_mil'], prev['text'])
                prev = ma
        elif prev:
            i += 1
            entry = "%d\n%s,%s --> %s,%s\n%s\n\n" % (i, prev['start'], prev['start_mil'], prev['end'], prev['end_mil'], prev['text'])
            
        if entry: fw.write(entry)
    
    fw.close()    
    return outfile
def parseXML(url):
    xml = httpget(url)
    doc = dom.parseString(xml)
    root = doc.documentElement
    return root
Example #13
0
def download_subtitles(url):
    # Download and Convert the TTAF format to srt
    # SRT:
    #1
    #00:01:22,490 --> 00:01:26,494
    #Next round!
    #
    #2
    #00:01:33,710 --> 00:01:37,714
    #Now that we've moved to paradise, there's nothing to eat.
    #

    # TT:
    #<p begin="0:01:12.400" end="0:01:13.880">Thinking.</p>

    logging.info('subtitles at =%s' % url)
    outfile = os.path.join(SUBTITLES_DIR, 'iplayer.srt')
    fw = open(outfile, 'w')

    if not url:
        fw.write("1\n0:00:00,001 --> 0:01:00,001\nNo subtitles available\n\n")
        fw.close()
        return

    txt = iplayer.httpget(url)

    p = re.compile(
        '^\s*<p.*?begin=\"(.*?)\.([0-9]+)\"\s+.*?end=\"(.*?)\.([0-9]+)\"\s*>(.*?)</p>'
    )
    i = 0
    prev = None

    # some of the subtitles are a bit rubbish in particular for live tv
    # with lots of needless repeats. The follow code will collapse sequences
    # of repeated subtitles into a single subtitles that covers the total time
    # period. The downside of this is that it would mess up in the rare case
    # where a subtitle actually needs to be repeated
    for line in txt.split('\n'):
        entry = None
        m = p.match(line)
        if m:
            start_mil = "%s000" % m.group(2)  # pad out to ensure 3 digits
            end_mil = "%s000" % m.group(4)

            ma = {
                'start': m.group(1),
                'start_mil': start_mil[:3],
                'end': m.group(3),
                'end_mil': start_mil[:3],
                'text': m.group(5)
            }

            ma['text'] = ma['text'].replace('&amp;', '&')
            ma['text'] = ma['text'].replace('&gt;', '>')
            ma['text'] = ma['text'].replace('&lt;', '<')
            ma['text'] = ma['text'].replace('<br />', '\n')
            ma['text'] = ma['text'].replace('<br/>', '\n')
            ma['text'] = re.sub('<.*?>', '', ma['text'])
            ma['text'] = re.sub('&#[0-9]+;', '', ma['text'])
            #ma['text'] = ma['text'].replace('<.*?>', '')

            if not prev:
                # first match - do nothing wait till next line
                prev = ma
                continue

            if prev['text'] == ma['text']:
                # current line = previous line then start a sequence to be collapsed
                prev['end'] = ma['end']
                prev['end_mil'] = ma['end_mil']
            else:
                i += 1
                entry = "%d\n%s,%s --> %s,%s\n%s\n\n" % (
                    i, prev['start'], prev['start_mil'], prev['end'],
                    prev['end_mil'], prev['text'])
                prev = ma
        elif prev:
            i += 1
            entry = "%d\n%s,%s --> %s,%s\n%s\n\n" % (
                i, prev['start'], prev['start_mil'], prev['end'],
                prev['end_mil'], prev['text'])

        if entry: fw.write(entry)

    fw.close()
    return outfile
Example #14
0
def parseXML(url):
    xml = httpget(url)
    doc = dom.parseString(xml)
    root = doc.documentElement
    return root