Skip to content

Instantly share code, notes, and snippets.

@leonekmi
Last active December 14, 2018 23:40
Show Gist options
  • Save leonekmi/0dac600f27fdad92ab757aacebedf77d to your computer and use it in GitHub Desktop.
Save leonekmi/0dac600f27fdad92ab757aacebedf77d to your computer and use it in GitHub Desktop.
Create a library website support for Scrobbly.

Create a website support - Chapter 2

Library websites

These instructions are for library websites (eg. Kitsu), instructions for other types of websites are here.

A snippet is joined in this Gist, it is documented and it contains all the instructions down below.

After that...

Don't forget to add your library at daemon.js.

var lanifan = require('./libraries/anifan');

var libraries = [..., new lanifan(storage.anifan_credentials)];

If your app needs some configuration on scrobbly.leonekmi.fr or an client id/secret, let me create an app in the name of Scrobbly, i will do the necessary. Thanks!

When you finished that, you can submit a pull request on master and i will review it.

Thanks for support!

/*
Scrobbly is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Scrobbly is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Scrobbly. If not, see <https://www.gnu.org/licenses/>.
*/
module.exports = class AniFan { // Change the name to the full site name.
constructor (credentials) {
this.browser = require('webextension-polyfill');
// You can add npm packages to help you on data requests.
this.credentials = credentials;
if (credentials) {
this.ready = true;
} else {
this.ready = false;
}
}
isReady() {
return this.ready;
}
init() {
// Initialize API components
return true;
}
getAnimeData(text) {
return new Promise(resolve => {
var animes = [];
// Retrieve data here
data.forEach(el => {
// Data must be formatted like that to avoid conflicts and incompatibilites.
animes.push({
id: el.id,
title: el.animeTitle,
episodes: el.episodes,
episodeDuration: (el.episodeLength != 0 && typeof el.episodeLength == 'number') ? el.episodeLength:'none',
cover: (el.coverImage) ? el.coverImage:this.browser.runtime.getURL('pages/img/none.png'),
synopsis: el.description
});
});
resolve(animes);
});
}
updateLibrary(working) {
return new Promise(resolve => {
// working is an object
// - anime is the anime object
// - progress is the progress object that you send in getProgress()
});
}
getProgress(animeId) {
return new Promise(resolve => {
resolve({
progress: (condition) ? result.data[0].progress:0, // Episode progress
create: (condition) ? true:false, // Some libraries has different routes for creating and updating a library entry, use this to remember what to do
id: (condition) ? result.id:false // Some libraries need the id of the library entry to patch it, use this to remember it.
});
});
}
get info() { // This is for internal reference only
return {
name: 'anifan', // lower letters only
url: 'https://anifan.com/',
auth: 'bearer'
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment