Steam API

This commit is contained in:
mProjectsCode 2022-05-29 20:01:33 +02:00
parent f6825bbadc
commit 5916ed66eb
3 changed files with 142 additions and 27 deletions

View file

@ -10,52 +10,52 @@ Search a movie, series, anime, game, music release or wiki article by its name a
Allows you to search by an ID that varies from API to API. Concrete information on this feature can be found in the description of the individual APIs. Allows you to search by an ID that varies from API to API. Concrete information on this feature can be found in the description of the individual APIs.
#### Templates #### Templates
The plugin allows you to set a template note that gets added to the end of any note created by this plugin. The plugin allows you to set a template note that gets added to the end of any note created by this plugin.
The plugin also offers simple "template tgs". E.g. if the template includes `{{ title }}`, it will be replaced by the title of the movie, show or game. The plugin also offers simple "template tgs". E.g. if the template includes `{{ title }}`, it will be replaced by the title of the movie, show or game.
Note that "template tags" are surrounded with two curly braces and that the spaces inside the curly braces are important. Note that "template tags" are surrounded with two curly braces and that the spaces inside the curly braces are important.
For arrays there are two special ways of displaying them. For arrays there are two special ways of displaying them.
- using `{{ LIST:variable_name }}` will result in - using `{{ LIST:variable_name }}` will result in
``` ```
- element 1 - element 1
- element 2 - element 2
- element 3 - element 3
- ... - ...
``` ```
- using `{{ ENUM:variable_name }}` will result in - using `{{ ENUM:variable_name }}` will result in
``` ```
element 1, element 2, element 3, ... element 1, element 2, element 3, ...
``` ```
Available variables that can be used in template tags are the same variables from the metadata of the note. Available variables that can be used in template tags are the same variables from the metadata of the note.
I also published my own templates [here](https://github.com/mProjectsCode/obsidian-media-db-templates). I also published my own templates [here](https://github.com/mProjectsCode/obsidian-media-db-templates).
### How to install ### How to install
Currently, you have to manually download the zip archive from the latest release here on GitHub. Currently, you have to manually download the zip archive from the latest release here on GitHub.
After downloading, extract the archive into the `.obsidian/plugins` folder in your vault. After downloading, extract the archive into the `.obsidian/plugins` folder in your vault.
The folder structure should look like this: The folder structure should look like this:
``` ```
[path to your vault] [path to your vault]
|_ .obsidian |_ .obsidian
|_ plugins |_ plugins
|_ obsidian-media-db-plugin |_ obsidian-media-db-plugin
|_ main.js |_ main.js
|_ manifest.json |_ manifest.json
|_ styles.css |_ styles.css
``` ```
Once the plugin submission goes through, the plugin will also be installable directly through obsidian's plugin installer. Once the plugin submission goes through, the plugin will also be installable directly through obsidian's plugin installer.
### How to use ### How to use
(pictures are coming) (pictures are coming)
Once you have installed this plugin, you will find a database icon in the left ribbon. Once you have installed this plugin, you will find a database icon in the left ribbon.
When using this or the `Add new Media DB entry` command, a popup will open. When using this or the `Add new Media DB entry` command, a popup will open.
Here you can enter the title of what you want to search for and then select in which APIs to search. Here you can enter the title of what you want to search for and then select in which APIs to search.
After clicking search, a new popup will open prompting you to select from the search results. After clicking search, a new popup will open prompting you to select from the search results.
Now you select the result you want and the plugin will cast it's magic and create a new note in your vault, that contains the metadata of the selected search result. Now you select the result you want and the plugin will cast it's magic and create a new note in your vault, that contains the metadata of the selected search result.
### Currently supported media types ### Currently supported media types
@ -71,7 +71,8 @@ Now you select the result you want and the plugin will cast it's magic and creat
| [Jikan](https://jikan.moe/) | Jikan is an API that uses [My Anime List](https://myanimelist.net) and offers metadata for anime. | series, movies, specials, OVAs | No | 60 per minute and 3 per second | Yes | | [Jikan](https://jikan.moe/) | Jikan is an API that uses [My Anime List](https://myanimelist.net) and offers metadata for anime. | series, movies, specials, OVAs | No | 60 per minute and 3 per second | Yes |
| [OMDb](https://www.omdbapi.com/) | OMDb is an API that offers metadata for movie, series and games. | series, movies, games | Yes, you can get a free key here [here](https://www.omdbapi.com/apikey.aspx) | 1000 per day | No | | [OMDb](https://www.omdbapi.com/) | OMDb is an API that offers metadata for movie, series and games. | series, movies, games | Yes, you can get a free key here [here](https://www.omdbapi.com/apikey.aspx) | 1000 per day | No |
| [MusicBrainz](https://musicbrainz.org/) | MusicBrainz is an API that offers information about music releases. | music releases | No | 50 per second | No | | [MusicBrainz](https://musicbrainz.org/) | MusicBrainz is an API that offers information about music releases. | music releases | No | 50 per second | No |
| [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) | The Wikipedia API allows acces to all Wikipedia articles. | wiki articles | No | None | No | | [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) | The Wikipedia API allows access to all Wikipedia articles. | wiki articles | No | None | No |
| [Steam](https://store.steampowered.com/) | The Steam API offers information on all steam games. | games | No | 10000 per day | No |
#### Notes #### Notes
- [Jikan](https://jikan.moe/) - [Jikan](https://jikan.moe/)
@ -89,9 +90,12 @@ Now you select the result you want and the plugin will cast it's magic and creat
- you can find this ID in the URL - you can find this ID in the URL
- e.g. for "Rogue One" the URL looks like this `https://www.imdb.com/title/tt3748528/` so the ID is `tt3748528` - e.g. for "Rogue One" the URL looks like this `https://www.imdb.com/title/tt3748528/` so the ID is `tt3748528`
- [MusicBrainz](https://musicbrainz.org/) - [MusicBrainz](https://musicbrainz.org/)
- the id of a release is not easily accessibe, you are better of just searching by title - the id of a release is not easily accessible, you are better off just searching by title
- [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) - [Wikipedia](https://en.wikipedia.org/wiki/Main_Page)
- [here](https://en.wikipedia.org/wiki/Wikipedia:Finding_a_Wikidata_ID) is a guide to finding the Wikipedia ID for an article - [here](https://en.wikipedia.org/wiki/Wikipedia:Finding_a_Wikidata_ID) is a guide to finding the Wikipedia ID for an article
- [Steam](https://store.steampowered.com/)
- you can find this ID in the URL
- e.g. for "Factorio" the URL looks like this `https://store.steampowered.com/app/427520/Factorio/` so the ID is `427520`
### Problems, unexpected behavior or improvement suggestions? ### Problems, unexpected behavior or improvement suggestions?
You are more than welcome to open an issue on [GitHub](https://github.com/mProjectsCode/obsidian-media-db-plugin/issues). You are more than welcome to open an issue on [GitHub](https://github.com/mProjectsCode/obsidian-media-db-plugin/issues).

109
src/api/apis/SteamAPI.ts Normal file
View file

@ -0,0 +1,109 @@
import {APIModel} from '../APIModel';
import {MediaTypeModel} from '../../models/MediaTypeModel';
import {MovieModel} from '../../models/MovieModel';
import MediaDbPlugin from '../../main';
import {SeriesModel} from '../../models/SeriesModel';
import {GameModel} from '../../models/GameModel';
import {contactEmail, debugLog, pluginName} from '../../utils/Utils';
import {requestUrl} from 'obsidian';
import {MediaType} from '../../utils/MediaType';
export class SteamAPI extends APIModel {
plugin: MediaDbPlugin;
typeMappings: Map<string, string>;
constructor(plugin: MediaDbPlugin) {
super();
this.plugin = plugin;
this.apiName = 'SteamAPI';
this.apiDescription = 'A free API for all Steam games.';
this.apiUrl = 'http://www.steampowered.com/';
this.types = ['games'];
this.typeMappings = new Map<string, string>();
this.typeMappings.set('game', 'game');
}
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
console.log(`MDB | api "${this.apiName}" queried by Title`);
const searchUrl = `http://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json`;
const fetchData = await requestUrl({
url: searchUrl,
});
if (fetchData.status !== 200) {
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
}
const data = await fetchData.json;
debugLog(data);
let filteredData = [];
for (const app of data.applist.apps) {
if (app.name.toLowerCase().includes(title.toLowerCase())) {
filteredData.push(app);
}
if (filteredData.length > 20) {
break;
}
}
let ret: MediaTypeModel[] = [];
for (const result of filteredData) {
ret.push(new GameModel({
type: MediaType.Game,
title: result.name,
englishTitle: result.name,
year: '',
dataSource: this.apiName,
id: result.appid,
} as GameModel));
}
return ret;
}
async getById(item: MediaTypeModel): Promise<MediaTypeModel> {
console.log(`MDB | api "${this.apiName}" queried by ID`);
const searchUrl = `http://store.steampowered.com/api/appdetails?appids=${item.id}`;
const fetchData = await requestUrl({
url: searchUrl,
});
if (fetchData.status !== 200) {
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
}
const result = (await fetchData.json)[item.id].data;
debugLog(result);
const model = new GameModel({
type: MediaType.Game,
title: result.name,
englishTitle: result.name,
year: (new Date(result.release_date.date)).getFullYear().toString(),
dataSource: this.apiName,
url: `https://store.steampowered.com/app/${result.id}`,
id: result.steam_appid,
genres: result.genres?.map((x: any) => x.description) ?? [],
onlineRating: Number.parseFloat(result.metacritic?.score ?? 0),
image: result.header_image ?? '',
released: !result.release_date?.comming_soon,
releaseDate: (new Date(result.release_date?.date)).toLocaleDateString() ?? 'unknown',
played: false,
personalRating: 0,
} as GameModel);
return model;
}
}

View file

@ -11,6 +11,7 @@ import {MediaDbIdSearchModal} from './modals/MediaDbIdSearchModal';
import {WikipediaAPI} from './api/apis/WikipediaAPI'; import {WikipediaAPI} from './api/apis/WikipediaAPI';
import {MusicBrainzAPI} from './api/apis/MusicBrainzAPI'; import {MusicBrainzAPI} from './api/apis/MusicBrainzAPI';
import {MediaTypeManager} from './utils/MediaTypeManager'; import {MediaTypeManager} from './utils/MediaTypeManager';
import {SteamAPI} from './api/apis/SteamAPI';
export default class MediaDbPlugin extends Plugin { export default class MediaDbPlugin extends Plugin {
settings: MediaDbPluginSettings; settings: MediaDbPluginSettings;
@ -55,6 +56,7 @@ export default class MediaDbPlugin extends Plugin {
this.apiManager.registerAPI(new MALAPI(this)); this.apiManager.registerAPI(new MALAPI(this));
this.apiManager.registerAPI(new WikipediaAPI(this)); this.apiManager.registerAPI(new WikipediaAPI(this));
this.apiManager.registerAPI(new MusicBrainzAPI(this)); this.apiManager.registerAPI(new MusicBrainzAPI(this));
this.apiManager.registerAPI(new SteamAPI(this));
// this.apiManager.registerAPI(new LocGovAPI(this)); // TODO: parse data // this.apiManager.registerAPI(new LocGovAPI(this)); // TODO: parse data
this.mediaTypeManager = new MediaTypeManager(this.settings); this.mediaTypeManager = new MediaTypeManager(this.settings);