Skip to content

Commit 5916ed6

Browse files
committed
Steam API
1 parent f6825bb commit 5916ed6

File tree

3 files changed

+143
-28
lines changed

3 files changed

+143
-28
lines changed

README.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,52 @@ Search a movie, series, anime, game, music release or wiki article by its name a
1010
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.
1111

1212
#### Templates
13-
The plugin allows you to set a template note that gets added to the end of any note created by this plugin.
14-
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.
13+
The plugin allows you to set a template note that gets added to the end of any note created by this plugin.
14+
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.
1515
Note that "template tags" are surrounded with two curly braces and that the spaces inside the curly braces are important.
1616

1717
For arrays there are two special ways of displaying them.
1818
- using `{{ LIST:variable_name }}` will result in
19-
```
20-
- element 1
21-
- element 2
22-
- element 3
23-
- ...
24-
```
19+
```
20+
- element 1
21+
- element 2
22+
- element 3
23+
- ...
24+
```
2525
- using `{{ ENUM:variable_name }}` will result in
26-
```
27-
element 1, element 2, element 3, ...
28-
```
26+
```
27+
element 1, element 2, element 3, ...
28+
```
2929

3030
Available variables that can be used in template tags are the same variables from the metadata of the note.
3131

3232
I also published my own templates [here](https://github.com/mProjectsCode/obsidian-media-db-templates).
3333

3434
### How to install
35-
Currently, you have to manually download the zip archive from the latest release here on GitHub.
35+
Currently, you have to manually download the zip archive from the latest release here on GitHub.
3636
After downloading, extract the archive into the `.obsidian/plugins` folder in your vault.
3737

3838
The folder structure should look like this:
39-
```
40-
[path to your vault]
41-
|_ .obsidian
42-
|_ plugins
43-
|_ obsidian-media-db-plugin
44-
|_ main.js
45-
|_ manifest.json
46-
|_ styles.css
47-
```
48-
49-
Once the plugin submission goes through, the plugin will also be installable directly through obsidian's plugin installer.
39+
```
40+
[path to your vault]
41+
|_ .obsidian
42+
|_ plugins
43+
|_ obsidian-media-db-plugin
44+
|_ main.js
45+
|_ manifest.json
46+
|_ styles.css
47+
```
48+
49+
Once the plugin submission goes through, the plugin will also be installable directly through obsidian's plugin installer.
5050

5151
### How to use
5252
(pictures are coming)
5353

54-
Once you have installed this plugin, you will find a database icon in the left ribbon.
55-
When using this or the `Add new Media DB entry` command, a popup will open.
54+
Once you have installed this plugin, you will find a database icon in the left ribbon.
55+
When using this or the `Add new Media DB entry` command, a popup will open.
5656
Here you can enter the title of what you want to search for and then select in which APIs to search.
5757

58-
After clicking search, a new popup will open prompting you to select from the search results.
58+
After clicking search, a new popup will open prompting you to select from the search results.
5959
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.
6060

6161
### 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
7171
| [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 |
7272
| [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 |
7373
| [MusicBrainz](https://musicbrainz.org/) | MusicBrainz is an API that offers information about music releases. | music releases | No | 50 per second | No |
74-
| [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) | The Wikipedia API allows acces to all Wikipedia articles. | wiki articles | No | None | No |
74+
| [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) | The Wikipedia API allows access to all Wikipedia articles. | wiki articles | No | None | No |
75+
| [Steam](https://store.steampowered.com/) | The Steam API offers information on all steam games. | games | No | 10000 per day | No |
7576

7677
#### Notes
7778
- [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
8990
- you can find this ID in the URL
9091
- e.g. for "Rogue One" the URL looks like this `https://www.imdb.com/title/tt3748528/` so the ID is `tt3748528`
9192
- [MusicBrainz](https://musicbrainz.org/)
92-
- the id of a release is not easily accessibe, you are better of just searching by title
93+
- the id of a release is not easily accessible, you are better off just searching by title
9394
- [Wikipedia](https://en.wikipedia.org/wiki/Main_Page)
9495
- [here](https://en.wikipedia.org/wiki/Wikipedia:Finding_a_Wikidata_ID) is a guide to finding the Wikipedia ID for an article
96+
- [Steam](https://store.steampowered.com/)
97+
- you can find this ID in the URL
98+
- e.g. for "Factorio" the URL looks like this `https://store.steampowered.com/app/427520/Factorio/` so the ID is `427520`
9599

96100
### Problems, unexpected behavior or improvement suggestions?
97101
You are more than welcome to open an issue on [GitHub](https://github.com/mProjectsCode/obsidian-media-db-plugin/issues).

src/api/apis/SteamAPI.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import {APIModel} from '../APIModel';
2+
import {MediaTypeModel} from '../../models/MediaTypeModel';
3+
import {MovieModel} from '../../models/MovieModel';
4+
import MediaDbPlugin from '../../main';
5+
import {SeriesModel} from '../../models/SeriesModel';
6+
import {GameModel} from '../../models/GameModel';
7+
import {contactEmail, debugLog, pluginName} from '../../utils/Utils';
8+
import {requestUrl} from 'obsidian';
9+
import {MediaType} from '../../utils/MediaType';
10+
11+
export class SteamAPI extends APIModel {
12+
plugin: MediaDbPlugin;
13+
typeMappings: Map<string, string>;
14+
15+
constructor(plugin: MediaDbPlugin) {
16+
super();
17+
18+
this.plugin = plugin;
19+
this.apiName = 'SteamAPI';
20+
this.apiDescription = 'A free API for all Steam games.';
21+
this.apiUrl = 'http://www.steampowered.com/';
22+
this.types = ['games'];
23+
this.typeMappings = new Map<string, string>();
24+
this.typeMappings.set('game', 'game');
25+
}
26+
27+
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
28+
console.log(`MDB | api "${this.apiName}" queried by Title`);
29+
30+
const searchUrl = `http://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json`;
31+
const fetchData = await requestUrl({
32+
url: searchUrl,
33+
});
34+
35+
if (fetchData.status !== 200) {
36+
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
37+
}
38+
39+
const data = await fetchData.json;
40+
41+
debugLog(data);
42+
43+
let filteredData = [];
44+
45+
for (const app of data.applist.apps) {
46+
if (app.name.toLowerCase().includes(title.toLowerCase())) {
47+
filteredData.push(app);
48+
}
49+
if (filteredData.length > 20) {
50+
break;
51+
}
52+
}
53+
54+
let ret: MediaTypeModel[] = [];
55+
56+
for (const result of filteredData) {
57+
ret.push(new GameModel({
58+
type: MediaType.Game,
59+
title: result.name,
60+
englishTitle: result.name,
61+
year: '',
62+
dataSource: this.apiName,
63+
id: result.appid,
64+
} as GameModel));
65+
}
66+
67+
return ret;
68+
}
69+
70+
async getById(item: MediaTypeModel): Promise<MediaTypeModel> {
71+
console.log(`MDB | api "${this.apiName}" queried by ID`);
72+
73+
const searchUrl = `http://store.steampowered.com/api/appdetails?appids=${item.id}`;
74+
const fetchData = await requestUrl({
75+
url: searchUrl,
76+
});
77+
78+
if (fetchData.status !== 200) {
79+
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
80+
}
81+
82+
const result = (await fetchData.json)[item.id].data;
83+
84+
debugLog(result);
85+
86+
const model = new GameModel({
87+
type: MediaType.Game,
88+
title: result.name,
89+
englishTitle: result.name,
90+
year: (new Date(result.release_date.date)).getFullYear().toString(),
91+
dataSource: this.apiName,
92+
url: `https://store.steampowered.com/app/${result.id}`,
93+
id: result.steam_appid,
94+
95+
genres: result.genres?.map((x: any) => x.description) ?? [],
96+
onlineRating: Number.parseFloat(result.metacritic?.score ?? 0),
97+
image: result.header_image ?? '',
98+
99+
released: !result.release_date?.comming_soon,
100+
releaseDate: (new Date(result.release_date?.date)).toLocaleDateString() ?? 'unknown',
101+
102+
played: false,
103+
personalRating: 0,
104+
} as GameModel);
105+
106+
return model;
107+
108+
}
109+
}

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {MediaDbIdSearchModal} from './modals/MediaDbIdSearchModal';
1111
import {WikipediaAPI} from './api/apis/WikipediaAPI';
1212
import {MusicBrainzAPI} from './api/apis/MusicBrainzAPI';
1313
import {MediaTypeManager} from './utils/MediaTypeManager';
14+
import {SteamAPI} from './api/apis/SteamAPI';
1415

1516
export default class MediaDbPlugin extends Plugin {
1617
settings: MediaDbPluginSettings;
@@ -55,6 +56,7 @@ export default class MediaDbPlugin extends Plugin {
5556
this.apiManager.registerAPI(new MALAPI(this));
5657
this.apiManager.registerAPI(new WikipediaAPI(this));
5758
this.apiManager.registerAPI(new MusicBrainzAPI(this));
59+
this.apiManager.registerAPI(new SteamAPI(this));
5860
// this.apiManager.registerAPI(new LocGovAPI(this)); // TODO: parse data
5961

6062
this.mediaTypeManager = new MediaTypeManager(this.settings);

0 commit comments

Comments
 (0)