def InstallApp(URL='', mediaitem=CMediaItem()): type = mediaitem.GetType(0) attributes = mediaitem.GetType(1) if type == 'app': response = mc.ShowDialogConfirm("Message", "Install Boxee App?", "No", "Yes") if response == False: return mc.ShowDialogWait() #loading text installer = CInstaller() # if attributes == 'navi-x': result = installer.InstallNaviX(URL, mediaitem) # else: # result = installer.InstallScript(URL, mediaitem) if result == 0: mc.ShowDialogOk("Installer", "Installation successful.") mc.ShowDialogOk("Installer", "Please restart Boxee.") elif result == -1: mc.ShowDialogOk("Installer", "Installation aborted.") elif result == -3: mc.ShowDialogOk("Installer", "Invalid ZIP file.") else: mc.ShowDialogOk("Installer", "Installation failed.") mc.HideDialogWait() return
def parseAudioStreams(item): try: play_audio = False audio_string = item.GetProperty('audio-string') audio_items = audio_string.split('||') if (len(audio_items) == 0): return raiseError( 'Unable to located proper audio items. This may be an error, please contact [email protected]. We apologize for the inconvenience.', 'playitem', 'problem locating audio streams, audio-string property is empty or malformed' ) elif (len(audio_items) == 1): stream_1 = audio_items[0] stream_1 = stream_1.split('|') play_audio = stream_1 elif (len(audio_items) > 1): stream_1 = audio_items[0] stream_2 = audio_items[1] stream_1 = stream_1.split('|') stream_2 = stream_2.split('|') confirm = mc.ShowDialogConfirm( 'MLB.TV', 'Please select the audio stream you wish to listen to...', stream_1[0], stream_2[0]) if confirm: play_audio = stream_1 else: play_audio = stream_2 if (play_audio or raiseError()): return False return play_audio except Exception, e: return raiseError(log='parseaudiostreams', error=e)
def thumbnail_function(): if mc.ShowDialogConfirm( "Clear thumbnail cache", "Are you sure you want to clear the thumbnail cache?", "Cancel", "OK"): os.system("rm %s" % xbmc.translatePath('special://profile/.fanart')) os.system( "find /data/.boxee/UserData/profiles/*/Thumbnails/ -name \*.tbn | xargs rm" ) mc.ShowDialogNotification("Clearing thumbnail cache")
def userLogout(prompt=True): try: confirm = True if prompt: confirm = mc.ShowDialogConfirm( 'MLB.TV', 'Would you like to sign out of MLB.TV? Your currently stored login information will be lost.', 'Cancel', 'Continue') if (confirm and logout()): mc.ActivateWindow(10482) except Exception, e: return raiseError(log='userLogout', error=e)
def promptQuality(): try: cf = mc.GetApp().GetLocalConfig() q_ask = bool(cf.GetValue('ask_quality')) q_high = bool(cf.GetValue('high_quality')) q_default = bool(cf.GetValue('default_quality')) if ((not q_ask) and ((not q_high) and (not q_default))): q_ask = True cf.SetValue('ask_quality', '1') if q_ask: q_message = 'Please select your video quality (manage this and other options in the settings tab):' quality = mc.ShowDialogConfirm('MLB.TV', q_message, 'Normal', 'High') quality = int(quality) elif q_high: quality = 1 else: quality = 0 return str(quality) except Exception, e: return raiseError(log='promptquality', error=e)
def unzip_file_into_dir(self, file, dir): chk_confirmation = False if os.path.exists(dir) == False: try: os.makedirs(dir) #create the directory except IOError: return -1 #failure zfobj = zipfile.ZipFile(file) for name in zfobj.namelist(): index = name.rfind('/') if index != -1: #entry contains path if os.path.exists(dir+name[:index+1]): #directory exists if chk_confirmation == False: response = mc.ShowDialogConfirm("Installer", "Directory already exists, continue?", "No", "Yes") if response == False: return -1 else: #directory does not exist. Create it. try: #create the directory structure os.makedirs(os.path.join(dir, name[:index+1])) except IOError: return -1 #failure if not name.endswith('/'): #entry contains a filename try: outfile = open(os.path.join(dir, name), 'wb') outfile.write(zfobj.read(name)) outfile.close() except IOError: pass #There was a problem. Continue... chk_confirmation = True return 0 #succesful
def MenuLeftSelectItem(itemNumber): if itemNumber == 0: SelectItem(iURL=home_URL) mc.GetWindow(14000).GetList(GetListView()).SetFocus() elif itemNumber == 1: userkey = mc.GetApp().GetLocalConfig().GetValue("userkey") arguments = "?user="******"&request=get&type=.plx" SelectItem(iURL=favorites_URL + arguments) elif itemNumber == 2: ListView = mc.GetApp().GetLocalConfig().GetValue("listview") if ListView == "default": mc.GetApp().GetLocalConfig().SetValue("listview", "thumbnails") elif ListView == "thumbnails": mc.GetApp().GetLocalConfig().SetValue("listview", "list") else: mc.GetApp().GetLocalConfig().SetValue("listview", "default") Init() ParsePlaylist(reload=False) mc.GetWindow(14000).GetList(122).SetFocus() mc.GetWindow(14000).GetList(122).SetFocusedItem(itemNumber) elif itemNumber == 3: if nxserver.is_user_logged_in() == True: response = mc.ShowDialogConfirm("Message", "Sign out?", "No", "Yes") if response: nxserver.logout() mc.ShowDialogOk("Sign out", "Sign out Successful.") Init() else: result = nxserver.login() if result == 0: mc.ShowDialogOk("Sign in", "Sign in Successful.") Init() elif result == -1: mc.ShowDialogOk("Sign in", "Sign in Failed.") mc.GetWindow(14000).GetList(GetListView()).SetFocus() elif itemNumber == 4: mc.CloseWindow() pass
def fanart_function(): if mc.ShowDialogConfirm( "Clear fanart cache", "Are you sure you want to clear the fanart cache?", "Cancel", "OK"): pass
def playItem(mlbList, forceAudioCheck=False, playFromListItem=False): if mc.ShowDialogWait(): play_audio = False if playFromListItem: window = mc.GetActiveWindow() list = window.GetList(mlbList) index = list.GetFocusedItem() item = list.GetItem(index) else: item = playFromListItem session_id = 'null' cf = mc.GetApp().GetLocalConfig() if cf.GetValue('sessionid'): session_id = cf.GetValue('sessionid') if isLoggedIn(): return raiseError( 'You must first log in before you can watch this game.') video_request_type = 'HTTP_CLOUD_WIRED' audio_request_type = 'AUDIO_SHOUTCAST_32K' audio_set_shout_protocol = False simulate_blackout = False simulate_not_authorized = False mr_url = 'https://secure.mlb.com/pubajaxws/bamrest/MediaService2_0/op-findUserVerifiedEvent/v-2.1?%s' params = { 'subject': 'LIVE_EVENT_COVERAGE', 'playbackScenario': video_request_type, 'eventId': item.GetProperty('event-id'), 'contentId': item.GetProperty('content-id'), 'sessionKey': session_id, 'fingerprint': cf.GetValue('fprt'), 'identityPointId': cf.GetValue('ipid'), 'platform': 'BOXEE' } web_url = ( 'http://mlb.mlb.com/media/player/entry.jsp?calendar_event_id=%s&source=boxeeRef' % item.GetProperty('event-id')) media_request = underscore((mr_url % urllib.urlencode(params))) if simulate_blackout: playlist_url = -1 elif simulate_not_authorized: playlist_url = -2 else: media_data = queryMediaService(media_request) playlist_url = media_data['playlist_url'] update_media_state = media_data['media_state'] if (bool(update_media_state) and (str(update_media_state).lower() != item.GetProperty('media-state').lower())): info( 'playitem', ('updating media_state (%s)' % update_media_state.lower())) item.SetProperty('media-state', update_media_state.lower()) if (playlist_url == -3000): check_auth = authenticate() if (check_auth == status_valid): media_data = queryMediaService(media_request) playlist_url = media_data['playlist_url'] update_media_state = media_data['media_state'] if (bool(update_media_state) and (str(update_media_state).lower() != item.GetProperty('media-state').lower())): info('playitem', ('updating media_state (%s)' % update_media_state.lower())) item.SetProperty('media-state', update_media_state.lower()) else: raiseError( 'Unable to validate your account. Please make sure your mlb.tv account is linked with Boxee! See boxee.tv/services.', 'playitem', 'lost users login credentials') mc.HideDialogWait() return False if ((playlist_url == -1) and ((not item.GetProperty('audio-string')) and (item.GetProperty('media-state') != 'media_on'))): return raiseError( 'No available audio streams found for this game. We apologize for the inconvenience.' ) confirm = mc.ShowDialogConfirm( 'MLB.TV', 'Video is not currently available for this game. Would you like to listen to the live audio broadcast?', 'No', 'Yes') if confirm: play_audio = parseAudioStreams(item) if play_audio: return False params = { 'subject': 'LIVE_EVENT_COVERAGE', 'playbackScenario': audio_request_type, 'eventId': item.GetProperty('event-id'), 'contentId': play_audio[1], 'sessionKey': session_id, 'fingerprint': cf.GetValue('fprt'), 'identityPointId': cf.GetValue('ipid'), 'platform': 'BOXEE' } del params['platform'] media_request = underscore((mr_url % urllib.urlencode(params))) media_data = queryMediaService(media_request) playlist_url = media_data['playlist_url'] update_media_state = media_data['media_state'] if (bool(update_media_state) and (str(update_media_state).lower() != item.GetProperty('media-state').lower())): info( 'playitem', ('updating media_state (%s)' % update_media_state.lower())) item.SetProperty('media-state', update_media_state.lower()) else: mc.HideDialogWait() return False if ((playlist_url == -2) and mc.GetActiveWindow().ClearStateStack()): return raiseError( 'You must own MLB.TV to watch live baseball. Please go to mlb.com/boxee to sign up.' ) if play_audio: content_type = 'audio/mpeg' stream_type = mc.ListItem.MEDIA_AUDIO_OTHER playlist_url = playlist_url.replace('http://', 'shout://') else: live = 0 playlist_url = (playlist_url + ('&quality=%s' % promptQuality())) if (item.GetProperty('media-state') == 'media_on'): confirm = mc.ShowDialogConfirm( 'MLB.TV', 'Would you like to watch this game from the start or jump into the live broadcast?', 'Start', 'Live') live = int(confirm) playlist_url = ((playlist_url + '&live=') + str(live)) content_type = 'application/vnd.apple.mpegurl' stream_type = mc.ListItem.MEDIA_VIDEO_OTHER alt_label = item.GetProperty('alt-label') title = alt_label.replace('#', '').replace('@mlbtv', '') title = (title.replace(' v ', ' @ ') + ' on MLB.TV') playlist_url = ((playlist_url + '&bx-ourl=') + urllib.quote_plus(web_url)) ext = mc.ListItem(stream_type) ext.SetTitle(alt_label) ext.SetLabel(title) ext.SetDescription(item.GetDescription(), False) ext.SetContentType(content_type) ext.SetThumbnail(item.GetThumbnail()) ext.SetProviderSource('MLB.TV') params = { 'title': title, 'alt-label': alt_label, 'event-id': item.GetProperty('event-id'), 'content-id': item.GetProperty('content-id'), 'description': item.GetDescription(), 'bx-ourl': web_url, 'thumbnail': item.GetThumbnail(), 'audio-stream': play_audio, 'media-state': item.GetProperty('media-state') } if play_audio: params['audio-string'] = item.GetProperty('audio-string') rand_number = str(random.randint(10000, 100000000)) tracking_url = ((( ((('http://mlbglobal08.112.2o7.net/b/ss/mlbglobal08/1/G.5--NS/' + rand_number) + '?ch=Media&pageName=BOXEE%20Media%20Return&c25=') + str(play_audio[2])) + '%7C') + underscore(audio_request_type)) + '&c27=Media%20Player&c43=BOXEE') notify = mc.Http().Get(tracking_url) del notify ext.SetPath(('app://mlb/launch?%s' % urllib.urlencode(params))) new_item = mc.ListItem(stream_type) new_item.SetLabel(title) new_item.SetTitle(alt_label) new_item.SetDescription(item.GetDescription(), False) new_item.SetPath(playlist_url) new_item.SetProviderSource('MLB.TV') new_item.SetContentType(content_type) new_item.SetThumbnail(item.GetThumbnail()) if (play_audio and new_item.SetAddToHistory(False)): new_item.SetReportToServer(False) new_item.SetExternalItem(ext) mc.GetActiveWindow().ClearStateStack() try: track_label = generateTrackerGameString(item) if (track_label and myTracker.trackEvent('Video', 'Play', track_label)): pass except: myTracker.trackEvent('Video', 'Play', title) mc.HideDialogWait() mc.GetPlayer().Play(new_item)
def onclick(): response = mc.ShowDialogConfirm( "UnBoxed", "Are you sure you wish to reboot your box?", "No", "Yes") if response: os.system("/sbin/reboot")