def play_video(path):
"""
Play a video by the provided path.
:param path: str
"""
# if the previous two if statements dont hit then the path is a
# video path so modify the string and play it with the youtube plugin
###############
# the path to let videos be played by the youtube plugin
youtubePath='plugin://plugin.video.youtube/?action=play_video&videoid='
# remove the full webaddress to make youtube plugin work correctly
path=path.replace('https://youtube.com/watch?v=','')
# also check for partial webaddresses we only need the video id
path=path.replace('watch?v=','')
# add youtube path to path to make videos play with the kodi youtube plugin
path=youtubePath+path
# Create a playable item with a path to play.
play_item = xbmcgui.ListItem(path=path)
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
python类setResolvedUrl()的实例源码
def play_video(path):
"""
Play a video by the provided path.
:param path: str
"""
# Create a playable item with a path to play.
play_item = xbmcgui.ListItem(path=path)
vid_url = play_item.getfilename()
stream_url = resolve_url(vid_url)
if stream_url:
play_item.setPath(stream_url)
# Pass the item to the Kodi player.
print "in play video"
print play_item
xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)
# addon kicks in
def play_video(path):
"""
Play a video by the provided path.
:param path: str
"""
# Create a playable item with a path to play.
play_item = xbmcgui.ListItem(path=path)
vid_url = play_item.getfilename()
stream_url = resolve_url(vid_url)
if stream_url:
play_item.setPath(stream_url)
# Pass the item to the Kodi player.
print "in play video"
print play_item
xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)
# 002 start
#link = "http://www.vidsplay.com/wp-content/uploads/2017/04/alligator.mp4"
def _play_video(self):
vid = self.root.params['vid']
src = self.root.params['source']
v = Entry('video.get', vid, self.root.conn)
try:
v.set_info()
except:
self.root.gui.notify(self.root.gui._string(400524), '')
return
if 'files' in v.info.keys():
paths = {}
if src == _VK_VIDEO_SOURCE:
for k in v.info['files'].keys():
paths[int(k.split('_')[1])] = v.info['files'][k]
else:
v_url = v.info['player']
if src == _VK_VIDEO_SOURCE:
paths = self.root.parse_vk_player_html(v_url)
### ????? ?????? ??????? ?????????? ?? ????????
k = max(filter(lambda x: x <= _SETTINGS_MAX_RES, paths.keys()))
path = paths[k]
play_item = xbmcgui.ListItem(path = path)
xbmcplugin.setResolvedUrl(_addon_id, True, listitem = play_item)
def play_track(track_id, album_id):
media_url = session.get_media_url(track_id, album_id=album_id)
log("Playing: %s" % media_url)
disableInputstreamAddon = False
if not media_url.startswith('http://') and not media_url.startswith('https://') and \
not 'app=' in media_url.lower() and not 'playpath=' in media_url.lower():
# Rebuild RTMP URL
if KODI_VERSION >= (17, 0):
media_url = 'rtmp://%s' % media_url
disableInputstreamAddon = True
else:
host, tail = media_url.split('/', 1)
app, playpath = tail.split('/mp4:', 1)
media_url = 'rtmp://%s app=%s playpath=mp4:%s' % (host, app, playpath)
li = ListItem(path=media_url)
if disableInputstreamAddon:
# Krypton can play RTMP Audio Streams without inputstream.rtmp Addon
li.setProperty('inputstreamaddon', '')
mimetype = 'audio/flac' if session._config.quality == Quality.lossless and session.is_logged_in else 'audio/mpeg'
li.setProperty('mimetype', mimetype)
xbmcplugin.setResolvedUrl(plugin.handle, True, li)
def play_track_cut(track_id, cut_id, album_id):
media_url = session.get_media_url(track_id, cut_id=cut_id, album_id=album_id)
log("Playing Cut %s: %s" % (cut_id, media_url))
disableInputstreamAddon = False
if not media_url.startswith('http://') and not media_url.startswith('https://') and \
not 'app=' in media_url.lower() and not 'playpath=' in media_url.lower():
# Rebuild RTMP URL
if KODI_VERSION >= (17, 0):
media_url = 'rtmp://%s' % media_url
disableInputstreamAddon = True
else:
host, tail = media_url.split('/', 1)
app, playpath = tail.split('/mp4:', 1)
media_url = 'rtmp://%s app=%s playpath=mp4:%s' % (host, app, playpath)
li = ListItem(path=media_url)
if disableInputstreamAddon:
# Krypton can play RTMP Audio Streams without inputstream.rtmp Addon
li.setProperty('inputstreamaddon', '')
mimetype = 'audio/flac' if session._config.quality == Quality.lossless and session.is_logged_in else 'audio/mpeg'
li.setProperty('mimetype', mimetype)
xbmcplugin.setResolvedUrl(plugin.handle, True, li)
def router(paramstring):
params = dict(parse_qsl(paramstring[1:]))
if params:
if params['mode'] == 'play':
play_item = xbmcgui.ListItem(path=params['link'])
xbmcplugin.setResolvedUrl(__handle__, True, listitem=play_item)
else:
for stream in streams():
list_item = xbmcgui.ListItem(label=stream['name'], thumbnailImage=stream['thumb'])
list_item.setProperty('fanart_image', stream['thumb'])
list_item.setProperty('IsPlayable', 'true')
url = '{0}?mode=play&link={1}'.format(__url__, stream['link'])
xbmcplugin.addDirectoryItem(__handle__, url, list_item, isFolder=False)
xbmcplugin.endOfDirectory(__handle__)
# --------------------------------------------------------------------------------
# Main
# --------------------------------------------------------------------------------
def playTrack(asin):
content = trackPostUnicodeGetHLSPage('https://music.amazon.de/dmls/', asin)
temp_file_path = addonUserDataFolder
if forceDVDPlayer:
temp_file_path += "/temp.mp4"
else:
temp_file_path += "/temp.m3u8"
if xbmcvfs.exists(temp_file_path):
xbmcvfs.delete(temp_file_path)
m3u_temp_file = xbmcvfs.File(temp_file_path, 'w')
manifest_match = re.compile('manifest":"(.+?)"',re.DOTALL).findall(content)
if manifest_match:
m3u_string = manifest_match[0]
m3u_string = m3u_string.replace("\\n", os.linesep)
m3u_temp_file.write(m3u_string.encode("ascii"))
m3u_temp_file.close()
play_item = xbmcgui.ListItem(path=temp_file_path)
play_item = setPlayItemInfo(play_item)
xbmcplugin.setResolvedUrl(pluginhandle, True, listitem=play_item)
def play_vod(video_id):
"""
Play a video by the provided path.
:param path: str
:return: None
"""
f = urllib2.urlopen('http://www.zhanqi.tv/api/static/video.videoid/{video_id}.json?_v='.format(video_id=video_id))
obj = json.loads(f.read())
#path = 'http://dlhls.cdn.zhanqi.tv/zqlive/{video}.m3u8'.format(video=obj['data']['videoIdKey']);
#path = 'http://ebithdl.cdn.zhanqi.tv/zqlive/{video}.flv'.format(video=obj['data']['videoIdKey'])
path = '{VideoUrl}{VideoID}'.format(VideoUrl=obj['data']['flashvars']['VideoUrl'], VideoID=obj['data']['flashvars']['VideoID'])
#xbmc.log("------------------", 1)
#xbmc.log(path, 1)
#xbmc.log("------------------", 1)
play_item = xbmcgui.ListItem(path=path, thumbnailImage=obj['data']['bpic'])
play_item.setInfo(type="Video", infoLabels={"Title":obj['data']['title']})
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
# directly play the item.
xbmc.Player().play(path, play_item)
def play_video(room_id):
"""
Play a video by the provided path.
:param path: str
:return: None
"""
f = urllib2.urlopen('http://www.zhanqi.tv/api/static/live.roomid/{room_id}.json?sid='.format(room_id=room_id))
obj = json.loads(f.read())
#path = 'http://dlhls.cdn.zhanqi.tv/zqlive/{video}.m3u8'.format(video=obj['data']['videoIdKey']);
#path = 'http://ebithdl.cdn.zhanqi.tv/zqlive/{video}.flv'.format(video=obj['data']['videoIdKey'])
path = 'rtmp://wsrtmp.load.cdn.zhanqi.tv/zqlive/{video}'.format(video=obj['data']['videoIdKey'])
play_item = xbmcgui.ListItem(path=path, thumbnailImage=obj['data']['bpic'])
play_item.setInfo(type="Video", infoLabels={"Title":obj['data']['title']})
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
# directly play the item.
xbmc.Player().play(path, play_item)
def _set_resolved_url(self, context, base_item, succeeded=True):
item = xbmc_items.to_item(context, base_item)
item.setPath(base_item.get_uri())
xbmcplugin.setResolvedUrl(self.handle, succeeded=succeeded, listitem=item)
"""
# just to be sure :)
if not isLiveStream:
tries = 100
while tries>0:
xbmc.sleep(50)
if xbmc.Player().isPlaying() and xbmc.getCondVisibility("Player.Paused"):
xbmc.Player().pause()
break
tries-=1
"""
def play_video(self, vid, size=None):
try:
play_info = self.eyny.get_video_link(vid, size)
except ValueError as e:
xbmcgui.Dialog().notification(
heading='Error',
message=unicode(e))
return
if size is None and len(play_info['sizes']) > 1:
ret = int(xbmcgui.Dialog().select(
'Please choose quality',
map(str, play_info['sizes'])))
self.play_video(vid, ret)
play_item = xbmcgui.ListItem(
path=self.build_request_url(
play_info['video'],
play_info['current_url']))
play_item.setProperty("IsPlayable", "true")
play_item.setInfo(
type="Video",
infoLabels={"Title": play_info['title']})
xbmcplugin.setResolvedUrl(self.addon_handle, True, listitem=play_item)
def play(data):
try:
from plexnet import plexobjects
plexObject = plexobjects.PlexObject.deSerialize(base64.urlsafe_b64decode(data))
if plexObject.type == 'track':
listitem = playTrack(plexObject)
elif plexObject.type in ('episode', 'movie', 'clip'):
listitem = playVideo(plexObject)
except:
util.ERROR()
xbmcplugin.setResolvedUrl(HANDLE, False, None)
return
xbmcplugin.setResolvedUrl(HANDLE, True, listitem)
def start_info_actions(infos, params):
for info in infos:
if info == 'autocomplete':
listitems = AutoCompletion.get_autocomplete_items(params["id"], params.get("limit", 10))
elif info == 'selectautocomplete':
if params.get("handle"):
xbmcplugin.setResolvedUrl(handle=int(params.get("handle")),
succeeded=False,
listitem=xbmcgui.ListItem())
try:
window = xbmcgui.Window(10103)
except Exception:
return None
window.setFocusId(300)
get_kodi_json(method="Input.SendText",
params='{"text":"%s", "done":false}' % params.get("id"))
return None
# xbmc.executebuiltin("SendClick(103,32)")
pass_list_to_skin(data=listitems,
handle=params.get("handle", ""),
limit=params.get("limit", 20))
def _set_resolved_url(self, context, base_item, succeeded=True):
item = xbmc_items.to_item(context, base_item)
item.setPath(base_item.get_uri())
xbmcplugin.setResolvedUrl(context.get_handle(), succeeded=succeeded, listitem=item)
"""
# just to be sure :)
if not isLiveStream:
tries = 100
while tries>0:
xbmc.sleep(50)
if xbmc.Player().isPlaying() and xbmc.getCondVisibility("Player.Paused"):
xbmc.Player().pause()
break
tries-=1
"""
def play_video(episode_url, thumbnail):
episodeDetails = {}
for i in range(int(this.getSetting('loginRetries')) + 1):
episodeDetails = get_media_info(episode_url)
if episodeDetails and episodeDetails.get('StatusCode', 0) == 1:
break
else:
login()
if episodeDetails and episodeDetails.get('StatusCode', 0) == 1:
media_url = episodeDetails['MediaReturnObj']['uri']
common.log(episodeDetails['MediaReturnObj']['live'] == False)
if not episodeDetails['MediaReturnObj']['live']:
# re-enable bw limiting in v0.1.12. Streams has very variable rate
# and without this limits, the stream will drop.
media_url = media_url.replace('&b=100-1000', '&b=100-6000')
server_override_enable = this.getSetting('server_override_enable')
server_override_url = this.getSetting('server_override_url')
common.log('#'*30)
common.log(server_override_url)
common.log(server_override_enable)
if server_override_enable.lower() == 'true' and server_override_url:
media_url = media_url.replace('http://o2-i.',
server_override_url)
liz = xbmcgui.ListItem(name, iconImage="DefaultVideo.png",
thumbnailImage=thumbnail, path=media_url)
liz.setInfo(type="Video", infoLabels={"Title": name})
liz.setProperty('IsPlayable', 'true')
return xbmcplugin.setResolvedUrl(thisPlugin, True, liz)
else:
default_msg = 'Subscription is already expired \
or the item is not part of your \
subscription.'
status_msg = episodeDetails.get('StatusMessage', default_msg)
xbmc.executebuiltin('Notification(%s, %s)' % \
('Media Error', status_msg))
def playEpisode(url):
cleanCookies(False)
errorCode = -1
episodeDetails = {}
episode = url.split('/')[0]
for i in range(int(setting('loginRetries')) + 1):
episodeDetails = getMediaInfo(episode)
if episodeDetails and 'errorCode' in episodeDetails and episodeDetails['errorCode'] == 0 and 'data' in episodeDetails:
break
else:
login()
if episodeDetails and 'errorCode' in episodeDetails and episodeDetails['errorCode'] == 0 and 'data' in episodeDetails:
if 'preview' in episodeDetails['data'] and episodeDetails['data']['preview'] == True:
showNotification(lang(50207), lang(50002))
else:
if 'StatusMessage' in episodeDetails and episodeDetails['StatusMessage'] != '':
showNotification(episodeDetails['StatusMessage'], lang(57000))
url = episodeDetails['data']['uri']
# url = url.replace('=/', '=%2f')
liz = xbmcgui.ListItem(name, iconImage = "DefaultVideo.png", thumbnailImage = thumbnail, path = url)
liz.setInfo( type = "Video", infoLabels = { "Title": name } )
liz.setProperty('IsPlayable', 'true')
return xbmcplugin.setResolvedUrl(thisPlugin, True, liz)
else:
if (not episodeDetails) or (episodeDetails and 'errorCode' in episodeDetails and episodeDetails['errorCode'] != 0):
if 'StatusMessage' in episodeDetails:
showNotification(episodeDetails['StatusMessage'])
else:
showNotification(lang(57001), lang(57000))
return False
def play_audio(url):
# set the path of the stream to a list item
play_item = xbmcgui.ListItem(path=url)
# the list item is ready to be played by Kodi
xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)
def next_track(self):
'''special entry which tells the remote connect player to move to the next track'''
# move to next track
self.sp.next_track()
# play next track
xbmc.sleep(100)
cur_playback = self.sp.current_playback()
trackdetails = cur_playback["item"]
url, li = parse_spotify_track(trackdetails, silenced=True)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, li)
def _set_resolved_url(self, context):
"""
Resolve a playable URL
:param context: context object
:type context: PlayContext
"""
self.log_debug('Resolving URL from {0}'.format(str(context)))
if context.play_item is None:
list_item = xbmcgui.ListItem(path=context.path)
else:
list_item = self.create_list_item(context.play_item)
xbmcplugin.setResolvedUrl(self._handle, context.succeeded, list_item)
def stream_url(params):
url = params.get('url',None)
common.plugin.log("stream_url() url:%s" % (url))
if not url:
popup("Impossible de lire ce flux")
common.plugin.log_error("Impossible de lire ce flux")
return
liz = xbmcgui.ListItem(path=url)
return xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=liz)
def play(self, video_id):
"""
Plays a video by Video ID
:param target: Video ID
:type target: string
"""
self.utils.log('Play video: ' + str(video_id))
use_inputstream = self.utils.use_inputstream()
self.utils.log('Using inputstream: ' + str(use_inputstream))
streams = self.get_stream_urls(video_id)
for stream in streams:
play_item = xbmcgui.ListItem(
path=self.get_m3u_url(streams.get(stream)))
if use_inputstream is True:
# pylint: disable=E1101
play_item.setContentLookup(False)
play_item.setMimeType('application/vnd.apple.mpegurl')
play_item.setProperty(
'inputstream.adaptive.stream_headers',
'user-agent=' + self.utils.get_user_agent())
play_item.setProperty(
'inputstream.adaptive.manifest_type', 'hls')
play_item.setProperty('inputstreamaddon',
'inputstream.adaptive')
return xbmcplugin.setResolvedUrl(
self.plugin_handle,
True,
play_item)
return False
def set_resolved_url(list_item):
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, list_item)
def play_resolved_url(url):
_log("play_resolved_url ["+url+"]")
listitem = xbmcgui.ListItem(path=url)
listitem.setProperty('IsPlayable', 'true')
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
def play_resolved_url(url):
_log("play_resolved_url ["+url+"]")
listitem = xbmcgui.ListItem(path=url)
listitem.setProperty('IsPlayable', 'true')
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
def play_video(path):
"""
Play a video by the provided path.
:param path: str
"""
# Create a playable item with a path to play.
play_item = xbmcgui.ListItem(path=path)
vid_url = play_item.getfilename()
stream_url = resolve_url(vid_url)
if stream_url:
play_item.setPath(stream_url)
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)
# addon kicks in
def play_video(path):
"""
Play a video by the provided path.
:param path: str
"""
# Create a playable item with a path to play.
play_item = xbmcgui.ListItem(path=path)
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)
# addon kicks in
def play_video(path):
"""
Play a video by the provided path.
:param path: str
"""
# Create a playable item with a path to play.
play_item = xbmcgui.ListItem(path=path)
vid_url = play_item.getfilename()
stream_url = resolve_url(vid_url)
if stream_url:
play_item.setPath(stream_url)
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)
def playvideo(name,url,iconimage,description):
r='"mp4".+?".+?"url":"(.+?)"}'
link=OPEN_URL(url)
match=re.compile(r).findall(link)
amount = len(match)-1
URL=match[amount]
print URL
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name,"Plot":description} )
liz.setProperty("IsPlayable","true")
liz.setPath(URL)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
def PLAY_STREAM(name,url,iconimage):
quality = int(__settings__.getSetting('live_stream'))
if len(url)>4:
STREAM=url
else:
SoapMessage=TEMPLATE(url,'itv'+url.replace('sim',''))
headers={'Content-Length':'%d'%len(SoapMessage),'Content-Type':'text/xml; charset=utf-8','Host':'mercury.itv.com','Origin':'http://www.itv.com','Referer':'http://www.itv.com/Mercury/Mercury_VideoPlayer.swf?v=null','SOAPAction':"http://tempuri.org/PlaylistService/GetPlaylist",'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36'}
res, response = http.request("http://mercury.itv.com/PlaylistService.svc", 'POST', headers=headers, body=SoapMessage)
rtmp=re.compile('<MediaFiles base="(.+?)"').findall(response)[0]
if 'CITV' in name:
r='CDATA\[(citv.+?)\]'
else:
r='CDATA\[(itv.+?)\]'
playpath=re.compile(r,re.DOTALL).findall(response)
if (quality == 0):
playpath = playpath[0]
elif (quality == 1):
playpath = playpath[1]
elif (quality == 2):
playpath = playpath[2]
elif (quality == 3):
playpath = playpath[3]
elif (quality == 4):
playpath = playpath[4]
STREAM=rtmp+' playpath='+playpath+' swfUrl=http://www.itv.com/mediaplayer/ITVMediaPlayer.swf live=true timeout=10 swfvfy=true'
liz = xbmcgui.ListItem(name, iconImage='DefaultVideo.png', thumbnailImage=iconimage)
liz.setInfo(type='Video', infoLabels={'Title':name})
liz.setProperty("IsPlayable","true")
liz.setPath(STREAM)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)