def get_trailer(source_id, movie_title, mode): __log('get_trailer started with mode=%s source_id=%s movie_title=%s ' % (mode, source_id, movie_title)) is_download = mode == 'download' try: local_path, remote_url, trailer_id = __select_check_trailer( source_id, movie_title, is_download=is_download, ) except NoDownloadPath: xbmcgui.Dialog().ok(_('no_download_path'), _('no_download_path')) return except (NoQualitySelected, NoTrailerSelected): return if mode == 'play': if plugin.get_setting('playback_mode') == '0': # stream return play_trailer(local_path, remote_url) elif plugin.get_setting('playback_mode') == '1': # download+play return download_play_trailer(local_path, remote_url, trailer_id) elif mode == 'download': # download in background return download_trailer(local_path, remote_url, trailer_id)
def show_favorites(url): '''Shows your favorite videos from http://acadmemicearth.org/favorites.' ''' src = s.download_page(url) if not src: return html = BS(src) videos = html.find('ul', {'class': 'favorites-list'}).findAll('li') items = [{ 'label': item.h3.a.string, 'url': favorites.url_for('watch_lecture', url=full_url(item.h3.a['href'])), 'thumbnail': full_url(item.img['src']), 'is_folder': False, 'is_playable': True, 'context_menu': [ (favorites._plugin.get_string(30301), 'XBMC.RunPlugin(%s)' % favorites.url_for( 'favorites.remove_lecture', url=full_url(item.find('div', {'class': 'delete'}).a['href']) )), ], } for item in videos] if not items: xbmcgui.Dialog().ok(favorites._plugin.get_string(30000), favorites._plugin.get_string(30404)) return favorites.add_items(items)
def getData(self, url): send = urllib.urlencode(self.data) self.request = urllib2.Request( url, send, headers={"User-Agent": "XBMC/Kodi MyTV Addon " + str(__version__)}) try: response = urllib2.urlopen(self.request) except HTTPError, e: dialog = xbmcgui.Dialog() dialog.ok(__lang__(30003), e.code) return
def play(url): plugin_url = resolve(download_page(url)) if plugin_url: return plugin.set_resolved_url(plugin_url) # Uh oh, things aren't working. Print the broken url to the log and ask if # we can submit the url to a google form. current_plugin_url = '?'.join([plugin._argv0, plugin._argv2]) xbmc.log('REPORT THIS URL: %s' % current_plugin_url) dialog = xbmcgui.Dialog() user_resp = dialog.yesno('Documentary Heaven Playback Problem.', 'There was an issue playing this video.', ('Would you like to report the URL to the' ' developer?')) if user_resp: report_broken_url(current_plugin_url)
def ask_trailer_quality(source, movie_title): trailer_qualities = source.get_trailer_qualities(movie_title) # if the user wants to be asked the quality, show the dialog if plugin.get_setting('ask_quality') == 'true': # if there are more than one trailer qualities, ask if len(trailer_qualities) > 1: dialog = xbmcgui.Dialog() selected = dialog.select(_('choose_trailer_quality'), [t['title'] for t in trailer_qualities]) # if the user canceled the dialog, raise if selected == -1: raise NoQualitySelected # there is only one trailer quality, don't ask and choose it else: selected = 0 # the user doesnt want to be asked, choose from settings else: selected = int(plugin.get_setting('trailer_quality')) return trailer_qualities[selected]['id']
def authenticate(self, username=None, password=None): username = username or favorites._plugin.get_setting('username') password = password or favorites._plugin.get_setting('password') params = { '_method': 'POST', 'data[User][username]': username, 'data[User][password]': password, 'data[User][goto]': '//', 'header-login-submit': 'Login', } resp = self.opener.open(LOGIN_URL, urlencode(params)) if resp.geturl().startswith(LOGIN_URL): dialog = xbmcgui.Dialog() # Incorrect username/password error message dialog.ok(favorites._plugin.get_string(30000), favorites._plugin.get_string(30401)) favorites._plugin.open_settings() return False self.cookie_jar.save(ignore_discard=True, ignore_expires=True)
def ask_trailer_type(source, movie_title): # if the user wants to be asked, show the select dialog if plugin.get_setting('ask_trailer') == 'true': trailer_types = source.get_trailer_types(movie_title) if not trailer_types: __log('there are no trailers found for selection') return 'trailer' # is there more than one trailer_types, ask elif len(trailer_types) > 1: dialog = xbmcgui.Dialog() selected = dialog.select(_('choose_trailer_type'), [t['title'] for t in trailer_types]) # if the user canceled the dialog, raise if selected == -1: raise NoTrailerSelected # there is only one trailer_type, don't ask and choose it else: selected = 0 return trailer_types[selected]['id'] # the user doesnt want to be asked, let the scraper choose the most recent else: return 'trailer'
def __select_check_trailer(source_id, movie_title, is_download): __log(('__select_check_trailer started with source_id=%s movie_title=%s ' 'is_download=%s') % (source_id, movie_title, is_download)) source = __get_source(source_id) trailer_type = ask_trailer_type(source, movie_title) # check if there is already a downloaded trailer in download_quality q_id = int(plugin.get_setting('trailer_quality_download')) trailer_quality = source.get_trailer_qualities(movie_title)[q_id]['id'] download_trailer_id = '|'.join( (source_id, movie_title, trailer_type, trailer_quality), ) local_path = plugin.get_setting(download_trailer_id) if local_path and xbmcvfs.exists(local_path): # there is a already downloaded trailer, signal with empty remote_url __log('trailer already downloaded, using downloaded version') remote_url = None else: # there is no already downloaded trailer if not is_download: # on play (and not download) the quality may differ trailer_quality = ask_trailer_quality(source, movie_title) if not plugin.get_setting('trailer_download_path'): xbmcgui.Dialog().ok(_('no_download_path'), _('please_set_path')) plugin.open_settings() download_path = plugin.get_setting('trailer_download_path') if not download_path: __log('still no download_path set - aborting') raise NoDownloadPath safe_chars = ('-_. abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') safe_title = ''.join([c for c in movie_title if c in safe_chars]) filename = '%s-%s-%s' % (safe_title, trailer_type, trailer_quality) local_path = os.path.join(download_path, filename) remote_url = source.get_trailer(movie_title, trailer_quality, trailer_type) return (local_path, remote_url, download_trailer_id)
def play_live(url, title, thumb, chid, usern, passwd): if usern != '': auth_resp = auth.doAuth(usern, passwd) if auth_resp < 100: xbmcgui.Dialog().ok( "Autorizacija nije uspješna", "Niste unijeli korisničke podatke ili uneseni podaci nisu tačni.\n\nNakon što kliknete OK otvoriće Vam se postavke te je neophodno da unesete ispravno korisničko ime i lozinku za Moja webTV servis " ) xbmcaddon.Addon(id='plugin.video.mojawebtv').openSettings() if auth_resp > 99: li = xbmcgui.ListItem(label=title, thumbnailImage=thumb) li.setInfo(type='Video', infoLabels={"Title": title}) li.setProperty('IsPlayable', 'true') xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(url, li) if usern == '': li = xbmcgui.ListItem(label=title, thumbnailImage=thumb) li.setInfo(type='Video', infoLabels={"Title": title}) li.setProperty('IsPlayable', 'true') xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(url, li) # Return an empty list so we can test with plugin.crawl() and # plugin.interactive() return []
def show_live(label): ''' ''' items = [] url_add = '' server = [0, 1, 2, 3] server[0] = '195.222.59.132' server[1] = '195.222.59.142' server[2] = '195.222.57.183' server[3] = '195.222.59.140' ext = [0, 1, 2, 3] ext[0] = '.smil' ext[1] = '.smil' ext[2] = '.smil' ext[3] = '.stream' # if xbmcplugin.getSetting(pluginhandle, 'hq') == "true": # The first link for the 'Clips' section links directly to a video so we # must handle it differently. if label == 'sd': auth_resp = auth.doAuth(usern, passwd) if auth_resp < 100: xbmcgui.Dialog().ok( "Autorizacija nije uspješna", "Niste unijeli korisničke podatke ili uneseni podaci nisu tačni.\n\nNakon što kliknete OK otvoriće Vam se postavke te je neophodno da unesete ispravno korisničko ime i lozinku za Moja webTV servis " ) xbmcaddon.Addon(id='plugin.video.mojawebtv').openSettings() if auth_resp > 99: videos, total_results = get_videos('sd') i = 0 for video in videos: items.append({ 'label': video['summary'], 'info': { 'plot': video['start'] + ' ' + video['title'], }, 'thumbnail': video['thumbnail'], 'url': plugin.url_for( 'play_live', url='http://webtvstream.bhtelecom.ba/kodi/' + video['videoid'] + '.m3u8', title=(video['title'].encode('utf8')), thumb=video['logo'], chid=video['videoid'], usern=usern, passwd=passwd), 'is_folder': False, 'is_playable': False, }) if label == 'cam': videos, total_results = get_videos('cam') i = 0 for video in videos: items.append({ 'label': video['summary'], 'info': { 'plot': video['start'] + ' ' + video['title'], }, 'thumbnail': video['thumbnail'], 'url': plugin.url_for('play_live', url='http://webtvstream.bhtelecom.ba/kodi/' + video['videoid'] + '.m3u8', title=(video['title'].encode('utf8')), thumb=video['logo'], chid=video['videoid'], usern=usern, passwd=passwd), 'is_folder': False, 'is_playable': False, }) if label == 'radio': videos, total_results = get_videos('radio') i = 0 for video in videos: items.append({ 'label': video['summary'], 'info': { 'plot': video['start'] + ' ' + video['title'], }, 'thumbnail': video['logo'], 'url': plugin.url_for('play_live', url='http://webtvstream.bhtelecom.ba/kodi/' + video['videoid'] + '.m3u8', title=(video['title'].encode('utf8')), thumb=video['logo'], chid=video['videoid'], usern=usern, passwd=passwd), 'is_folder': False, 'is_playable': False, }) if label == 'rec': auth_resp = auth.doAuth(usern, passwd) if auth_resp < 100: xbmcgui.Dialog().ok( "Autorizacija nije uspješna", "Niste unijeli korisničke podatke ili uneseni podaci nisu tačni.\n\nNakon što kliknete OK otvoriće Vam se postavke te je neophodno da unesete ispravno korisničko ime i lozinku za Moja webTV servis " ) xbmcaddon.Addon(id='plugin.video.mojawebtv').openSettings() if auth_resp > 99: videos, total_results = get_videos('rec') for video in videos: items.append({ 'label': video['summary'], 'thumbnail': video['logo'], 'info': { 'plot': video['summary'], }, 'url': plugin.url_for('get_epg', ch=video['videoid']), 'is_folder': True, 'is_playable': False, }) return plugin.add_items(items)
def tvList(url): args = urlparse.parse_qs(sys.argv[2][1:], keep_blank_values=True, strict_parsing=False) title_tmp = args.get('title', None) filters = False if title_tmp is None: title = '' else: title = title_tmp[0].decode('utf-8').encode('utf-8') show_title_tmp = args.get('show_title', None) if show_title_tmp is None: show_title = '' else: show_title = show_title_tmp[0].decode('utf-8').encode('utf-8') menulist = [] items = [] dialog = xbmcgui.Dialog() if (not plugin.get_setting('username')) or ( not plugin.get_setting('password')): dialog.ok(__lang__(30003), __lang__(30005)) return signin = login(plugin.get_setting('username'), plugin.get_setting('password'), url) if (not signin) or (not signin.token): return if not signin.data: return if 'menu' not in signin.data: if 'key' not in signin.data: dialog.ok(__lang__(30003), signin.data['msg']) return else: if 'quality_urls' in signin.data and len( signin.data['quality_urls']) > 1: for key, val in enumerate(signin.data['quality_urls']): items.append(val['title']) ret = dialog.select(__lang__(30006), items) tvPlay(signin.data['quality_urls'][ret]['key'], title, show_title, getTrackingKey(signin.data['quality_urls'][ret])) return tvPlay(signin.data['key'], title, show_title, getTrackingKey(signin.data)) return else: menulist = signin.data['menu'] _show_title = signin.data.get('title_prev', ' ').encode('utf-8') if not menulist: dialog.ok(__lang__(30003), __lang__(30004)) if menulist: for (key, val) in enumerate(menulist): if val['type'] == 'item': items.append({ 'label': u"{0}".format(val['title']), 'key': u"{0}".format(key), 'url': plugin.url_for('tvPlay', url=val['key'], tracking_key=getTrackingKey(val)), 'thumb': "{0}".format(val["thumb"]) }) elif val['type'] == 'menu': label = val['title'].encode('utf-8') items.append({ 'label': label, 'key': u"{0}".format(key), 'url': plugin.url_for('tvList', url=val['key'], title=label, show_title=_show_title), 'thumb': "{0}".format(val["thumb"]) }) return plugin.add_items(items, False, [ xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE, xbmcplugin.SORT_METHOD_VIDEO_TITLE ])
if res['login'] == 'yes': if self.login_iteration > 0: self.login_iteration = 0 return self.logIN() self.data = self.getLive() data_new = self.getData(url) self.login_iteration += 1 return data_new else: dialog = xbmcgui.Dialog() dialog.ok(__lang__(30003), res['msg']) return return res def getLive(self): return {'token': self.token} def makeUserPass(self): return { "usr": self.usr, "pwd": self.pas, "access_type":
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') safe_title = ''.join([c for c in movie_title if c in safe_chars]) filename = '%s-%s-%s' % (safe_title, trailer_type, trailer_quality) local_path = os.path.join(download_path, filename) remote_url = source.get_trailer(movie_title, trailer_quality, trailer_type) return (local_path, remote_url, download_trailer_id) def _(s): s_id = STRINGS.get(s) if s_id: return plugin.get_string(s_id) else: return s def __log(text): xbmc.log('%s addon: %s' % (__addon_name__, text)) if __name__ == '__main__': try: plugin.set_content('movies') plugin.run() except NetworkError as e: __log('NetworkError: %s' % e) xbmcgui.Dialog().ok(_('neterror_title'), _('neterror_line1'), _('neterror_line2'))
def add_lecture(url): '''This is a context menu view to add an item to a user's favorites on academciearth.org''' if not s.download_page(url): xbmcgui.Dialog().ok(favorites._plugin.get_string(30000), favorites._plugin.get_string(30404))