Skip to content

Instantly share code, notes, and snippets.

@leonekmi
Created November 28, 2018 13:08
Show Gist options
  • Save leonekmi/eca3a5bf7ce4735280220e595304a8a8 to your computer and use it in GitHub Desktop.
Save leonekmi/eca3a5bf7ce4735280220e595304a8a8 to your computer and use it in GitHub Desktop.
Create an anime streaming website support in Scrobbly

Create a website support - Chapter 1

Streaming websites

These instructions are for streaming websites (eg. Crunchyroll), instructions for other types of websites are here.

There is 2 main cases for streaming websites :

  • The website is static (the page fully reloads when you click a link, eg. Crunchyroll)
  • The website is dynamic (the page is not reloading when you click a link, eg. Netflix)

The website is static

Easy way! Follow the steps in the document static.js in this gist.

The website is dynamic

You can do by 2 ways :

  • Check each x seconds for updates on the pages
  • Use DOM events to detect data Document dynamic.js can help you.

After that...

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

var wbestanime = require('./websites/bestanime').api;

var libraries = [..., new wbestanime()];

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/>.
*/
exports.api = class AnimeSiteName { // Export api with a class, rename it with the full site name.
constructor () {
this.browser = require('webextension-polyfill');
this.urlregex = /https:\/\/www.bestanime.tv\//; // This regex identifies the website, since this website is dynamic, do not specify player page URL scheme.
this.storage = {};
this.jquery = require('jquery'); // Jquery is optional
return true;
}
isUsable() {
// Here you can add additional steps, the goal is to identify if we are on the good website.
return this.urlregex.test(document.documentURI);
}
init() {
setInterval(() => { // This is an example for time-based support, but you can use event-based support.
var title = this.jquery('h1.title').text();
var episodeNumber = this.jquery('h2.epData').text();
console.log('[scrobbly] bestanime support is time-based, some issues can occur', {title, episodeNumber}); // This line can help to get easy feedback from users.
if (title == this.storage.title && episodeNumber == this.storage.episodeNumber) return; // Avoid requests loop.
if (title && episodeNumber) {
this.storage = {title, episodeNumber}; // Store this to avoid requests loop.
this.browser.runtime.sendMessage({action: 'start', animeName: title, episode: episodeNumber}); // This line is mandatory, it sends data to main script.
}
}, 6500);
}
}
/*
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/>.
*/
exports.api = class AnimeSiteName { // Export api with a class, rename it with the full site name.
constructor () {
this.browser = require('webextension-polyfill');
this.urlregex = /https:\/\/www.bestanime.tv\/en\/episode\/([a-zA-Z0-9-]+)/; // This regex identifies if we are in a player page or somewhere else.
this.jquery = require('jquery'); // JQuery is optional
return true;
}
isUsable() {
// Here you can add additional steps, the goal is to identify if we are on a player page and not on other pages.
return this.urlregex.test(document.documentURI);
}
init() {
// Here you can do the magic! You can use nearly everithing to get data here.
var title = this.jquery('.episode_title').text();
var season = this.jquery('.episode_subtitle span.season').text(); // It's a good practice to add the season number after the anime title
season = season[season.length -1];
if (parseInt(season) != 1) {
title += ' ' + season;
}
var episodeNumber = this.jquery('.episode_subtitle span.episodenumber').text();
this.browser.runtime.sendMessage({action: 'start', animeName: title, episode: episodeNumber}); // This line is mandatory, it sends data to main script.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment