Skip to content

Commit

Permalink
🛠️Fix video access for logged-in users
Browse files Browse the repository at this point in the history
  • Loading branch information
t0pl committed Dec 20, 2020
1 parent fe1a19d commit 951e9d6
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 103 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Get schoolmouv's premium pdfs and videos - browser extension
Browsers based on `Chromium` and `Firefox` should be compatible as well on Windows, Mac and Linux (usually not on Android)

## Install🔥
Install it manually
Install it manually from `source` folder

See [this](https://developer.chrome.com/extensions/getstarted) for more info or
drag and drop the xpi file into your browser (**firefox-like** only)
Binary file removed pdf_and_videos_from_schoolmouv-1.3-an+fx.xpi
Binary file not shown.
2 changes: 1 addition & 1 deletion source/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SchoolMouv's premium resources made free",
"version": "1.3",
"version": "1.4",
"manifest_version": 2,

"description": "Gets schoolmouv.fr's premium videos and pdfs for free, no need to be a registered user",
Expand Down
48 changes: 4 additions & 44 deletions source/scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,23 @@ window.headers_ = {
}

const clean_url = (url) => {
return url.split("#")[0].split("?")[0]
return url.replace('/eleves','').split("#")[0].split("?")[0]
}

const is_website_valid = (url) => {
return url.startsWith("https://www.schoolmouv.fr");
return url.startsWith("https://www.schoolmouv.fr") && url.split('/').length >= 6;
}

const see_in_new_tab = (final_hidden_resource) => {
browser.tabs.create({ "url": final_hidden_resource })
}

const isAndroid = () => {
//not used
return typeof browser.windows.WindowType === "undefined"
}

const isFirefox = () => {
return typeof browser.webRequest.getSecurityInfo !== "undefined"
}

const resource_type = () => {
const valid_pdfs = [
'scientifique',
'mouvement-litteraire',
'schema-bilan',
'fiche-methode-bac',
'fiche-de-revision',
'demonstration',
'repere',
'personnages-historique',
'lecon',
'fiche-materiel',
'evenement-historique',
'savoir-faire',
'fiche-methode',
'bien-rediger',
'fiche-pratique',
'auteur',
'philosophe',
'formule-ses',
'figure-de-style',
'fiche-annale',
'definition',
'algorithme',
'fiche-calculatrice',
'courant-philosophique',
'fiche-methode-brevet',
'fiche-de-cours',
'genre-litteraire',
'registre-litteraire',
'carte',
'fiche-de-lecture',
'fiche-oeuvre',
'notion'
]
for (const _pdf of valid_pdfs) {
if (window.url.includes(_pdf)) return "pdf"
}
if (window.url.endsWith('cours-video')) return "video"
if (!window.url.includes("/qcm") && !window.url.includes("/exercice") && window.url.split('/').length) return "pdf"
return ""
}
3 changes: 1 addition & 2 deletions source/scripts/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ const get_pdf = () => {
}

const url_to_direct_pdf_link = () => {
const to_be_replaced = window.url.includes("/eleves/") ? "www.schoolmouv.fr/eleves" : "www.schoolmouv.fr"
return window.url.replace(to_be_replaced, "pdf-schoolmouv.s3.eu-west-1.amazonaws.com") + ".pdf";
return window.url.replace("www.schoolmouv.fr", "pdf-schoolmouv.s3.eu-west-1.amazonaws.com") + ".pdf";
}
130 changes: 75 additions & 55 deletions source/scripts/video.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
/*
@author:t0pl
This tool isn't affiliated to SchoolMouv in any way
NOTES
browser.windows.create not available in Android
TODO
❌ Rearrange functions
✅ Remove useless headers
❌ Handle errors
✅ Secure fonction access
❌ Only open selected video
*/

/* Error handling */

function check_status_code(response) {

if (!response.ok) (console.warn(`${url} returned wrong status code: ${response.status}`));
return response.text();

}

/* Requests */
const ____ = (url) => {
const vimeo_player = (url) => {
if (url) {
set_listener();
fetch(url).then(function (response) {
if (!response.ok) console.warn(`${url} returned wrong status code: ${response.status}`);
return response.text()
})
.then(function (data) {
for (const part of data.split('};')) {
fetch(url).then(check_status_code)
.then(function (res) {
//Locate part of response containing mp4s
for (const part of res.split('};')) {
if (part.includes('.mp4')) {
const _interesting_part = JSON.parse(`{${part.split('= {')[1]}}`);
//_interesting_part.video.width _interesting_part.video.height
const all_mp4s_found = get_direct_links(_interesting_part);

const cleared_JSON = vimeo_JSON(part);
const all_mp4s_found = direct_links(cleared_JSON);

console.log(all_mp4s_found);

//Display results in new tab
see_in_new_tab(all_mp4s_found[0])
}
}
Expand All @@ -41,55 +40,75 @@ const ____ = (url) => {

const get_video = () => {
set_referer_in_headers()
fetch(window.url).then(function (response) {
if (!response.ok) (console.warn(`${url} returned wrong status code: ${response.status}`));
return response.text();
}).then(function (data) {
const to_json = `{${data.split('window.__INITIAL_STATE__={')[1].split('};(function(')[0]}}`;
const urls = get_urls_from_source_id(to_json);
console.log(urls);
for (const to_get of urls) {
____(to_get)
}
}).catch(function (err) {
console.error('Error during request: ', err);
})

//Fetch schoolmouv webpage
fetch(window.url)
.then(check_status_code)
.then(function (data) {

const clear_json = schoolmouv_JSON(data);
const urls = source_2_Vimeo_URL(clear_json);

console.log(urls);

//Fetch all vimeo webpages
for (const to_get of urls) {
vimeo_player(to_get)
}
}).catch(function (err) {
console.error('Error during request: ', err);
})
}

/* Parsing */
const get_urls_from_source_id = (to_json) => {
const vimeo_JSON = (part) => {

//Locate JSON in response and Convert from Vimeo WebPage
let located_json = part.split('= {')[1];
let cleared_json = JSON.parse(`{${located_json}}`);

return cleared_json;
}

const schoolmouv_JSON = (res) => {

//Locate JSON in response and Convert from Schoolmouv WebPage
const to_json = `{${res.split('window.__INITIAL_STATE__={')[1].split('};(function(')[0]}}`;
const clear_json = JSON.parse(to_json);

return clear_json;
}

const source_2_Vimeo_URL = (clear_json) => {
var first_step_urls = [];
var parsed_data = JSON.parse(to_json).sheet.resources;
if (parsed_data === undefined) {
console.log('registered user')
parsed_data = JSON.parse(to_json).resources.state.resources
let key = key_to_get_source_id()
for (var index_ = 0; index_ < parsed_data[key].length; index_++) {
first_step_urls.push(`https://player.vimeo.com/video/${parsed_data[key][index_].source}?app_id=122963`);
}
}
else {
console.log('unregistered user')
Object.keys(parsed_data).forEach(function (key) {
var source = parsed_data[key].source;
first_step_urls.push(`https://player.vimeo.com/video/${source}?app_id=122963`);
})
let parsed_data = clear_json.sheet.resources;

Object.keys(parsed_data).forEach(function (key) {

let source = parsed_data[key].source;
first_step_urls.push(`https://player.vimeo.com/video/${source}`);
})

if (first_step_urls === []) {
console.warn("'Source id' not found")
return []
}
if (first_step_urls === []) console.warn("'Source id' not found")
return first_step_urls
return first_step_urls
}

const key_to_get_source_id = () => {
//Needed if registered user, to find right key in {}
return window.url.split('/').splice(-2).join('-'); //des-cartes-pour-comprendre-le-monde-cours-video
}

const get_direct_links = (json_) => {
const direct_links = (cleared_JSON) => {
let direct_links = [];
for (var _ = 0; _ < json_.request.files.progressive.length; _++) {
direct_links.push(json_.request.files.progressive[_].url);
for (var _ = 0; _ < cleared_JSON.request.files.progressive.length; _++) {
direct_links.push(cleared_JSON.request.files.progressive[_].url);
}
return direct_links;
}

/* Header stuff */
const set_referer_in_headers = () => {
window.headers_['Referer'] = window.url;
Expand Down Expand Up @@ -119,14 +138,15 @@ const modify_headers = (header_array, _name, _value) => { // Credits: https://st
}

const onBeforeSendHeaders_callback = (details) => {
//Fired to modify request
Object.keys(window.headers_).forEach(function (key) {
//console.log(details.requestHeaders);
modify_headers(details.requestHeaders, key, window.headers_[key]);
});

return { requestHeaders: details.requestHeaders };
}

const OnBeforeRequestOptions = () => {
//Options differ in Chrome/Firefox
return isFirefox() ? ['blocking', 'requestHeaders'] : ['blocking', 'requestHeaders', 'extraHeaders']
}

0 comments on commit 951e9d6

Please sign in to comment.