2.0.0-beta.13.2 • Published 3 years ago

@millenniumearl/f95api v2.0.0-beta.13.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

CodeFactor FOSSA Status Known Vulnerabilities codecov npm

F95API

Unofficial Typescript API used for data scraping from the F95Zone platform.

These APIs have been developed to support this application and allow you to obtain data on games and mods on the platform F95zone (NSFW)

A simple usage example can be found in src/example.ts

Table of Contents

Main features

  • Support for two-factor authentication
  • Structured and typed data of games, mods, comics, assets and animations
  • Structured and typed data of the current user (threads followed, favorites...)
  • Structured and typed data of other users (titles, donations, registration date...)
  • Standard search, through the "Latest Updates" page or advanced
  • Saving of cookies to maintain the session

Login

In addition to traditional login, two-factor authentication via callback that returns the OTP value is also supported.

// Normal login
let result = await F95API.login(username, password);

// 2FA login
let 2faCallback = function () => Promise<number>;
let result = await F95API.login(username, password, 2faCallback);

Refer to src/example.ts (lines 35-67) for a working example.

Data scraping

Each game, mod, comic, animation or asset is identified as handiwork and obtaining this element is generic, it will then be up to the user to decide which property to use based on the type of handiwork that has been requested.

Handiworks can be obtained by query or by URL.

// With query
const query = {
    category: "games";
    keywords = "Your game name";
    order = "likes";
};

let listOfFoundGames = await F95API.searchHandiwork<Game>(query);

// With URL
let specificGame = await F95API.getHandiworkFromURL<Game>("the URL of your game");

While user data (after authenticating) with

const userdata = new UserProfile();

// Fetch basic data (always necessary)
await userdata.fetch();

// Fetch all data (may take a while)
await userdata.fetch(true);

// Async properties
const threads = await userdata.watched;
const bookmarks = await userdata.bookmarks;
const alerts = await userdata.alerts;
const games = await userdata.featuredGames;

Classes

Handiwork

Information about games, mods, etc... are stored in a Handiwork object with the following fields:

Basic properties

This list of properties is common to every handiwork, be it a game, a comic, etc...

PropertyTypeDescription
idnumberUnique ID of the thread associated with the handiwork in the platform
namestringThe handiwork name
overviewstringDescription of the handiwork
authorsTAuthor[]The developer of this handiwork including the platforms on which it can be found
categoryTCategoryThe membership category
changelogTChangelog[]List of changes divided by version
coverstringURL of the possible cover of the handiwork (in case of multiple images the first available is taken)
lastThreadUpdateDateDate of the last update of the thread associated with the handiwork
prefixesstring[]List of prefixes
ratingTRatingUsers' ratings on the handiwork (average, maximum, minimum, number of votes)
tagsstring[]List of tags
threadPublishingDateDatePublication date of the thread associated with the handiwork
urlstringThe URL that leads to the handiwork's thread on F95Zone

Mixed properties

Each property is specific to a particular type of handiwork.

PropertyTypeHandiwork typeDescription
genrestring[]Animation/Comic/GameList of genres represented in this work
pagesstringAnimation/ComicNumber of pages or elements of which the work is composed
resolutionstring[]Animation/ComicList of resolutions available for the work
installationstringAnimationInstallation instructions
languagestring[]AnimationList of available languages
lengthstringAnimationLength of the animation
censoredbooleanAnimation/GameAre the NSFW parts censored?
engineTEngineGameGame engine (Unity, Ren'Py, RPGM...)
lastReleaseDateGameDate of the last update of this handiwork
modbooleanGameSpecify if it is a mod or a real game
osstring[]GameList of supported OS (Windows/Linux/Mac/Android...)
statusTStatusGameState of development (Completed/Abandoned/Ongoing/Onhold)
versionstringGameVersion of the handiwork
assetLinkstringAssetExternal URL of the asset (es. Daz3D store)
associatedAssetsstring[]AssetList of URLs of assets associated with the work (for example same collection)
compatibleSoftwarestring[]AssetSoftware compatible with the work
includedAssetsstring[]AssetList of assets url included in the work or used to develop it
officialLinksstring[]AssetList of official links of the work, external to the platform (es. Daz3D store)
skustringAssetUnique SKU value of the work

The serialization/deserialization in JSON format of this object is possible through JSON.stringify()/JSON.parse().

Platform user

A generic user registered on the platform is represented by a PlatformUser object with the following fields:

PropertyTypeDescription
idnumberUnique user ID
namestringUsername
titlestringTitle assigned to the user by the platform
bannersstring[]List of banners assigned by the platform
messagesnumberNumber of messages written by the user
reactionScorenumberTotal number of reactions received from other users
pointsnumberTotal number of points received after the acquisition of trophies
ratingsReceivednumberNumber of ratings received
joinedDateDate of joining the platform
lastSeenDateDate of the last connection to the platform
followedbooleanIndicates whether the user is followed by the currently logged in user
ignoredbooleanIndicates whether the user is ignored by the currently logged on user
privatebooleanIndicates that the profile is private and not viewable by the user
avatarstringURL of the image used as the user's avatar
amountDonatednumberValue ($) of donations made

User data

The user data currently connected through this API extends the PlatformUser class via the class UserProfile and adds:

PropertyTypeDescription
watchedPromise<IWatchedThread[]>List of followed thread data
bookmarksPromise<IBookmarkedPost[]>List of bookmarked posts data
alertsPromise<IAlert[]>List of alerts
conversationsPromise<IConversation[]>List of conversations (only without labels)
featuredGamesPromise<Game[]>List of featured games from the platform (carousel, may not be available if disabled in settings)

Login results

The outcome of the authentication process is represented by the LoginResult object:

PropertyTypeDescription
successbooleanList of followed thread data
codenumberCode associated with the result of the login operation
messagestringPossible error message (unrecognized user, wrong password...) or authentication successful message

Logging

To log the behavior of the application log4js-api is used with a default level of "warn". This option can be changed with the loggerLevel property.

Guidelines for errors

  • If you can, return a meaningful value
  • Return null only if the function should return a complex object (including strings)
  • Return an empty array if the function should return an array
  • Return false, -1 when the function should return boolean or number
  • Throw an exception only if it is an error or if a wrong value could mess up the functioning of the library
  • For all network operations, return a Result object