python下载是免费的吗-关于python下载imooc的免费视频的方法

前言

这几天收到很多回复,都是再说代码有问题,我很疑惑,经过反复几次回复我才知道,我的代码中一些关键的url被屏蔽掉了(imooc的网址),所以导致代码报错,我服了,所以我打算把代码放到压缩包里面.在这里

软件功能方面

linux平台上,软件可以下载imooc的视频并进行合成

windows平台需要ffmpeg并加入到环境变量里面

下面是原始文章

昨天心血来潮,突然想下载慕课网视频(免费视频),调试了几遍,得到了接口,接口很容易得到,只不过接口中的info字段是经过加密的,还有 m3u8的视频的AES-128秘钥也是经过加密的,还好他们用到的加密方法是一套,还不算费劲,后面我懒得写分析过程了(分析过程应该就属于浏览器调试的方法,后面我会单独出一篇文章)

慕课网的接口

{

"result": 1,

"data": {

"info": "UmwqhmAsBBsZHy0FBid5JAA8BBtHZC0NBiceKABEBBsVai0cBCcPJAY6BAYZEy0HBicESmc9BEVuEy0NBicSJHk9BBdgEy0bBiceIhE9BA4ZCi0cBl4eJB09BAELfSkaHSceNwA7BA4ZEzQcfyceJB09BAtwEy15BidmMnQoBBsDAy0fBjoeJBAhBHIZE0wcYyceJGZZYH9hFVkNBicZJBs9BBsBEi0cBjoeJBs9BAFwEy15Bid4QGwRZxsZdUlCOgc+AwAZBHViEy1nBgQeJAAeBDgZEy1mOyceHQA9PxsZKC0cMSceXjc9BCAZExQcBlweJCIABBspIi0cPSceXwBcBBsZfx0sNEV8RQAMBBsZc0t4Nyd/JAA9YxsZdi0cZyceEwA9aHsvcUgcBhIeJHs9PRsZExwcNicjJAAcBBsgEy1mPyceQwA9JRsZfy13BhAeJDAHbRsZJi0cPhoeJC09BDoZExccYydsAwA9IxsZK0QcBkIeJHIROCQZEyYcJyceJCYABBtwEy0pBicCImQKBBsFCi1+Bj8zJABQBBt+Ey0sYSceEwA9JRsZJi0cBSceQQA9Ji0AE0scJyceKQBbBHYZEw17Bj8eKiQzFxsZETU+KCYeJGAzFxsfExQcBj0gKQA9YRsZHS0ZBiczJAAkBBsKEywcBid7JAAkBBs3Ezwc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y0lBidlJAAfORsZIxwcBhweJHs9ZRsZE0EsNhV8RmE9NRsZE016YhYeRQA9BHwZE0gcBkYeJDc9BHd5JU95BicrJABGBCMZKC0cJSdkJDk9BHwZEwwcBkseTwAKBBspKUQcBhIeJDgABBs0Ey09BickJGU9djwZEwocBh93JABYBBtrPxEjBicVJCE9BBs/Li0cbyceEQA9GB19JC0cGj4eRgAlKRsZfi0cYSceFGc9BCwZEwwcBhIeJAM9BH4ZEw8qHyd4JCE9BBYZdS1xBic+QwAlBBU9HT4cBiUGBi48BBt5HT4cACcnJAAnOhYZE0gcBikeIQA9KRsZCi0cFScfJAA9YRsZCi0cKCcPJGU9BBYZPS0gOycePhA9CRs1Hi0bBiceSQA9IxsZJUocBhAeJCE9BC4ZEzEgAgF5JAA7IC0aEy0eNgkNJAAvJCwZEz0wYj0eKQBbBAIZEz0cOScwPQATBBYZEwAcBjkkBgYIBBt/Mi0eBiMeJwAFJH0vfi0cODkePhY+BBsaEy04ASceEQA9PD8IEy0eBh4eBBs9BAIZExIcOSceJCw9CD8jIi0dBiceRC09BBgZEyE4HSceEgE9Bht8Ey0cYyceFBokBH8Zdi0cZCceJgYnFRsZLC14Bid7JAA7HgIZEi0cBkIeJCU9BBUKE0gcBicFJAAMBBsmEz8cZiQeJDgNAioZEywcBkIeJGc9BAUDEzwcBjkEJBE9BGkkEw0cPyceFQA9IxsZMxgcBh4eJCRUBBt8Ey19Bid8RmRQBBt+Ey17Bid8QiBPPxsZLC0tBiceHgBUBCYZExQcBhweJDs9BCwZE1wcBkAeJBU9HRsZEwMcHyd4PQADBB0nCi0cFicpJGU9BAAZEz0BBid6Pj4vOxsZCT0cEyd6Pj4OBBs6EzccOBgeRAAzBCwZE0kGFicPJC4nPRsZARMHBicdJAA4BBt/EyAcKDIeQgAzARsZYi0cYSceNABMBHwZEz0=pTiPOMGyHRsJ",

"cdn": [

"aliyun",

"aliyun1",

"letv"

]

},

"msg": ""

}

这里面 info 里面字段就是加密(关于解密在后面)

这个url是获取 视频清晰度的, info字段就是3种清晰度的视频url

另外别的接口也都是有info字段的,所有的info字段都是经过加密的,主要的入口就是上面接口

获取视频的主要过程:

1.通过上面的接口——————返回3种清晰度视频的url

2.然后在请求其中一种清晰度url——————返回带有很多 .ts内容的url (其实就是相当于一个 index.m3u 文件,只不过也是将主要内容放到info字段进行加密了,是接口的形式,不是以文件的形式)

3.在第2步中返回值有秘钥的url(这个秘钥也是经过加密的放在info字段)请求这个秘钥url——————返回 秘钥在info字段中

4.请求多个ts文件并通过获取到的秘钥对ts视频进行解密

所以核心就是找到解密info的算法

解密info字段的js算法

简单调试找到了js的解密info的算法

function n(t, e) {

function r(t, e) {

var r = "";

if ("object" == typeof t)

for (var n = 0; n < t.length; n++)

r += String.fromCharCode(t[n]);

t = r || t;

for (var i, o, a = new Uint8Array(t.length), s = e.length, n = 0; n < t.length; n++)

o = n % s,

i = t[n],

i = i.toString().charCodeAt(0),

a[n] = i ^ e.charCodeAt(o);

return a

}

function n(t) {

var e = "";

if ("object" == typeof t)

for (var r = 0; r < t.length; r++)

e += String.fromCharCode(t[r]);

t = e || t;

var n = new Uint8Array(t.length);

for (r = 0; r < t.length; r++)

n[r] = t[r].toString().charCodeAt(0);

var i, o, r = 0;

for (r = 0; r < n.length; r++)

0 != (i = n[r] % 3) && r + i < n.length && (o = n[r + 1],

n[r + 1] = n[r + i],

n[r + i] = o,

r = r + i + 1);

return n

}

function i(t) {

var e = "";

if ("object" == typeof t)

for (var r = 0; r < t.length; r++)

e += String.fromCharCode(t[r]);

t = e || t;

var n = new Uint8Array(t.length);

for (r = 0; r < t.length; r++)

n[r] = t[r].toString().charCodeAt(0);

var r = 0,

i = 0,

o = 0,

a = 0;

for (r = 0; r < n.length; r++)

o = n[r] % 2,

o && r++,

a++;

var s = new Uint8Array(a);

for (r = 0; r < n.length; r++)

o = n[r] % 2,

s[i++] = o ? n[r++] : n[r];

return s

}

function o(t, e) {

var r = 0,

n = 0,

i = 0,

o = 0,

a = "";

if ("object" == typeof t)

for (var r = 0; r < t.length; r++)

a += String.fromCharCode(t[r]);

t = a || t;

var s = new Uint8Array(t.length);

for (r = 0; r < t.length; r++)

s[r] = t[r].toString().charCodeAt(0);

for (r = 0; r < t.length; r++) {

if (0 != (o = s[r] % 5) && 1 != o && r + o < s.length && (i = s[r + 1],

n = r + 2,

s[r + 1] = s[r + o],

s[o + r] = i,

(r = r + o + 1) - 2 > n)) {

for (; n < r - 2; n++) {

s[n] = s[n] ^ e.charCodeAt(n % e.length)

}

}

}

for (r = 0; r < t.length; r++)

s[r] = s[r] ^ e.charCodeAt(r % e.length);

return s

}

for (var a = {

data: {

info: t

}

}, s = {

q: r,

h: n,

m: i,

k: o

}, l = a.data.info, u = l.substring(l.length - 4).split(""), c = 0; c < u.length; c++)

u[c] = u[c].toString().charCodeAt(0) % 4;

u.reverse();

for (var d = [], c = 0; c < u.length; c++)

d.push(l.substring(u[c] + 1, u[c] + 2)),

l = l.substring(0, u[c] + 1) + l.substring(u[c] + 2);

a.data.encrypt_table = d,

a.data.key_table = [];

for (var c in a.data.encrypt_table)

"q" != a.data.encrypt_table[c] && "k" != a.data.encrypt_table[c] || (a.data.key_table.push(l.substring(l.length - 12)),

l = l.substring(0, l.length - 12));

a.data.key_table.reverse(),

a.data.info = l;

var f = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

a.data.info = function(t) {

var e, r, n, i, o, a, s;

for (a = t.length,

o = 0,

s = ""; o < a;) {

do {

e = f[255 & t.charCodeAt(o++)]

} while (o < a && -1 == e);

if (-1 == e)

break;

do {

r = f[255 & t.charCodeAt(o++)]

} while (o < a && -1 == r);

if (-1 == r)

break;

s += String.fromCharCode(e << 2 | (48 & r) >> 4);

do {

if (61 == (n = 255 & t.charCodeAt(o++)))

return s;

n = f[n]

} while (o < a && -1 == n);

if (-1 == n)

break;

s += String.fromCharCode((15 & r) << 4 | (60 & n) >> 2);

do {

if (61 == (i = 255 & t.charCodeAt(o++)))

return s;

i = f[i]

} while (o < a && -1 == i);

if (-1 == i)

break;

s += String.fromCharCode((3 & n) << 6 | i)

}

return s

}(a.data.info);

for (var c in a.data.encrypt_table) {

var h = a.data.encrypt_table[c];

if ("q" == h || "k" == h) {

var p = a.data.key_table.pop();

a.data.info = s[a.data.encrypt_table[c]](a.data.info, p)

} else{

a.data.info = s[a.data.encrypt_table[c]](a.data.info)

}

}

if (e)

return a.data.info;

var g = "";

for (c = 0; c < a.data.info.length; c++)

g += String.fromCharCode(a.data.info[c]);

return g

}

简单测试一下这个加密算法是不是正确,在代码后面加上两句

a = n("UmwqhmAsBBsZHy0FBid5JAA8BBtHZC0NBiceKABEBBsVai0cBCcPJAY6BAYZEy0HBicESmc9BEVuEy0NBicSJHk9BBdgEy0bBiceIhE9BA4ZCi0cBl4eJB09BAELfSkaHSceNwA7BA4ZEzQcfyceJB09BAtwEy15BidmMnQoBBsDAy0fBjoeJBAhBHIZE0wcYyceJGZZYH9hFVkNBicZJBs9BBsBEi0cBjoeJBs9BAFwEy15Bid4QGwRZxsZdUlCOgc+AwAZBHViEy1nBgQeJAAeBDgZEy1mOyceHQA9PxsZKC0cMSceXjc9BCAZExQcBlweJCIABBspIi0cPSceXwBcBBsZfx0sNEV8RQAMBBsZc0t4Nyd/JAA9YxsZdi0cZyceEwA9aHsvcUgcBhI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C0tBiceHgBUBCYZExQcBhweJDs9BCwZE1wcBkAeJBU9HRsZEwMcHyd4PQADBB0nCi0cFicpJGU9BAAZEz0BBid6Pj4vOxsZCT0cEyd6Pj4OBBs6EzccOBgeRAAzBCwZE0kGFicPJC4nPRsZARMHBicdJAA4BBt/EyAcKDIeQgAzARsZYi0cYSceNABMBHwZEz0=pTiPOMGyHRsJ")

console.log(a)

这个测试的内容就是第一个接口响应返回info中的内容

用node 运行一下结果

#EXTM3U

#EXT-X-VERSION:3

#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=512000, RESOLUTION=1280x720

https://www.imooc.com/video/58ddf665e420e5315c8b461a/medium.m3u8?cdn=aliyun1&ssl=1&hxk_uri=aHR0cHM6Ly93d3cuaW1vb2MuY29tL3ZpZGVvLzU4ZGRmNjY1ZTQyMGU1MzE1YzhiNDYxYS9tZWRpdW0uaHhrP3RpbWVzdGFtcD0xNTY2MDkzMzYyJnRva2VuPWltb29jJTNBWWpSalpEVmtOMkkxTXpneU4yWXpObVU1T1dNM016TTVNREk0T1RNMU1qZG1OekF4WldReU13JTNEJTNE×tamp=1566093362&token=imooc%3AZDY1NzcyNWU1NDRmMWMzZWFlMDE3MTk2OTVkZDVhNTY2ODAzZjAwMg%3D%3D

#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=384000, RESOLUTION=1280x720

https://www.imooc.com/video/58ddf665e420e5315c8b461a/medium.m3u8?cdn=aliyun1&ssl=1&hxk_uri=aHR0cHM6Ly93d3cuaW1vb2MuY29tL3ZpZGVvLzU4ZGRmNjY1ZTQyMGU1MzE1YzhiNDYxYS9tZWRpdW0uaHhrP3RpbWVzdGFtcD0xNTY2MDkzMzYyJnRva2VuPWltb29jJTNBWWpSalpEVmtOMkkxTXpneU4yWXpObVU1T1dNM016TTVNREk0T1RNMU1qZG1OekF4WldReU13JTNEJTNE×tamp=1566093362&token=imooc%3AZDY1NzcyNWU1NDRmMWMzZWFlMDE3MTk2OTVkZDVhNTY2ODAzZjAwMg%3D%3D

#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=256000, RESOLUTION=720x480

https://www.imooc.com/video/58ddf665e420e5315c8b461a/low.m3u8?cdn=aliyun1&ssl=1&hxk_uri=aHR0cHM6Ly93d3cuaW1vb2MuY29tL3ZpZGVvLzU4ZGRmNjY1ZTQyMGU1MzE1YzhiNDYxYS9sb3cuaHhrP3RpbWVzdGFtcD0xNTY2MDkzMzYyJnRva2VuPWltb29jJTNBWWpSalpEVmtOMkkxTXpneU4yWXpObVU1T1dNM016TTVNREk0T1RNMU1qZG1OekF4WldReU13JTNEJTNE×tamp=1566093362&token=imooc%3AMzM2MjRjMDc1ODI0NjFkNDA0NjgwNjk4ZTc0NDEzNmFjOWQ2YzA2ZQ%3D%3D

可以看到已经解析出来3中清晰度视频的url了,可以说我用python调用node来完成info字段的解密,是完全没有问题的,但是总是感觉调用node不如使用完全的python好,所以我用python又实现了一遍这个算法,没错自从上次用python实现怎么学校的js(500多行)算法后,我就一发不可收拾了

python实现:enc.py(在压缩包里面)

python下载视频代码:api.py(在压缩包里面)

这段代码我挺满意的,因为里面的函数返回值都是像接口一样封装的,我用到的下载视频功能只是调用了每个函数的返回值中的一小部分,还有很多有用的信息我也都提取出来了,这里的main函数就相当于一个测试示例, 提供一个url就可以下载一个视频下面所有小节的视频了,如果这篇文章帮到你,可以给我个评论,谢谢,因为完成这个算法真的花费了我很大的力气

你可能感兴趣的:(python下载是免费的吗-关于python下载imooc的免费视频的方法)