예제 #1
0
    def get_metadata(self, name, media_type):
        if helper.get_setting('enable-metadata') == 'false' or name == 'Next':
            return {},  ''
        helper.start('MediaList.get_metadata - name: %s, media_type: %s' % (name, media_type))

        name_for_movie_search = self.clean_name(name)
        name_for_tv_search = self.clean_tv_show_name(name_for_movie_search)

        metadata = {}
        if media_type == 'tvshow' or media_type == 'special' or media_type == 'preview':
            metadata = self.meta.get_meta('tvshow', name_for_tv_search)
            if metadata['tvdb_id'] == '':
                # If tvshow search failed, and if there was a year in the name, try tv without it
                import re
                if re.search('( \([12][0-9]{3}\))$', name_for_tv_search) != None:
                    metadata = self.meta.get_meta('tvshow', name_for_tv_search[:-7], update=True)
                    if metadata['imdb_id'] != '':
                        metadata = self.meta.update_meta('tvshow', name_for_tv_search, imdb_id='', new_imdb_id=metadata['imdb_id'])
            if metadata['tvdb_id'] != '' and media_type == 'preview':
                media_type = 'tvshow'
            helper.log_debug('Metadata for show %s: %s' % (name_for_tv_search, metadata))
        
        if media_type == 'movie' or media_type == 'preview':
            metadata = self.meta.get_meta('movie', name_for_movie_search)
            if metadata['tmdb_id'] != '' and media_type == 'preview':
                media_type = 'preview'
            helper.log_debug('Metadata for movie %s: %s' % (name_for_movie_search, metadata))

        helper.end('MediaList.get_metadata')
        return metadata, media_type
예제 #2
0
    def play(self):
        if self.link == '':
            return

        import urlresolver
        ''' 
            Kodi v17 updated to Python 2.7.10 from 2.7.5 in v16, which introduced this error when 
            trying to resolve the url:
            http://stackoverflow.com/questions/27835619/ssl-certificate-verify-failed-error

            In Kodi v16, python would not verify the SSL certs or at least ignore, but they changed
            with the upgrade to v17.  Sometimes the cert from the initial decrypted URL is invalid,
            so to avoid errors, we temporarily disable SSL to get the resolved URL.  Although this
            workaround isn't secure, I figure it's not any worse than before...
        '''
        try:
            url = urlresolver.resolve(self.link)
        except:
            helper.log_debug(
                'Attempt to resolve URL failed; trying again with SSL temporarily disabled (v16 behavior)'
            )
            import ssl
            default_context = ssl._create_default_https_context  # save default context
            ssl._create_default_https_context = ssl._create_unverified_context
            url = urlresolver.resolve(self.link)
            ssl._create_default_https_context = default_context  # restore default context

        helper.log_debug("UrlResolver's resolved link: %s" % url)
        helper.resolve_url(url)
예제 #3
0
    def __login(self, username, password):
        #url = helper.domain_url() + '/user/ajax/login'
        form_data = {'username': username, 'password': password, 'remember': 1}

        ts = re.search('ts=\"(.*?)\"', self.html).group(1)
        url_base = re.search('href=\"(.*?)\"', self.html).group(1)

        params = [('username', str(username)), ('password', str(password)),
                  ('remember', '1'), ('ts', str(ts))]
        extra_para = self.__get_extra_url_parameter(params)  #1673
        url = '%s/user/ajax/login?ts=%s&_=%s' % (url_base, ts, extra_para)

        #helper.show_error_dialog(['',str(extra_para)])
        json = self.net.get_json(url, self.cookies, helper.domain_url(),
                                 form_data)
        helper.log_debug('login response: %s' % json)
        #helper.show_error_dialog(['',str(json)])

        if helper.handle_json_errors(json) or json.get('success',
                                                       False) == False:
            return False

        helper.set_setting('username', username)
        helper.set_setting('password', password)
        return True
    def add_items(self):
        helper.start('EpisodeList.add_items')
        if self.links == []:
            return

        half_eps = 0
        episodes = []
        for link in self.links:
            num = link['data-base']  #.string.strip()
            url = link['href']
            if self.__is_half_episode(num):  # 1a and 1b
                half_eps += 1

            episodes.append((num, url))

        self.num_episodes = len(episodes)

        helper.log_debug(
            'We have effectively %d episodes with %d half episodes' %
            (self.num_episodes, half_eps))

        all_metadata = self.get_metadata(args.base_title)
        helper.log_debug('We have %d metadata entries' % len(all_metadata))
        offset = -1
        for idx, (name, url) in enumerate(episodes):
            if self.__is_half_episode(name):
                offset -= 1
            metadata = all_metadata[
                int(name) +
                offset] if int(name) + offset < len(all_metadata) else {
                    'title': name
                }
            icon, fanart = self._get_art_from_metadata(metadata)
            query = self._construct_query(url,
                                          'qualityPlayer',
                                          metadata,
                                          media_type=self.media_type)
            cm_items = self._get_contextmenu_items()
            if helper.get_setting('enable-metadata') == 'true':
                metadata['title'] = '%s - %s' % (name, metadata['title'])
            #helper.show_error_dialog(['',str(query)])
            helper.add_video_item(query,
                                  metadata,
                                  img=icon,
                                  fanart=fanart,
                                  contextmenu_items=cm_items)

        self._add_related_links()

        helper.set_content('episodes')
        helper.add_sort_methods(['episode', 'title'])
        helper.end_of_directory()
        helper.end('EpisodeList.add_items')
        return
예제 #5
0
    def parse(self):
        if self.soup == None:
            return

        helper.start('MediaList.parse')
        timestamper = t_s.TimeStamper('MediaList.parse')
        self.links, self.data_tips, self.media_type_list = self._parse_links_from_grid()
        helper.log_debug('# of links found with class=name: %d' % len(self.links))
        self._find_next_page_link()
        helper.end('MediaList.parse')
        timestamper.stamp_and_dump()
예제 #6
0
    def __get_best_link_for_preset_quality(self, links):
        preset_quality = int(helper.get_setting('preset-quality').strip('p'))
        url_to_play = None
        for item in links:
            quality = item['label']
            if preset_quality >= int(quality.strip('p')):
                helper.log_debug(
                    'Found media to play at matching quality: %s' % quality)
                url_to_play = item['file']
                break

        if url_to_play == None:
            helper.log_debug(
                'No matching quality found; using the lowest available')
            url_to_play = links[-1]['file']

        return url_to_play
    def __init__(self, url_val=args.value, form_data=None):
        self.html = ''
        self.soup = None
        self.links = []
        self.has_next_page = False

        self.meta = metadatahandler.meta
        self.net, self.cookies = nethelper.net, nethelper.cookies

        if not url_val:
            return

        self.url = url_val if 'http' in url_val else (helper.domain_url() +
                                                      url_val)
        self.html, e = self.net.get_html(self.url, self.cookies,
                                         helper.domain_url(), form_data)
        self.html = helper.handle_html_errors(self.html, e)
        helper.log_debug('HTML length: %s' % len(self.html))

        self.soup = BeautifulSoup(self.html,
                                  "html.parser") if self.html != '' else None
예제 #8
0
    def get_metadata(self, name):
        if helper.get_setting('enable-metadata') == 'false':
            return {}

        # If we have no previous metadata, and this isn't a mismatch, then
        # we've already had a legitimate try with no luck.
        if not self.mismatch and (args.imdb_id == None and args.tmdb_id == None):
            helper.log_debug('Not a mismatch and no previous results for movie')
            return {}
        
        imdb_id = args.imdb_id if args.imdb_id and not self.mismatch else ''
        tmdb_id = args.tmdb_id if args.tmdb_id and not self.mismatch else ''
        should_update = self.mismatch
        metadata = self.meta.get_meta('movie', name, imdb_id, tmdb_id, update=should_update)

        # Delete mismtached entries from the tv show cache, since they're not tv shows
        if self.mismatch:
            self.meta.update_meta_to_nothing('tvshow', name)
            helper.log_debug('Movie mismatch - new meta: %s' % str(self.meta))

        return metadata
예제 #9
0
    def search_and_update(self):
        # Grab the search string from the user
        while True:
            idx = helper.present_selection_dialog(
                'Choose a title to search for', self.options)
            helper.log_debug('User selected index %d' % idx)
            if idx == -1:
                helper.show_small_popup('Cancelled attempt to fix metadata')
                return

            default_text = self.options[idx] if idx != 0 else ''
            search_string = helper.get_user_input(
                'Type the show to find metadata for', default_text)
            if search_string == None:
                helper.log_debug('User cancelled manual metadata search')
                return
            elif not search_string:
                helper.show_ok_dialog(
                    ['Invalid search query.  Please try again'])
            else:
                break

        helper.show_busy_notification()

        # Grab the metadata
        from resources.lib.lists import medialist
        mlist = medialist.MediaList(None)
        metadata, media_type = mlist.get_metadata(search_string,
                                                  self.ep_list.media_type)
        if media_type == 'special':
            media_type = 'tvshow'
        helper.log_debug('search and update media type: %s' % media_type)

        # Grab the ID and the actual title, which might have gotten stripped of
        # the year because of a mismatch...
        if media_type == 'movie':
            tmdb_id = metadata.get('tmdb_id', '')
            actual_title = mlist.clean_name(args.full_title)
        else:
            tmdb_id = metadata.get('tvdb_id', '')
            actual_title = mlist.clean_tv_show_name(
                mlist.clean_name(args.full_title))

        helper.log_debug('Metadatafinder results: %s, %s, %s' %
                         (tmdb_id, media_type, metadata))
        if tmdb_id:
            helper.log_debug(
                'Found metadata from search for %s; refreshing the page' %
                args.base_title)
            helper.show_small_popup(
                msg='Updating show with newly found metadata...')
            self.meta.update_meta(media_type,
                                  actual_title,
                                  imdb_id='',
                                  new_tmdb_id=tmdb_id,
                                  new_imdb_id=metadata.get('imdb_id'))
            helper.refresh_page()
        else:
            helper.show_ok_dialog([
                'Did not find any metadata from the search query.  Please try again.'
            ])
        helper.close_busy_notification()
예제 #10
0
 def __init__(self, url=''):
     helper.log_debug('Initializing VideoPlayer with url: %s' % url)
     self.link = url