Exemple #1
0
 def _try_parse_value(cls, vals: utils.misc.dotdict, child: lxml.objectify.ObjectifiedElement, tag: str, text: str, custom_types: CustomTypes) -> bool:
     if tag == 'icon_url':
         vals.icon_url = text
     elif tag == 'banner_url':
         vals.banner_url = text
     elif tag == 'thumbnail_url':
         vals.thumbnail_url = text
     elif tag == 'title':
         xmlutils.validate_schema(child, {'name': None, 'icon_url': None, 'banner_url': None, 'thumbnails': {'thumbnail': None}}, True)
         if hasattr(child, 'thumbnails'):
             thumbnails = [common.SamuraiThumbnail._parse(t) for t in child.thumbnails.thumbnail]
         else:
             thumbnails = []
         vals.title = SamuraiMovieLinkedTitle(
             ids.ContentID(child.get('id')),
             child.name.text,
             xmlutils.get_text(child, 'icon_url'),
             xmlutils.get_text(child, 'banner_url'),
             thumbnails
         )
     elif tag == 'rating_info':
         vals.rating_info = custom_types['rating_info']._parse(child)
     else:
         return False
     return True
Exemple #2
0
    def _read(self, reader, config):
        ec_info = xmlutils.load_root(reader, 'title_ec_info')
        xmlutils.validate_schema(
            ec_info, {
                'title_id': None,
                'content_size': None,
                'title_version': None,
                'disable_download': None,
                'content_lock': {
                    'seed_published': None,
                    'external_seed': None,
                    'playable_date': None
                }
            }, True)

        self.title_id = ids.TitleID(ec_info.title_id.text)
        self.content_size = int(ec_info.content_size.text)
        self.version = int(ec_info.title_version.text)
        self.download_disabled = utils.misc.get_bool(
            ec_info.disable_download.text)

        if hasattr(ec_info, 'content_lock'):
            self.seed_published = utils.misc.get_bool(
                ec_info.content_lock.seed_published.text)
            self.external_seed = xmlutils.get_text(ec_info.content_lock,
                                                   'external_seed')
            self.playable_date = xmlutils.get_text(ec_info.content_lock,
                                                   'playable_date')
Exemple #3
0
    def _read_title(self, title):
        assert xmlutils.get_child_tags(title) <= {
            'name', 'aocs_banner_url', 'aocs_description', 'aocs'
        }
        self.name = title.name.text
        self.banner_url = xmlutils.get_text(title, 'aocs_banner_url')
        self.description = xmlutils.get_text(title, 'description')

        self._read_dlcs(title.aocs)
Exemple #4
0
 def _parse_internal(cls, xml):
     return {
         'required': utils.misc.get_bool(xml.get('required')),
         'type': int(xml.get('type')),
         'id': int(xml.id.text),
         'name': xml.name.text,
         'icons': [common.SamuraiIcon._parse(icon) for icon in xml.icons.icon] if hasattr(xml, 'icons') else None,
         'description': xmlutils.get_text(xml, 'description'),
         'ext_info': xmlutils.get_text(xml, 'ext_info')
     }
Exemple #5
0
    def _try_parse_value(cls, vals: utils.misc.dotdict, child: lxml.objectify.ObjectifiedElement, tag: str, text: str, custom_types: title_list.CustomTypes) -> bool:
        if 'is_public' not in vals:
            xml = child.getparent()
            vals.is_public = utils.misc.get_bool(xml.get('public'))

        if tag == 'formal_name':
            vals.formal_name = text
        elif tag == 'genres':
            vals.genres = []
            for genre in child.genre:
                xmlutils.validate_schema(genre, {'name': None}, False)
                vals.genres.append(common.IDName(int(genre.get('id')), genre.name.text))
        elif tag == 'keywords':
            vals.keywords = [keyword.text for keyword in getattr(child, 'keyword', [])]
        elif tag == 'ticket_available':
            vals.has_ticket = utils.misc.get_bool(text)
        elif tag == 'download_code_sales':
            vals.sales_download_code = utils.misc.get_bool(text)
        elif tag == 'download_card_sales':
            xmlutils.validate_schema(child, {'image_url': None}, True)
            vals.sales_download_card = SamuraiDownloadCardSales(
                utils.misc.get_bool(child.get('available')),
                xmlutils.get_text(child, 'image_url')
            )
        else:
            return super()._try_parse_value(vals, child, tag, text, custom_types)
        return True
Exemple #6
0
 def _parse_internal(cls, xml):
     return {
         'id': int(xml.get('id')),
         'device': xml.get('device'),
         'category': xml.get('category'),
         'name': xml.name.text,
         'icon_url': xmlutils.get_text(xml, 'icon_url')
     }
Exemple #7
0
    def _parse_internal(cls, xml):
        descriptors = []
        if hasattr(xml, 'descriptors') and hasattr(xml.descriptors,
                                                   'descriptor'):
            for d in xml.descriptors.descriptor:
                descriptors.append(
                    SamuraiRatingDescriptor(
                        xmlutils.get_text(d, 'name'),
                        [SamuraiIcon._parse(icon) for icon in d.icons.icon]
                        if hasattr(d, 'icons') else None))

        return {**super()._parse_internal(xml), 'descriptors': descriptors}
Exemple #8
0
def test_xml__get_text(xml_element):
    assert xml.get_text(xml_element.node, 'el2') == 'text2'
    assert xml.get_text(xml_element.node, 'doesnotexist') is None
Exemple #9
0
 def _try_parse_value(cls, vals: utils.misc.dotdict, child: lxml.objectify.ObjectifiedElement, tag: str, text: str, custom_types: title_list.CustomTypes) -> bool:
     if tag == 'package_url':
         vals.package_url = text
     elif tag == 'thumbnails':
         vals.thumbnails = [common.SamuraiThumbnail._parse(t) for t in child.thumbnail]
     elif tag == 'hero_banner_url':
         vals.hero_banner_url = text
     elif tag == 'web_sales':
         vals.sales_web = utils.misc.get_bool(text)
     elif tag == 'top_image':
         xmlutils.validate_schema(child, {'type': None, 'url': None}, False)
         vals.top_image_type = child.type.text
         vals.top_image_url = child.url.text
     elif tag == 'description':
         vals.description = text
     elif tag == 'price_description':
         vals.price_description = text
     elif tag == 'features':
         vals.features = [SamuraiTitleFeature._parse(feature) for feature in child.feature]
     elif tag == 'play_styles':
         xmlutils.validate_schema(child, {'play_style': {
             'controllers': {'controller': {'id': None, 'name': None, 'icons': {'icon': None}}},
             'features': {'feature': SamuraiTitleFeature._get_schema()[0]}}
         }, True)
         vals.play_styles = []
         for play_style in child.play_style:
             if hasattr(play_style, 'controllers'):
                 controllers = [
                     SamuraiTitleController(
                         utils.misc.get_bool(controller.get('required')),
                         int(controller.get('type')),
                         int(controller.id.text),
                         controller.name.text,
                         [common.SamuraiIcon._parse(icon) for icon in controller.icons.icon] if hasattr(controller, 'icons') else None
                     )
                     for controller in play_style.controllers.controller
                 ]
             else:
                 controllers = []
             if hasattr(play_style, 'features'):
                 features = [SamuraiTitleFeature._parse(feature) for feature in play_style.features.feature]
             else:
                 features = []
             vals.play_styles.append(SamuraiTitlePlayStyle(play_style.get('type'), controllers, features))
     elif tag == 'languages':
         vals.languages = []
         for language in child.language:
             xmlutils.validate_schema(language, {'iso_code': None, 'name': None}, False)
             vals.languages.append(SamuraiTitleLanguage(language.iso_code.text, language.name.text))
     elif tag == 'number_of_players':
         # sometimes this field contains additional text in a second line, discard it for now and use the first non-empty line
         cleaned_text = next(line for line in text.replace('<br>', '\n').split('\n') if line)
         matches = re.search(r'(\d+)(?:\s*-\s*(\d+))?', cleaned_text)
         if matches:
             vals.num_players = (int(matches[1]), int(matches[2] or matches[1]))
         elif cleaned_text.startswith('*'):  # disclaimer instead of specific player numbers (example: 50010000037675)
             vals.num_players = None
         elif re.search(r'[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]', cleaned_text):  # ignore errors if text contains japanese/chinese/korean characters
             vals.num_players = None
         else:
             raise RuntimeError(f'Could not parse player details: {text}')
         vals.num_players_raw = text
     elif tag == 'disclaimer':
         vals.disclaimer = text
     elif tag == 'copyright':
         xmlutils.validate_schema(child, {'text': None, 'image_url': None}, True)
         vals.copyright = SamuraiTitleCopyright(child.find('text').text, xmlutils.get_text(child, 'image_url'))
     elif tag == 'screenshots':
         vals.screenshots = [SamuraiTitleScreenshot._parse(screenshot) for screenshot in child.screenshot]
     elif tag == 'main_images':
         vals.main_images = [SamuraiTitleScreenshot._parse(image) for image in child.image]
     elif tag == 'preference':
         target = child.find('target_player')
         style = child.find('play_style')
         vals.preferences = SamuraiTitlePreference(
             SamuraiTitlePreferenceTarget(int(target.everyone.text), int(target.gamers.text)),
             SamuraiTitlePreferenceStyle(int(style.casual.text), int(style.intense.text))
         )
     elif tag == 'web_sites':
         vals.websites = []
         for website in child.web_site:
             xmlutils.validate_schema(website, {'name': None, 'url': None, 'official': None}, False)
             vals.websites.append(SamuraiTitleWebsite(
                 website.name.text,
                 website.url.text,
                 utils.misc.get_bool(website.official.text)
             ))
     elif tag == 'movies':
         vals.movies = [movie_list.SamuraiListMovie._parse(m) for m in child.movie]
     elif tag == 'demo_titles':
         vals.demos = [
             SamuraiTitleLinkedDemo(
                 ids.ContentID(demo.get('id')),
                 demo.name.text,
                 xmlutils.get_text(demo, 'icon_url')
             )
             for demo in child.demo_title
         ]
     elif tag == 'peripheral_description':
         vals.peripheral_description = text
     elif tag == 'network_feature_description':
         vals.network_feature_description = text
     elif tag == 'spec_description':
         vals.spec_description = text
     elif tag == 'data_size':
         vals.size = int(text)
     elif tag == 'alternate_rating_image_url':
         vals.rating_info_alternate_image_url = text
     elif tag == 'save_data_count':
         vals.save_data_count = text
     elif tag == 'save_data_volume':
         vals.save_data_volume = text
     elif tag == 'catch_copy':
         vals.catch_copy = text
     elif tag == 'shared_movies':
         vals.shared_movies = [SamuraiSharedMovie._parse(movie) for movie in child.shared_movie]
     elif tag == 'title_notices':
         xmlutils.validate_schema(child, {'title_notice': {'url': None, 'display_name': None, 'description': None}}, False)
         vals.title_notices = [
             SamuraiTitleNotice(
                 notice.get('type'),
                 notice.url.text,
                 notice.display_name.text,
                 notice.description.text
             )
             for notice in child.title_notice
         ]
     elif tag == 'title_metas':
         xmlutils.validate_schema(child, {'title_meta': {'value': None}}, False)
         vals.title_metas = [(m.get('type'), m.value.text) for m in child.title_meta]
     elif tag == 'digital_manuals':
         xmlutils.validate_schema(child, {'digital_manual': {'name': None, 'url': None}}, False)
         vals.digital_manuals = [SamuraiDigitalManual(manual.name.text, manual.url.text) for manual in child.digital_manual]
     elif tag == 'aoc_infos':
         vals.aoc_infos = text
     else:
         return super()._try_parse_value(vals, child, tag, text, custom_types)
     return True