def play_video(self, item, player=None): try: # videos are always type video item['info_type'] = 'video' except TypeError: pass # not a dict item = self._listitemify(item) item.set_played(True) if player: _player = xbmc.Player(player) else: _player = xbmc.Player() _player.play(item.get_path(), item.as_xbmc_listitem()) return [item]
def playLecture(courseShortName, lecture_id): username = plugin.get_setting('username') password = plugin.get_setting('password') if isSettingsBad(username, password): return [] sylabus = getSylabus(courseShortName, username, password) if sylabus is None: return [] sections = sylabus['sections'] for lecture_contents in sections.values(): sections = lecture_contents["sections"] for section_name, section in sections.iteritems(): if section["lecture_id"] == lecture_id: plugin.log.debug("FOUND!: %s", section_name.encode('ascii', 'ignore')) cookies = getClassCookies(courseShortName, username, password) path = getContentURL(section, cookies) if path is not None: plugin.log.info('Handle: ' + str(plugin.handle)) plugin.set_resolved_url(path) if "Subtitle" in section['resources']: player = xbmc.Player() while not player.isPlaying(): time.sleep(1) player.setSubtitles(section['resources']["Subtitle"]) break
def _add_subtitles(self, subtitles): '''Adds subtitles to playing video. :param subtitles: A URL to a remote subtitles file or a local filename for a subtitles file. .. warning:: You must start playing a video before calling this method or it will loop for an indefinite length. ''' # This method is named with an underscore to suggest that callers pass # the subtitles argument to set_resolved_url instead of calling this # method directly. This is to ensure a video is played before calling # this method. player = xbmc.Player() monitor = xbmc.Monitor() for _ in range(30): if player.isPlaying(): break if monitor.abortRequested(): return monitor.waitForAbort(1) else: raise Exception('No video playing. Aborted after 30 seconds.') player.setSubtitles(subtitles)
def play_episode(url): plugin.log.debug(url) resolution = plugin.get_setting('quality', str) use_mp4_url = plugin.get_setting('mp4_url', bool) if use_mp4_url: plugin.log.debug('using mp4') info = scraper.extractVideoUrl(url) else: plugin.log.debug('using not mp4') info = scraper.extractStreamUrl(url) avail_resolutions = info['videos'].keys() if not resolution in avail_resolutions: resolution = avail_resolutions[0] video = info['videos'][resolution] if use_mp4_url: plugin.log.debug('about to play using ' + video['url']) plugin.play_video({'label': info['title'], 'path': video['url']}) else: flashVer = 'WIN 11,6,602,180' swfUrl = 'http://www.ondemandkorea.com/player/jw6.2/jwplayer.flash.swf' rtmp_url = "%s app=%s swfUrl=%s pageUrl=%s playpath=%s" % ( video['tcUrl'], video['app'], swfUrl, url, video['playpath']) from xbmcswift2 import xbmc xbmc.Player().play(rtmp_url) return plugin.finish(None, succeeded=False)
def play_video(eid, server): html = fetch_html('/vids/play/%s/%s' % (eid, server)) urls = joonmedia.extract_video_link(html) if len(urls) > 0: # select first video plugin.log.debug(urls[0]) quality = plugin.get_setting('qualityPref', int) info = getVideoInfo(urls[0], quality=quality, resolve_redirects=True) if info is None: plugin.log.warning('Fail to extract') return None streams = info.streams() plugin.log.debug("num of streams: %d" % len(streams)) from xbmcswift2 import xbmc, xbmcgui pl = xbmc.PlayList( xbmc.PLAYLIST_VIDEO ) pl.clear() for stream in streams: li = xbmcgui.ListItem(stream['title'], iconImage="DefaultVideo.png") li.setInfo( 'video', { "Title": stream['title'] } ) pl.add(stream['xbmc_url'], li) xbmc.Player().play(pl) else: plugin.log.warning('Unsupported') return plugin.finish(None, succeeded=False) # immediate return
def playmovie(url, label=''): """ play movie """ result = _http(baseurl + url) mp4str = re.search(r'<video id="player".*?<source src="(.*?)"', result, re.S) if mp4str: playurl = mp4str.group(1) plugin.play_video({ 'label': label, 'is_playable': True, 'path': playurl }) flashvar = re.search(r'var flashvars = \{(.*?)\};', result, re.S) if flashvar: rtmpstr = re.search(r'src : "(rtmp.*?)"', flashvar.group(1)) title = re.search(r'label : "(.*?)"', flashvar.group(1)) swfurl = re.search(r'var cmp_url = "(.*?)"', result) rtmpurl = re.search(r'(rtmp://.*?/.*?)/(.*)', rtmpstr.group(1)) pageurl = baseurl + url playurl = rtmpurl.group(1) + ' playpath=mp4:' + rtmpurl.group( 2) + ' pageUrl=' + pageurl + ' swfUrl=' + swfurl.group(1) listitem = xbmcgui.ListItem() listitem.setInfo(type="Video", infoLabels={'Title': title.group(1)}) xbmc.Player().play(playurl, listitem)
def play_video(self, item, player=xbmc.PLAYER_CORE_DVDPLAYER): if not hasattr(item, 'as_xbmc_listitem'): if 'info_type' not in item.keys(): item['info_type'] = 'video' item = xbmcswift2.ListItem.from_dict(**item) item.set_played(True) xbmc.Player(player).play(item.get_path(), item.as_xbmc_listitem()) return [item]
def playvideo(vid, name, image): quality = int(plugin.addon.getSetting('movie_quality')) urls = video_from_vid(vid, level=quality) stackurl = 'stack://' + ' , '.join(urls) list_item = xbmcgui.ListItem(name, thumbnailImage=image) list_item.setInfo('video', {'title': name}) xbmc.Player().play(stackurl, list_item)
def playvideo(url, name, image): level = int(plugin.addon.getSetting('resolution')) urls = video_from_url(url, level=level) stackurl = 'stack://' + ' , '.join(urls) list_item = xbmcgui.ListItem(name, thumbnailImage=image) list_item.setInfo('video', {'title': name}) xbmc.Player().play(stackurl, list_item)
def jrplay_url(url): result = jrnaverm.parseVideoPage( url ) nurl = result['path']+"|User-Agent="+jrnaverm.BrowserAgent from xbmcswift2 import xbmc, xbmcgui li = xbmcgui.ListItem(result['title'], iconImage="defaultVideo.png") li.setInfo('video', {"Title": result['title']}) xbmc.Player().play(nurl, li) return plugin.finish(None, succeeded=False)
def list_parts(category, video, part): playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() for item in bili.get_video_parts2(category, video, part): playlist.add(item['link']) xbmc.Player().play(playlist)
def video_url(url): proxy = None if plugin.get_setting('useProxy', bool): proxy = plugin.get_setting('proxyServer', unicode) print "Proxy=" + proxy data = gomm.parseProg(url, proxy=proxy) if data is None: if not gomtv_login(): return data = gomm.parseProg(url, proxy=proxy) if data is None: xbmcgui.Dialog().ok(_L(30010), _L(30013)) return if len(data) == 1: video = data[0] url = video['url'] + "|Referer=" + url li = xbmcgui.ListItem(video['title'], iconImage="DefaultVideo.png") li.setInfo('video', {"Title": video['title']}) xbmc.Player().play(url, li) elif plugin.get_setting('plistDir', bool): items = [{ 'label': item['title'], 'path': item['url'] + "|Referer=" + url, 'thumbnail': "DefaultVideo.png", 'is_playable': True } for item in data] return plugin.finish(items) else: pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) pl.clear() for item in data: li = xbmcgui.ListItem(item['title'], iconImage="DefaultVideo.png") li.setInfo('video', {"Title": item['title']}) pl.add(item['url'] + "|Referer=" + url, li) xbmc.Player().play(pl) return plugin.finish(None, succeeded=False)
def playvideo(tvId, vid, title, pic): sel = int(plugin.addon.getSetting('resolution')) m3u8set = plugin.addon.getSetting('m3u8') playmode = True if m3u8set == 'true' else None urls = video_from_vid(tvId, vid, level=sel, m3u8=playmode) if urls is None: xbmcgui.Dialog().ok(plugin.addon.getAddonInfo('name'), '无法播放此视频') return if len(urls) > 1: stackurl = 'stack://' + ' , '.join(urls) list_item = xbmcgui.ListItem(title, thumbnailImage=pic) list_item.setInfo('video', {'title': title}) xbmc.Player().play(stackurl, list_item) else: plugin.set_resolved_url(urls[0])
def play_path(userid, path, md5, name=None): params = dict((k, v[0]) for k, v in plugin.request.args.items()) subtitle = params.get('subtitle') if subtitle: subtitle = [ get_dlink(userid, subtitle) + '|User-Agent=AppleCoreMedia/1.0.0.9B206 (iPad; U; CPU OS 5_1_1 like Mac OS X; zh_cn)' ] # noqa else: subtitle = [] # api = get_api(userid) # item = api.get_filemetas(path)['info'][0] # url = item['dlink'] + '|User-Agent=AppleCoreMedia/1.0.0.9B206 (iPad; U; CPU OS 5_1_1 like Mac OS X; zh_cn)' # noqa url = get_dlink( userid, path ) + '|User-Agent=AppleCoreMedia/1.0.0.9B206 (iPad; U; CPU OS 5_1_1 like Mac OS X; zh_cn)' # noqa api = get_api(userid) api_res = api.get_subtitle(md5, name or '', path) if api_res['total_num'] > 0: for sub_record in api_res['records']: subtitle.insert(0, sub_record['file_path']) params = dict((k, v[0]) for k, v in plugin.request.args.items()) if 'resolved' in params: plugin.set_resolved_url(url) if subtitle: player = xbmc.Player() for _ in xrange(30): if player.isPlaying(): break time.sleep(1) else: raise Exception('No video playing. Aborted after 30 seconds.') for surl in subtitle: # print '$'*50, surl player.setSubtitles(surl) # player.setSubtitleStream(0) else: listitem = xbmcgui.ListItem(name) player = myplayer.Player() player.play(url, listitem, sublist=subtitle)
def disc_play_all(disc_id): data = api.request( 'disc.getInfo', { 'id': disc_id, 'video_sources': _get_supported_sources(), 'video_status': 1 }) items = [ _make_video_item(video) for video in data['disc']['videos']['video'] ] playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() for item in items: listitem = ListItem.from_dict(**item) playlist.add(item['path'], listitem.as_xbmc_listitem()) player = xbmc.Player() player.playPlaylist(playlist)
def playmovie(url, source='youku'): """ play movie """ playutil = PlayUtil(url, source) movurl = getattr(playutil, source, playutil.notsup)() if not movurl: xbmcgui.Dialog().ok('提示框', '解析地址异常,无法播放') return if 'not support' in movurl: xbmcgui.Dialog().ok('提示框', '不支持的播放源,目前支持youku/sohu/qq/iqiyi/pps/letv/tudou') return if 'cancel' in movurl: return listitem = xbmcgui.ListItem() listitem.setInfo(type="Video", infoLabels={'Title': 'c'}) xbmc.Player().play(movurl, listitem)
def playLecture(courseShortName, lecture_id): username = plugin.get_setting('username') password = plugin.get_setting('password') if isSettingsBad(username, password): return [] sylabus = getSylabus(courseShortName, username, password) if sylabus is None: return [] sections = sylabus['sections'] for lecture_contents in sections.values(): sections = lecture_contents["sections"] for section_name, section in sections.iteritems(): if section["lecture_id"] == lecture_id: print "FOUND!: %s" % section_name.encode('ascii', 'ignore') class_cookies = getClassCookieOrLogin(username, password, courseShortName) cookies = '&'.join( ["%s=%s" % (x["name"], x["value"]) for x in class_cookies]) cookies_str = urllib.urlencode({'Cookie': cookies}) path = getContentURL(section, courseShortName, username, password, cookies_str) if path is not None: plugin.log.info('Handle: ' + str(plugin.handle)) ret = plugin.set_resolved_url(path) if "Subtitle" in section['resources']: player = xbmc.Player() while not player.isPlaying(): time.sleep(1) player.setSubtitles(section['resources']["Subtitle"]) # return ret break
def play_video(url): plugin.log.debug(url) quality = plugin.get_setting('qualityPref', int) info = getVideoInfo(url, quality=quality, resolve_redirects=True) if info: streams = info.streams() plugin.log.debug("num of streams: %d" % len(streams)) from xbmcswift2 import xbmc, xbmcgui pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) pl.clear() for stream in streams: li = xbmcgui.ListItem(stream['title'], iconImage="DefaultVideo.png") li.setInfo('video', {"Title": stream['title']}) pl.add(stream['xbmc_url'], li) xbmc.Player().play(pl) else: plugin.log.warning('Fail to extract') plugin.play_video({'path': url, 'is_playable': True}) return plugin.finish(None, succeeded=False)
def player(url, gcid, cid, title, finalurl=False): ''' play video, add subtitle ''' if not finalurl: url = xl.urlopen(url, redirect=False) # cks = dict((ck.name, ck.value) for ck in xl.cookiejar) cks = ['%s=%s' % (ck.name, ck.value) for ck in xl.cookiejar] movurl = '%s|%s&Cookie=%s' % (url, urllib.urlencode( xl.headers), urllib2.quote('; '.join(cks))) # for ck in xl.cookiejar: # print ck.name, ck.value listitem = xbmcgui.ListItem(label=title) listitem.setInfo(type="Video", infoLabels={'Title': title}) player = xbmc.Player() player.play(movurl, listitem) surl = '' subtinfo = '{0}/subtitle/list?gcid={1}&cid={2}&userid={3}&t={4}'.format( cloudurlpre, gcid, cid, xl.userid, cachetime) subtinfo = '%s|%s&Cookie=%s' % (subtinfo, urllib.urlencode( xl.headers), urllib2.quote('; '.join(cks))) subtitle = xl.urlopen(subtinfo) sinfos = json.loads(subtitle) # print sinfos surls = '' if 'sublist' in sinfos and len(sinfos['sublist']): surls = [sinfo['surl'] for sinfo in sinfos['sublist']] if surls: for _ in xrange(30): if player.isPlaying(): break time.sleep(1) else: raise Exception('No video playing. Aborted after 30 seconds.') xl.headers.pop('Accept-encoding') for surl in surls: player.setSubtitles( '%s|%s&Cookie=%s' % (surl, urllib.urlencode( xl.headers), urllib2.quote('; '.join(cks))))
def list_videos(category, video): videos = bili.get_video_paths(category, video) if len(videos) > 1: dir_list = [{ 'label': item['title'], 'thumbnail': item['thumbnail'], 'path': plugin.url_for('list_parts', category=category, video=item['published'], part=item['part']) } for item in videos] else: playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() for item in bili.get_video_parts(category, video, '直接播放'): playlist.add(item['link']) xbmc.Player().play(playlist) return dir_list
else: notify(e.localized) except Exception as e: plugin.log.exception(e) notify(lang(40410)) finally: plugin.close_storages() return False if __name__ == '__main__': sleep(5000) safe_update_library() next_run = None while not abort_requested(): now = datetime.datetime.now() update_on_demand = plugin.get_setting('update-library', bool) if not next_run: next_run = now next_run += datetime.timedelta(hours=12) plugin.log.info("Scheduling next library update at %s" % next_run) elif now > next_run and not xbmc.Player().isPlaying( ) or update_on_demand: updated = safe_update_library() if update_on_demand: plugin.set_setting('update-library', False) if updated: plugin.refresh_container() next_run = None sleep(1000)
plugin = Plugin() my_stations = plugin.get_storage('my_stations.json', file_format='json') found = False if plugin.get_setting('autostart', bool): for station in my_stations.values(): if 'autostart' in station: found = True plugin.log.info("Play startup radio station: %s" % station['name']) listitem = xbmcgui.ListItem(station['name']) listitem.setArt({'thumb': station['thumbnail']}) listitem.setRating("radio.de", float(station.get('rating', '0.0'))) listitem.setInfo( 'music', { 'title': station['name'], 'genre': station['genre'], 'size': station['bitrate'], 'comment': station['current_track'] }) xbmc.Player().play(item=station['stream_url'], listitem=listitem) if not found: plugin.notify(plugin.get_string( Strings['no-station-notification']).encode('utf-8'), delay=25000, image=plugin.addon.getAddonInfo('path') + "/icon.png")
def watch_broadcast(userId, broadNo): from xbmcswift2 import xbmc url = afreeca.extractBroadUrl(userId, broadNo) xbmc.Player().play(url) return plugin.finish(None, succeeded=False)
def launch_game(self, game_id): import time import xbmcgui player = xbmc.Player() if player.isPlayingVideo(): player.stop() if self.plugin.get_setting('last_run', str): xbmc.audioSuspend() xbmc.executebuiltin("Dialog.Close(busydialog)") xbmc.executebuiltin("Dialog.Close(notification)") if os.path.isfile("/storage/moonlight/aml_decoder.stats"): os.remove("/storage/moonlight/aml_decoder.stats") self.config_helper.configure() if self.plugin.get_setting('last_run', str): sp = subprocess.Popen( ["moonlight", "stream", "-app", game_id, "-logging"], cwd="/storage/moonlight", env={'LD_LIBRARY_PATH': '/storage/moonlight'}, shell=False, preexec_fn=os.setsid) else: sp = subprocess.Popen( [ "moonlight", "stream", "-app", game_id, "-logging", "-delay", "10" ], cwd="/storage/moonlight", env={'LD_LIBRARY_PATH': '/storage/moonlight'}, shell=False, preexec_fn=os.setsid) subprocess.Popen([ '/storage/.kodi/addons/script.luna/resources/lib/launchscripts/osmc/moonlight-heartbeat.sh' ], shell=False) if not self.plugin.get_setting('last_run', str): xbmc.Player().play( '/storage/.kodi/addons/script.luna/resources/statics/loading.mp4' ) time.sleep(8) xbmc.audioSuspend() time.sleep(2.5) xbmc.Player().stop() self.plugin.set_setting('last_run', game_id) subprocess.Popen(['killall', '-STOP', 'kodi.bin'], shell=False) sp.wait() main = "pkill -x moonlight" heartbeat = "pkill -x moonlight-heart" print(os.system(main)) print(os.system(heartbeat)) xbmc.audioResume() if os.path.isfile("/storage/moonlight/aml_decoder.stats"): with open("/storage/moonlight/aml_decoder.stats") as stat_file: statistics = stat_file.read() if "StreamStatus = -1" in statistics: confirmed = xbmcgui.Dialog().yesno( 'Stream initialisation failed...', 'Try running ' + game_id + ' again?', nolabel='No', yeslabel='Yes') if confirmed: self.launch_game(game_id) else: xbmcgui.Dialog().ok('Stream statistics', statistics) game_controller = RequiredFeature('game-controller').request() game_controller.refresh_games() del game_controller xbmc.executebuiltin('Container.Refresh') xbmcgui.Dialog().notification( 'Information', game_id + ' is still running on host. Resume via Luna, ensuring to quit before the host is restarted!', xbmcgui.NOTIFICATION_INFO, False)
def watch_broadcast(bno): from xbmcswift2 import xbmc url = afreecam.getStreamUrlByBroadNum(int(bno)) url += "|User-Agent=" + afreecam.IPadAgent xbmc.Player().play(url) return plugin.finish(None, succeeded=False)
def onInit(self): self.list = self.getControl( STATION_LIST_ID ) #items = [] station_list = [] Streams = stations.getStations(_sort_stations) idx = 0 print (xbmc.PLAYLIST_VIDEO) print (xbmc.PLAYLIST_MUSIC) audio_playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) video_playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) audio_playlist.clear() video_playlist.clear() for Station in Streams: Address = Station['Address'] Country = Station['Country'] Director= Station['Director'] Email = Station['Email'] Icon = Station['Icon'] Name = Station['Name'] Phone = Station['Phone'] Schedule= Station['Schedule'] Url = Station['Url'] Verified= Station['Verified'] WebPage = Station['WebPage'] Video = Station['Video'] if 'false' == Verified: continue order = str(idx).zfill(2) li = xbmcgui.ListItem(order + ") " + Name, Name) li.setInfo('music', {'Title': Name}) li.setProperty('Address', Address) li.setProperty('Country', Country) li.setProperty('Director', Director) li.setProperty('Email', Email) li.setProperty('Icon', Icon) li.setProperty('Name', Name) li.setProperty('Phone', Phone) li.setProperty('Url', Url) li.setProperty('WebPage', WebPage) li.setProperty('Schedule', Schedule) li.setProperty('Id', str(idx)) li.setProperty('Video', Video) xlistitem = xbmcgui.ListItem(Name, iconImage=Icon, path=Url) if ("true" == Video): xlistitem.setInfo( "video", { "Title": Name } ) video_playlist.add(Url, xlistitem) else: xlistitem.setInfo( "audio", { "Title": Name } ) audio_playlist.add(Url, xlistitem) station_list.append(li) idx = idx + 1; self.list.addItems( station_list ) self.focusedID = _last_station_id self.stationsCount = len(Streams) self.list.selectItem(self.focusedID) #self.player = xbmc.Player(xbmc.PLAYER_CORE_AUTO) self.player = xbmc.Player() if (_auto_start): self.runPlayer(_last_station_id) else: self.list.selectItem(_last_focused_station_id)
def episode(episode_url): video_link = wco.get_episode(episode_url) plugin.log.info(video_link) if video_link: xbmc.Player().play(video_link) pass
def startChannel(): channelid = __settings__.getSetting('start_channelid') link = link = fptplay.getLinkById(channelid, __settings__.getSetting('quality')) xbmc.Player().play(link)