def hasMedia(self, count_link_images=False): images = False video = False for l in self.links(): if l.isImage(): images = True if count_link_images and l.textIsImage(): images = True elif StreamExtractor.mightHaveVideo(l.url) or StreamExtractor.mightHaveVideo(l.text): video = True if not images: images = bool(self.imageURLs()) return images, video
def handlePush(data, from_gui=False): if not from_gui and checkForWindow(): # Do nothing if the window is open return False if data.get("type") == "link": url = data.get("url", "") if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info["title"] or "?") idx = xbmcgui.Dialog().select(util.T(32091), vlist) if idx < 0: return vid.selectStream(idx) util.LOG(vid.streamURL()) # TODO: REMOVE StreamUtils.play(vid.streamURL()) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == "video" or media == "music": StreamUtils.play(url) return True elif media == "image": import gui gui.showImage(url) return True elif data.get("type") == "file": if data.get("file_type", "").startswith("image/"): import gui gui.showImage(data.get("file_url", "")) return True elif data.get("file_type", "").startswith("video/") or data.get("file_type", "").startswith("audio/"): StreamUtils.play(data.get("file_url", "")) return True elif data.get("type") == "note": import gui gui.showNote(data.get("body", "")) return True elif data.get("type") == "list": import gui gui.showList(data) return True elif data.get("type") == "address": import urllib xbmc.executebuiltin( "XBMC.RunScript(special://home/addons/service.pushbullet.com/lib/maps.py,service.pushbullet.com,%s,None,)" % urllib.quote(data.get("address", "")) ) return True return False
def handlePush(data, from_gui=False): if not from_gui and checkForWindow(): #Do nothing if the window is open return False if data.get('type') == 'link': url = data.get('url', '') if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info['title'] or '?') idx = xbmcgui.Dialog().select(common.localise(32091), vlist) if idx < 0: return vid.selectStream(idx) playMedia(vid.streamURL(), vid.title, vid.thumbnail, vid.description) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == 'video' or media == 'audio': url += '|' + urllib.urlencode({'User-Agent': getURLUserAgent(url)}) playMedia(url, playlist_type='video' and xbmc.PLAYLIST_VIDEO or xbmc.PLAYLIST_MUSIC) return True elif media == 'image': import gui gui.showImage(url) return True elif data.get('type') == 'file': if data.get('file_type', '').startswith('image/'): import gui gui.showImage(data.get('file_url', '')) return True elif data.get('file_type', '').startswith('video/') or data.get( 'file_type', '').startswith('audio/'): playMedia(data.get('file_url', '')) return True elif data.get('type') == 'note': import gui gui.showNote(data.get('body', '')) return True elif data.get('type') == 'list': import gui gui.showList(data) return True elif data.get('type') == 'address': cmd = 'XBMC.RunScript({0},MAP,{1},None,)'.format( common.__addonid__, urllib.quote(data.get('address', ''))) xbmc.executebuiltin(cmd) return True return False
def handlePush(data, from_gui=False): if not from_gui and checkForWindow(): # Do nothing if the window is open return False if data.get("type") == "link": url = data.get("url", "") if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info["title"] or "?") idx = xbmcgui.Dialog().select(common.localise(32091), vlist) if idx < 0: return vid.selectStream(idx) playMedia(vid.streamURL(), vid.title, vid.thumbnail, vid.description) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == "video" or media == "audio": url += "|" + urllib.urlencode({"User-Agent": getURLUserAgent(url)}) playMedia(url, playlist_type="video" and xbmc.PLAYLIST_VIDEO or xbmc.PLAYLIST_MUSIC) return True elif media == "image": import gui gui.showImage(url) return True elif data.get("type") == "file": if data.get("file_type", "").startswith("image/"): import gui gui.showImage(data.get("file_url", "")) return True elif data.get("file_type", "").startswith("video/") or data.get("file_type", "").startswith("audio/"): playMedia(data.get("file_url", "")) return True elif data.get("type") == "note": import gui gui.showNote(data.get("body", "")) return True elif data.get("type") == "list": import gui gui.showList(data) return True elif data.get("type") == "address": cmd = "XBMC.RunScript({0},MAP,{1},None,)".format(common.__addonid__, urllib.quote(data.get("address", ""))) xbmc.executebuiltin(cmd) return True return False
def handlePush(data, from_gui=False): if not from_gui and checkForWindow(): #Do nothing if the window is open return False if data.get('type') == 'link': url = data.get('url', '') if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info['title'] or '?') idx = xbmcgui.Dialog().select(util.T(32091), vlist) if idx < 0: return vid.selectStream(idx) util.LOG(vid.streamURL()) #TODO: REMOVE StreamUtils.play(vid.streamURL()) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == 'video' or media == 'music': StreamUtils.play(url) return True elif media == 'image': import gui gui.showImage(url) return True elif data.get('type') == 'file': if data.get('file_type', '').startswith('image/'): import gui gui.showImage(data.get('file_url', '')) return True elif data.get('file_type', '').startswith('video/') or data.get( 'file_type', '').startswith('audio/'): StreamUtils.play(data.get('file_url', '')) return True elif data.get('type') == 'note': import gui gui.showNote(data.get('body', '')) return True elif data.get('type') == 'list': import gui gui.showList(data) return True elif data.get('type') == 'address': import urllib xbmc.executebuiltin( 'XBMC.RunScript(special://home/addons/service.pushbullet.com/lib/maps.py,service.pushbullet.com,%s,None,)' % urllib.quote(data.get('address', ''))) return True return False
def play_video(path, isyoutube, isplayable): """ Play a video by the provided path. :param path: Fully-qualified video URL :type path: str :type isyoutube: bool :type isplayable: Number 0-4 """ if isplayable in ('0', '2', '3'): # unplayable item (unknown, coming soon, outdated) if isplayable == '2': if not dialogYesNo(LS(30000), LS(30067)): return elif isplayable == '3': if not dialogYesNo(LS(30000), LS(30066)): return else: return if strToBool(isyoutube): writeLog('Youtube video, invoke plugin.youtube.dl', xbmc.LOGINFO) writeLog('try to use quality factor {}'.format(yt_quality)) if YDStreamExtractor.mightHaveVideo(path, resolve_redirects=True): try: vid = YDStreamExtractor.getVideoInfo(path, quality=yt_quality, resolve_redirects=True) if vid is not None: if vid.hasMultipleStreams(): s_list = list() for stream in vid.streams(): s_list.append(stream['title']) writeLog( 'multiple streams detected: {}'.format( ', '.join(s_list)), xbmc.LOGINFO) path = vid.streamURL() else: notify(LS(30000), LS(30047), xbmcgui.NOTIFICATION_WARNING) writeLog('Could not extract video stream', xbmc.LOGERROR) except Exception as e: notify(LS(30000), LS(30047), xbmcgui.NOTIFICATION_WARNING) writeLog('youtube_dl has thrown an exception', xbmc.LOGERROR) writeLog(str(e), xbmc.LOGERROR) else: writeLog('Could not extract video stream', xbmc.LOGERROR) notify(LS(30000), LS(), xbmcgui.NOTIFICATION_WARNING) play_item = xbmcgui.ListItem(path=path) xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
def handlePush(data,from_gui=False): if not from_gui and checkForWindow(): #Do nothing if the window is open return False if data.get('type') == 'link': url = data.get('url','') if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info['title'] or '?') idx = xbmcgui.Dialog().select(common.localise(32091),vlist) if idx < 0: return vid.selectStream(idx) playMedia(vid.streamURL(),vid.title,vid.thumbnail,vid.description) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == 'video' or media == 'audio': url += '|' + urllib.urlencode({'User-Agent':getURLUserAgent(url)}) playMedia(url,playlist_type='video' and xbmc.PLAYLIST_VIDEO or xbmc.PLAYLIST_MUSIC) return True elif media == 'image': import gui gui.showImage(url) return True elif data.get('type') == 'file': if data.get('file_type','').startswith('image/'): import gui gui.showImage(data.get('file_url','')) return True elif data.get('file_type','').startswith('video/') or data.get('file_type','').startswith('audio/'): playMedia(data.get('file_url','')) return True elif data.get('type') == 'note': import gui gui.showNote(data.get('body','')) return True elif data.get('type') == 'list': import gui gui.showList(data) return True elif data.get('type') == 'address': cmd = 'XBMC.RunScript({0},MAP,{1},None,)'.format(common.__addonid__,urllib.quote(data.get('address',''))) xbmc.executebuiltin(cmd) return True return False
def canHandle(data): if data.get('type') == 'link': url = data.get('url','') if StreamExtractor.mightHaveVideo(url): return 'video' mediaType = getURLMediaType(url) if mediaType: return mediaType return canPlayURL(url) and 'video' or None elif data.get('type') == 'file': fType = data.get('file_type','')[:5] if fType in ('image','video','audio'): return fType elif data.get('type') == 'note': return 'note' elif data.get('type') == 'list': return 'list' elif data.get('type') == 'address': return 'address' return None
def canHandle(data): if data.get('type') == 'link': url = data.get('url','') if StreamExtractor.mightHaveVideo(url): return 'video' mediaType = getURLMediaType(url) if mediaType: return mediaType return canPlayURL(url) and 'video' or None elif data.get('type') == 'file': fType = data.get('file_type','')[:5] if fType in ('image','video','audio'): return fType elif data.get('type') == 'note': return 'note' elif data.get('type') == 'list': return 'list' elif data.get('type') == 'address': return 'address' return None
def canHandle(data): if data.get('type') == 'link': url = data.get('url', '') if StreamExtractor.mightHaveVideo(url): return True if getURLMediaType(url): return True return canPlayURL(url) elif data.get('type') == 'file': return data.get('file_type', '').startswith('image/') or data.get( 'file_type', '').startswith('audio/') or data.get( 'file_type', '').startswith('video/') elif data.get('type') == 'note': return True elif data.get('type') == 'list': return True elif data.get('type') == 'address': return True return False
def canHandle(data): if data.get("type") == "link": url = data.get("url", "") if StreamExtractor.mightHaveVideo(url): return "video" mediaType = getURLMediaType(url) if mediaType: return mediaType return canPlayURL(url) and "video" or None elif data.get("type") == "file": fType = data.get("file_type", "")[:5] if fType in ("image", "video", "audio"): return fType elif data.get("type") == "note": return "note" elif data.get("type") == "list": return "list" elif data.get("type") == "address": return "address" return None
def canHandle(data): if data.get("type") == "link": url = data.get("url", "") if StreamExtractor.mightHaveVideo(url): return True if getURLMediaType(url): return True return canPlayURL(url) elif data.get("type") == "file": return ( data.get("file_type", "").startswith("image/") or data.get("file_type", "").startswith("audio/") or data.get("file_type", "").startswith("video/") ) elif data.get("type") == "note": return True elif data.get("type") == "list": return True elif data.get("type") == "address": return True return False
def onInit(self): BaseWindow.onInit(self) self.setProperty('loading', '1') self._winID = xbmcgui.getCurrentWindowId() self.pushList = self.getControl(101) token = util.getSetting('pb_access_token') if not token: return loadVideoThumbs = util.getSetting('load_video_thumbs', False) kodiDevice = devices.getDefaultKodiDevice( util.getSetting('pb_client_iden'), util.getSetting('pb_client_nickname')) if not kodiDevice: return self.pushes = [] pushes = self.client.pushes() if not pushes: return items = [] cacheIDs = [] self.pushes = [] for p in pushes: #Keep all IDs cached so that we don't cause a delay when changing view if p.get('active'): cacheIDs.append(p.get('iden')) if self.viewMode == 'SELF': self.pushes = [ p for p in pushes if p.get('active') and p.get('target_device_iden') == kodiDevice.ID ] elif self.viewMode == 'ALL': self.pushes = [p for p in pushes if p.get('active')] elif self.viewMode: self.pushes = [ p for p in pushes if p.get('active') and p.get('target_device_iden') == self.viewMode ] for push in self.pushes: iden = push.get('iden') title = push.get('title', push.get('name', push.get('file_name', ''))) bg = push.get('image_url', '') info = push.get('url', '') mediaIcon = '' media = '' if push.get('type') == 'address': bg = maps.Maps().getMap(urllib.quote(push.get('address', '')), 'None', marker=True, return_url_only=True) elif push.get('type') == 'link': url = push.get('url') if StreamExtractor.mightHaveVideo(url): media = 'video' if loadVideoThumbs: bg = getCachedData(iden) if not bg: bg = StreamExtractor.getVideoInfo(url).thumbnail cacheData(iden, bg) else: media = pushhandler.getURLMediaType(url) if not title: title = url.rsplit('/', 1)[-1] elif push.get('type') == 'file': info = urllib.unquote(push.get('file_url', '')) if push.get('file_type', '').startswith('image/'): media = 'image' elif push.get('file_type', '').startswith('audio/'): media = 'music' elif push.get('file_type', '').startswith('video/'): media = 'video' if media: mediaIcon = 'service-pushbullet-com-icon_{0}.png'.format(media) item = xbmcgui.ListItem( title, iconImage='service-pushbullet-com-{0}.png'.format( push.get('type', ''))) desc = push.get('body', push.get('address', '')) if push.get('type') == 'list': li = [] ct = 0 for i in push.get('items', []): li.append(i.get('text', '')) ct += 1 if ct > 50: break desc = ', '.join(li) desc = '[CR]'.join(desc.splitlines()[:4]) item.setProperty('description', desc) item.setProperty('info', info) item.setProperty( 'sender', push.get('sender_name', push.get('sender_email', ''))) item.setProperty('media_icon', mediaIcon) item.setProperty('background', bg) #item.setProperty('date',time.strftime('%m-%d-%Y %H:%M',time.localtime(push.get('created',0)))) item.setProperty( 'date', '{0} {1}'.format( util.durationToShortText(time.time() - push.get('created', 0)), T(32053))) items.append(item) self.setProperty('loading', '0') self.pushList.reset() self.pushList.addItems(items) if items: self.setFocusId(101) self.reSelect() cleanCache(cacheIDs)
def onInit(self): BaseWindow.onInit(self) self.setProperty('loading','1') self._winID = xbmcgui.getCurrentWindowId() self.pushList = self.getControl(101) token = util.getSetting('token') if not token: return loadVideoThumbs = util.getSetting('load_video_thumbs',False) kodiDevice = devices.getDefaultKodiDevice(util.getSetting('device_iden'),util.getSetting('device_name')) if not kodiDevice: return self.pushes = [] pushes = self.client.pushes() if not pushes: return items = [] cacheIDs = [] self.pushes = [] for p in pushes: #Keep all IDs cached so that we don't cause a delay when changing view if p.get('active'): cacheIDs.append(p.get('iden')) if self.viewMode == 'SELF': self.pushes = [p for p in pushes if p.get('active') and p.get('target_device_iden') == kodiDevice.ID] elif self.viewMode == 'ALL': self.pushes = [p for p in pushes if p.get('active')] elif self.viewMode: self.pushes = [p for p in pushes if p.get('active') and p.get('target_device_iden') == self.viewMode] for push in self.pushes: iden = push.get('iden') title = push.get('title',push.get('name',push.get('file_name',''))) bg = push.get('image_url','') info = push.get('url','') mediaIcon = '' media = '' if push.get('type') == 'address': bg = maps.Maps().getMap(urllib.quote(push.get('address','')),'None',marker=True,return_url_only=True) elif push.get('type') == 'link': url = push.get('url') if StreamExtractor.mightHaveVideo(url): media = 'video' if loadVideoThumbs: bg = getCachedData(iden) if not bg: bg = StreamExtractor.getVideoInfo(url).thumbnail cacheData(iden,bg) else: media = pushhandler.getURLMediaType(url) if not title: title = url.rsplit('/',1)[-1] elif push.get('type') == 'file': info = urllib.unquote(push.get('file_url','')) if push.get('file_type','').startswith('image/'): media = 'image' elif push.get('file_type','').startswith('audio/'): media = 'music' elif push.get('file_type','').startswith('video/'): media = 'video' if media: mediaIcon = 'service-pushbullet-com-icon_{0}.png'.format(media) item = xbmcgui.ListItem(title,iconImage='service-pushbullet-com-{0}.png'.format(push.get('type',''))) desc = push.get('body',push.get('address','')) if push.get('type') == 'list': li = [] ct = 0 for i in push.get('items',[]): li.append(i.get('text','')) ct+=1 if ct > 50: break desc = ', '.join(li) desc = '[CR]'.join(desc.splitlines()[:4]) item.setProperty('description',desc) item.setProperty('info',info) item.setProperty('sender', push.get('sender_email','')) item.setProperty('media_icon',mediaIcon) item.setProperty('background',bg) #item.setProperty('date',time.strftime('%m-%d-%Y %H:%M',time.localtime(push.get('created',0)))) item.setProperty('date','{0} {1}'.format(util.durationToShortText(time.time() - push.get('created',0)),T(32053))) items.append(item) self.setProperty('loading','0') self.pushList.reset() self.pushList.addItems(items) if items: self.setFocusId(101) self.reSelect() cleanCache(cacheIDs)
def onInit(self): BaseWindow.onInit(self) self.setProperty("loading", "1") self._winID = xbmcgui.getCurrentWindowId() self.pushList = self.getControl(101) token = util.getSetting("pb_access_token") if not token: return loadVideoThumbs = util.getSetting("load_video_thumbs", False) kodiDevice = devices.getDefaultKodiDevice( util.getSetting("pb_client_iden"), util.getSetting("pb_client_nickname") ) if not kodiDevice: return self.pushes = [] pushes = self.client.pushes() if not pushes: return items = [] cacheIDs = [] self.pushes = [] for p in pushes: # Keep all IDs cached so that we don't cause a delay when changing view if p.get("active"): cacheIDs.append(p.get("iden")) if self.viewMode == "SELF": self.pushes = [p for p in pushes if p.get("active") and p.get("target_device_iden") == kodiDevice.ID] elif self.viewMode == "ALL": self.pushes = [p for p in pushes if p.get("active")] elif self.viewMode: self.pushes = [p for p in pushes if p.get("active") and p.get("target_device_iden") == self.viewMode] for push in self.pushes: iden = push.get("iden") title = push.get("title", push.get("name", push.get("file_name", ""))) bg = push.get("image_url", "") info = push.get("url", "") mediaIcon = "" media = "" if push.get("type") == "address": bg = maps.Maps().getMap( urllib.quote(push.get("address", "")), "None", marker=True, return_url_only=True ) elif push.get("type") == "link": url = push.get("url") if StreamExtractor.mightHaveVideo(url): media = "video" if loadVideoThumbs: bg = getCachedData(iden) if not bg: bg = StreamExtractor.getVideoInfo(url).thumbnail cacheData(iden, bg) else: media = pushhandler.getURLMediaType(url) if not title: title = url.rsplit("/", 1)[-1] elif push.get("type") == "file": info = urllib.unquote(push.get("file_url", "")) if push.get("file_type", "").startswith("image/"): media = "image" elif push.get("file_type", "").startswith("audio/"): media = "music" elif push.get("file_type", "").startswith("video/"): media = "video" if media: mediaIcon = "service-pushbullet-com-icon_{0}.png".format(media) item = xbmcgui.ListItem(title, iconImage="service-pushbullet-com-{0}.png".format(push.get("type", ""))) desc = push.get("body", push.get("address", "")) if push.get("type") == "list": li = [] ct = 0 for i in push.get("items", []): li.append(i.get("text", "")) ct += 1 if ct > 50: break desc = ", ".join(li) desc = "[CR]".join(desc.splitlines()[:4]) item.setProperty("description", desc) item.setProperty("info", info) item.setProperty("sender", push.get("sender_name", push.get("sender_email", ""))) item.setProperty("media_icon", mediaIcon) item.setProperty("background", bg) # item.setProperty('date',time.strftime('%m-%d-%Y %H:%M',time.localtime(push.get('created',0)))) item.setProperty( "date", "{0} {1}".format(util.durationToShortText(time.time() - push.get("created", 0)), T(32053)) ) items.append(item) self.setProperty("loading", "0") self.pushList.reset() self.pushList.addItems(items) if items: self.setFocusId(101) self.reSelect() cleanCache(cacheIDs)