Skip to content

Adding a New Parser

Andy Luhrs edited this page Mar 9, 2020 · 1 revision

Add the SourceSite

The first thing to do is define the basic SourceSite:

  1. Create MiniIndex.Models/SourceSites/<SiteName>Source.cs
  2. Copy basics from another SourceSite (I recommend Cults3d).
  3. Change the naming to match your SourceSite.
  4. Update BaseUri to the URL relative to the Creator's page, for example https://www.myminifactory.com/users/ is the BaseUri for https://www.myminifactory.com/users/Evocatus%20miniature

Write the parser

The actual parser is the main thing to focus on getting right. You can refer to the existing parsers in MiniIndex.Core/Minis/Parsers/ for references on what a parser does, they're all fairly simple. Most websites don't have an API, so we use HTMLAgilityPack to parse the actual HTML.

Required Fields

  • Creator URL - The URL of the profile of the person who uploaded/created the Mini
  • Creator Name - The username of the creator.
  • Mini Name - The name/title of the Mini.
  • Thumbnail URL - The URL for a picture of the Mini.
  • Link - The URL to the Mini.
  • Cost - The cost of the Mini (0 for free).

API Parser

TODO - Reach out to us if you want to parse a website using it's API and we'll fill this in together :). Right now we only do this for Thingiverse, and it's a bit more involved with "ownership" of API keys and rate limiting.

HTML Parser

Look through the existing HTML Parsers for references to how to do this right. Things like Thumbnail and Mini name can likely be parsed easily from meta tags like og:image that are generally well-used for social media websites. Others might be a bit harder and can be done by looking at various header tags or if you're lucky have the ID field used.

  1. Create the parser file - MiniIndex.Core/Minis/Parsers/<SiteName>/<SiteName>Parser.cs
  2. Implement CanParse - CanParse parses the URL to determine if this parser should parse it. It should do everything possible to ensure that the given URL is a valid model, and not a user, profile, or other page.
  3. Implement ParseFromUrl - This manually parses through the HTML of the website to make a Creator object and returns a Mini object.
  4. Parse Creator information - In the previous step you defined the structure of the URL and you'll declare your creator here based off the URL and creator name.
  5. Parse the Mini information -

Instantiate the SourceSite

Every SourceSite much be instantiated in MiniIndex.Persistence/Configuration/SourceSiteEntityConfiguration.cs, simply add .HasValue<Cults3dSource>("<SiteName>")

Add CSS

Styling for each site individually is done in MiniIndex/wwwroot/css/site.css, follow the outline below, trying to use the site's primary color for the button background. Make sure your PNG has transparency and isn't massive.

.thumb-wrapper.<SiteName> span {
    `background: transparent url('../images/SourceSiteIcons/<SiteName>.png') no-repeat;
}

.<SiteName> {
    background-color: #<Site's primary color> !important;
    border-color: #<Site's primary color> !important;
    color: <white or black depending on background> !important;
}

Manually test it

Make sure you do basic testing:

  1. Free Minis parse properly and show up when the "Free Only" checkbox is used.
  2. Paid Minis parse properly and don't show up when the "Free Only" checkbox is used.
  3. The link to the Mini works.
  4. The link on the Creator's page to their profile works.
  5. Names with potentially special characters like & or " parse properly.
  6. The icon on the browse pages looks good.
  7. The coloring of the button is good and has good contrast with the text.