Skip to content

Commit

Permalink
移除js2py库依赖,优化交互
Browse files Browse the repository at this point in the history
  • Loading branch information
AuYang261 committed Apr 2, 2024
1 parent dd24b14 commit 1684c85
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 2,978 deletions.
38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# BIT_yanhe_download

## 下载指定课程
## 介绍

本项目可下载[延河课堂 (yanhekt.cn)](https://www.yanhekt.cn/recordCourse)中的课程视频。延河课堂是北京理工大学的在线课堂,提供了大量的课程视频,但是没有提供下载功能。本项目可以下载指定课程的视频录像和屏幕信号,包括无权限的课程。

欢迎提出建议和star!

## 使用:下载指定课程

[下载并解压](https://github.com/AuYang261/BIT_yanhe_download/releases/latest/download/yanhe.zip)

[延河课堂 (yanhekt.cn)](https://www.yanhekt.cn/recordCourse)中找到想下载的课程,以链接为https://www.yanhekt.cn/course/40524 的课程为例,复制地址栏最后的五位编号40524。注意是课程列表的链接(以`yanhekt.cn/course/五位编号`开头),不是视频界面的链接(以`yanhekt.cn/session/六位编号`开头)。

![image-20231018204208066](md/README/image-20231018204208066.png)

双击运行`main.exe``run.bat`文件,并输入你想下载的课程编号(40524)。输出课程视频列表:
双击运行`main.exe`(Release中的)`run.bat`文件,并输入你想下载的课程编号(40524)。输出课程视频列表:

![image-20230926124749421](md/README/image-20230926124749421.png)

Expand All @@ -20,19 +26,18 @@

![image-20230926124922726](md/README/image-20230926124922726.png)

## 依赖
## 依赖

* ffmpeg,已在Release中提供。

*若想用python环境运行,需安装这些依赖*

* python,[下载](https://www.python.org/ftp/python/3.9.4/python-3.9.4-amd64.exe)并安装

* python第三方库requests、execjs。双击运行项目根目录下的`install.bat`一键安装。

或手动安装:打开命令行(按win+r,在打开的窗口中输入cmd,回车),运行如下命令以安装:
* python第三方库requests。打开命令行(按win+r,在打开的窗口中输入cmd,回车),运行如下命令安装:

```bash
pip install requests
pip install PyExecJS
pip install -r requirements.txt
```

## 注意
Expand All @@ -42,17 +47,10 @@

## 打包

* 使用如下命令打包:

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

如果想要运行时不依赖python环境,可将python程序打包成可执行文件。Release中已打包。

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

```bash
python js_to_py.py
```
使用如下命令打包:


```bash
Pyinstaller -F main.py
```
3 changes: 0 additions & 3 deletions install.bat

This file was deleted.

2 changes: 0 additions & 2 deletions js_to_py.py

This file was deleted.

40 changes: 20 additions & 20 deletions m3u8dl.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
'''
Project :
FilePath : \BIT-YANHE\m3u8dl.py
Descripttion :
Author : GDDG08
Date : 2022-11-07 12:09:26
LastEditors : GDDG08
LastEditTime : 2022-11-07 15:39:29
'''
# coding=utf-8

import os
import re
import sys
Expand All @@ -18,7 +11,7 @@
import time
from concurrent.futures import ThreadPoolExecutor

from signature_from_js import signature_from_js
from hashlib import md5

class ThreadPoolExecutorWithQueueSizeLimit(ThreadPoolExecutor):
"""
Expand Down Expand Up @@ -67,18 +60,18 @@ def __init__(self, url, workDir, name, max_workers=32, num_retries=999, base64_k
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.52',
'Origin': 'https://www.yanhekt.cn',
'referer': 'https://www.yanhekt.cn/',
}
self.timestamp = str(int(time.time()))
self.signature = signature_from_js.getSignature(self.timestamp)
}
self.magic = "1tJrMwNq3h0yLgx86Rued2J1tFc"
self.updateSignature()

urllib3.disable_warnings()

self._url=signature_from_js.encryptURL(self._url)
self._url=self.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')
with ThreadPoolExecutorWithQueueSizeLimit(self._max_workers) as pool:
pool.submit(self.updateSignature)
pool.submit(self.updateSignatureLoop)
for k, ts_url in enumerate(self._ts_url_list):
pool.submit(self.download_ts, ts_url, os.path.join(self._file_path, str(k)), self._num_retries)
if self._success_sum == self._ts_sum:
Expand All @@ -87,13 +80,20 @@ def __init__(self, url, workDir, name, max_workers=32, num_retries=999, base64_k
print(f"Download successfully --> {self._name}")

def updateSignature(self):
self.timestamp = str(int(time.time()))
self.signature = md5((self.magic + "_v1_" + self.timestamp).encode()).hexdigest()

def updateSignatureLoop(self):
while self._success_sum != self._ts_sum:
self.timestamp = str(int(time.time()))
self.signature = signature_from_js.getSignature(self.timestamp)
# print('Updated signature')
# print(timestamp, signature)
self.updateSignature()
time.sleep(10)

def encryptURL(self, url):
url_list = url.split('/')
# "a97f12c055a10ee51d60e441e618bfef"
url_list.insert(-1, md5((self.magic + "_100").encode()).hexdigest())
return '/'.join(url_list)

def getToken(self):
if self._token == None:
headers = {
Expand Down Expand Up @@ -228,7 +228,7 @@ def download_key(self, key_line, num_retries):
print(e)
if os.path.exists(os.path.join(self._file_path, 'key')):
os.remove(os.path.join(self._file_path, 'key'))
print("加密视频,无法加载key,揭秘失败")
print("加密视频,无法加载key,解密失败")
if num_retries > 0:
self.download_key(key_line, num_retries - 1)

Expand Down
14 changes: 9 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding=utf-8

import requests
import m3u8dl
import sys
Expand Down Expand Up @@ -28,10 +30,10 @@ def main():
videoList = req.json()['data']
# print(json.dumps(videoList, indent=2))
for i, c in enumerate(videoList):
print(i, c['title'])
print(i, ":", c['title'])

index = eval('[' + input('select(split by \',\'):') + ']')
vga = input('video(1) or screen(2)?(input 1 or 2, default 1):')
index = eval('[' + input('select(split by \',\', such as: 0,2,4):') + ']')
vga = input('video(1) or screen(2)?(input 1 or 2, default video):')
if not os.path.exists('output/'):
os.mkdir('output/')
for i in index:
Expand All @@ -40,10 +42,10 @@ def main():
print(name)
if vga == "2":
print("Downloading screen...")
m3u8dl.M3u8Download(c['videos'][0]['vga'], 'output\\' + course.json()['data']['name_zh'].strip() + ('-screen' if vga == '2' else '-video'), name)
m3u8dl.M3u8Download(c['videos'][0]['vga'], 'output/' + course.json()['data']['name_zh'].strip() + '-screen', name)
else:
print("Downloading video...")
m3u8dl.M3u8Download(c['videos'][0]['main'], 'output\\'+ course.json()['data']['name_zh'].strip() + ('-screen' if vga == '2' else '-video'), name)
m3u8dl.M3u8Download(c['videos'][0]['main'], 'output/'+ course.json()['data']['name_zh'].strip() + '-video', name)


if __name__ == '__main__':
Expand All @@ -54,3 +56,5 @@ def main():
print(e)
print("If the problem is still not solved, you can report an issue in https://github.com/AuYang261/BIT_yanhe_download/issues.")
print("Or contact with the author [email protected]. Thanks for your report!")
print("如果问题仍未解决,您可以在https://github.com/AuYang261/BIT_yanhe_download/issues 中报告问题。")
print("或者联系作者[email protected]。感谢您的报告!")
1 change: 0 additions & 1 deletion pack.bat

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
Loading

0 comments on commit 1684c85

Please sign in to comment.