Skip to content

Instantly share code, notes, and snippets.

@hackingman
Created June 20, 2017 19:25
Show Gist options
  • Save hackingman/210c4d60dfb55708b722640420e1acdb to your computer and use it in GitHub Desktop.
Save hackingman/210c4d60dfb55708b722640420e1acdb to your computer and use it in GitHub Desktop.
myfreecams livestreamer URL generator
"use strict";
// ATTENTION! Requires `npm install websocket` to run
var url = require("url"),
http = require("http"),
WebSocketClient = require("websocket").client;
function usage()
{
console.error("Usage: node get_mfc_video_url.js <mfc username or url>");
process.exit(1);
}
if(process.argv.length<3)
usage();
var targetUsername = process.argv[2];
if(targetUsername.indexOf("http")===0)
targetUsername = url.parse(targetUsername, true).hash;
if(targetUsername.indexOf("#")===0)
targetUsername = targetUsername.substring(1);
targetUsername = targetUsername.trim();
if(targetUsername.length===0)
usage();
var client = new WebSocketClient();
client.on("connectFailed", function(error) { console.log("Connect Error: " + error.toString()); });
client.on("connect", function(connection)
{
connection.on("error", function(error) { console.log("Connection Error: " + error.toString()); });
connection.on("close", function() { });
connection.on("message", function(message)
{
if(message.type==="utf8")
{
var parts = /^([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ?(.*)/.exec(message.utf8Data);
if(!parts || parts.length<6)
{
console.error("Invalid Message: %s", message.utf8Data);
return;
}
if(parts[1]==="005369" || parts[1]==="005269")
{
connection.close();
getModelInfo(JSON.parse(decodeURIComponent(parts[6].substring(0, parts[6].indexOf("}")+1))).fileno);
}
}
});
connection.sendUTF("hello fcserver\n\0");
connection.sendUTF("1 0 0 20071025 0 guest:guest\n\0");
});
client.connect("ws://xchat20.myfreecams.com:8080/fcsl", "", "http://xchat20.myfreecams.com:8080", {Cookie : "company_id=3149; guest_welcome=1; history=7411522,5375294"});
function getModelInfo(fileno)
{
http.get("http://www.myfreecams.com/mfc2/php/mobj.php?f=" + fileno + "&s=xchat20", function(response)
{
var rawHTML = "";
response.on("data", function(d) { rawHTML += d; });
response.on("end", function()
{
rawHTML = rawHTML.toString("utf8");
rawHTML = rawHTML.substring(rawHTML.indexOf("{"), rawHTML.indexOf("\n")-1);
rawHTML = rawHTML.replace(/[^\x20-\x7E]+/g, "");
var modelsData = JSON.parse(rawHTML);
for(var key in modelsData)
{
if(!modelsData.hasOwnProperty(key))
continue;
var modelData = modelsData[key];
if(!modelData.nm || modelData.nm.toLowerCase()!==targetUsername.toLowerCase())
continue;
console.log("hlsvariant://http://video" + (modelData.u.camserv-500) + ".myfreecams.com:1935/NxServer/mfc_" + (100000000+modelData.uid) + ".f4v_aac/playlist.m3u8?nc=1423603882490");
process.exit(0);
}
process.exit(0);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment