Skip to content

Commit

Permalink
移除js运行环境依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
AuYang261 committed Oct 23, 2023
1 parent 003a9e7 commit a4039f7
Show file tree
Hide file tree
Showing 6 changed files with 1,875 additions and 13 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@
## 注意

* 需要关闭本机上的代理,否则会提示类似`check_hostname requires server_hostname`的报错信息。

* 可以下载无权限的课程,只要知道课程链接(中的课程编号)就行。

## 打包

* 使用如下命令打包:

```bash
Pyinstaller -F main.py
```


* `js_to_py.py`将获取签名的js代码转为python代码,运行如下命令进行转换:

```bash
python js_to_py.py
```


2 changes: 2 additions & 0 deletions js_to_py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import js2py
js2py.translate_file('signature.js', 'signature_from_js.py')
12 changes: 3 additions & 9 deletions m3u8dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import platform
import requests
import urllib3
import execjs
import time
from concurrent.futures import ThreadPoolExecutor

from signature_from_js import signature_from_js

class ThreadPoolExecutorWithQueueSizeLimit(ThreadPoolExecutor):
"""
Expand Down Expand Up @@ -71,13 +71,7 @@ def __init__(self, url, workDir, name, max_workers=64, num_retries=5, base64_key

urllib3.disable_warnings()

js = ''
# with open(os.path.dirname(sys.argv[0])+"/signature.js", 'r', encoding='UTF-8') as f:
with open("./signature.js", 'r', encoding='UTF-8') as f:
js = f.read()
self._signJs = execjs.compile(js)

self._url=self._signJs.call("encryptURL",self._url)
self._url=signature_from_js.encryptURL(self._url)

self.get_m3u8_info(self._url, self._num_retries)
print('Downloading: %s' % self._name, 'Save path: %s' % self._file_path, sep='\n')
Expand All @@ -91,7 +85,7 @@ def __init__(self, url, workDir, name, max_workers=64, num_retries=5, base64_key

def getSignature(self):
timestamp = str(int(time.time()))
signature = self._signJs.call('getSignature', timestamp)
signature = signature_from_js.getSignature(timestamp)
# print(timestamp, signature)
return timestamp, signature

Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def main():

course = requests.get(f'https://cbiz.yanhekt.cn/v1/course?id={courseID}&with_professor_badges=true', headers=headers)
req = requests.get(f'https://cbiz.yanhekt.cn/v2/course/session/list?course_id={courseID}', headers=headers)
if course.json()['code'] != '0':
if course.json()['code'] != '0' and course.json()['code'] != 0:
print(course.json()['code'])
print(course.json()['message'])
raise Exception("Please Check your course ID, note that it should be started with yanhekt.cn/course/***, not yanhekt.cn/session/***")
print(course.json()['data']['name_zh'])
Expand Down
6 changes: 4 additions & 2 deletions signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
* @LastEditors : GDDG08
* @LastEditTime : 2022-11-07 11:16:50
*/
global.navigator = { userAgent: 'node.js' };

navigator={
userAgent: 'node.js',
appName: "Microsoft Internet Explorer",
};
function C() {
function e(e, t, n, a) {
return T(n - 281, t)
Expand Down
Loading

0 comments on commit a4039f7

Please sign in to comment.