Skip to content

Instantly share code, notes, and snippets.

@baptx
Last active December 7, 2020 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baptx/a0548b0630d9157cb1d61693be8295ac to your computer and use it in GitHub Desktop.
Save baptx/a0548b0630d9157cb1d61693be8295ac to your computer and use it in GitHub Desktop.
Get M3U8 streaming URL from France TV info replay website
// ==UserScript==
// @name get_m3u8
// @namespace francetvinfo
// @include http://www.francetvinfo.fr/*
// @version 1
// @grant none
// ==/UserScript==
/* Using Content Script Injection (window.functionName) to make function available outside GreaseMonkey scope
Page reload is needed if using existing function _jsonp_loader_callback_request_0. */
window._jsonp_loader_callback_request_1 = function(json)
{
alert(json.videos[1].url);
}
window._jsonp_loader_callback_request_2 = function(json)
{
alert(json.videos[5].url);
}
function get_m3u8()
{
// replay
var el = document.getElementById("catchup");
if (el) {
var id = el.href.match(/video\/(.*)@/)[1];
var script = document.createElement("script");
script.src = "http://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=" + id + "&catalogue=Info-web&callback=_jsonp_loader_callback_request_1";
document.getElementsByTagName("head")[0].appendChild(script);
} else {
// live
var el = document.getElementById("en_direct_video");
if (el) {
var id = el.href.match(/video\/(.*)/)[1];
var script = document.createElement("script");
script.src = "http://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=" + id + "&catalogue=Pluzz&callback=_jsonp_loader_callback_request_2";
document.getElementsByTagName("head")[0].appendChild(script);
}
}
}
get_m3u8();
@gilmararaujo
Copy link

Hi, I tried to execute using nodejs, but it's not possible because or window do not exist in nodejs. How to execute this script?

@baptx
Copy link
Author

baptx commented Dec 7, 2020

@gilmararaujo Hi, this is not a Node.js script but a script to use with a web browser addon like Greasemonkey (you can recognize the script type because of the file extension .user.js which is a userscript). It is possible that the script is no longer working and needs to be updated due to a change of francetvinfo.fr website.
Here is more information that I gave on my website to another user interested in Node.js:

You can do a web scrapping script with Node.js also, the idea is the same, you have to get the video ID that is printed in the source code of a replay video like https://www.francetvinfo.fr/replay-jt/france-3/12-13/jt-de-12-13-du-jeudi-11-octobre-2018_2950395.html and then pass the ID (189835310 in this case) in the API URL like https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=189835310&catalogue=Info-web&callback=_jsonp_loader_callback_request_0 to be able to parse the JSON data and get the M3U8 URL.
The easiest way to get the M3U8 URL without script is just to open the browser console in Firefox for example, then click on the “Network” console tab and if you reload the replay page, you should see a M3U8 URL that you can copy and paste in a video player (it is displayed now because they switched to HTML5 player but I had to use the Greasemonkey script previously on a computer that did not have Flash Player installed).
Since you may have to use a web browser to find the video URL, it may be more convenient to directly get the M3U8 URL in the browser console instead of having to use a script in a command-line console but it depends of what you want to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment