当前位置: 首页 > news >正文

网站定位是什么济南网站推广优化

网站定位是什么,济南网站推广优化,个性定制网站,中文域名网站好不好优化本文涵盖的内容仅供个人学习使用,如果侵犯学校权利,麻烦联系我删除。 初衷 研究生必修选逃, 期末复习怕漏过重点题目,但是看学在西电的录播回放课一卡一卡的,于是想在空余时间一个个下载下来,然后到时候就…

本文涵盖的内容仅供个人学习使用,如果侵犯学校权利,麻烦联系我删除。

初衷

研究生必修选逃, 期末复习怕漏过重点题目,但是看学在西电的录播回放课一卡一卡的,于是想在空余时间一个个下载下来,然后到时候就突击复习。

环境

因为懒得用二进制安装ffmpeg,所以用的Ubuntu22.04。年轻的本科生windows选手们可以自行学习二进制安装ffmpeg。

sudo apt install ffmpeg
ffmpeg -version
# 要有python3,安装步骤略过
...
# pip依赖
pip install aiohttp
pip install tqdm
pip install m3u8

预备知识

关于网站部分,本文写于2024-12-05,不保证后面会不会改

学在西电就是在学习通上再加了一层,加了点新东西。录播在这个地方看。(本文默认已经登录成功)
在这里插入图片描述
下面的图就是录播播放界面,由于有学生姓名和学号的水印,我打码了。
左边是拍老师和黑板的录像,右边是展示ppt的录像。
在这里插入图片描述
为了捕获请求,我们先打开开发者面板的网络面板,点击下面的某堂课跳转,然后在页面刷新后获取到加载时的请求,通过关键词过滤m3u8,得到重要的三个请求。
在这里插入图片描述
注意这里有两个playback.m3u8,通过上面图中那个另外的请求playVideo?info=...的响应,我们可以看到pptVideoteacherTrack这两个路径,分别对应ppt和老师黑板的m3u8文件的url。

{"type": "2","videoPath": {"pptVideo": "....m3u8","teacherTrack": "....m3u8","studentFull": "....m3u8"},"liveId": ...,"isshowpl": 0
}

在学在西电里,视频文件是被切分为许多个几秒的视频块(ts文件,是Transport Stream不是Typescript),通过一个m3u8协议文件保存对应视频的各个小视频块的文件名、序列号、持续时间等信息。
在这里插入图片描述
m3u8文件内容如下,还好学在西电这里没有做加密,没有#EXT-X-KEY:METHOD=AES-128,URI...这么一行,所以我们可以用这些ts文件名直接下载(当然前面还要有http之类的前缀)。
在这里插入图片描述
最后,使用伟大牛逼的 ffmpeg 可以将这些ts文件合并为 mp4 文件。
在这里插入图片描述
在这里插入图片描述

具体代码

1. 下载各ts

基于m3u8库解析m3u8文件,aiohttp做协程下载,tqdm做进度条方便查看,最后记得threading加锁。
考虑到偶尔的下载异常,加了个3次重试。
url按照下图获取。

在这里插入图片描述
实测5分钟左右下完。

# download.py
import shutil
import threading
import m3u8
import os
import logging
import re
import asyncio
import aiohttp
from tqdm import tqdmpbar:tqdm = None
pbar_lock = threading.Lock()async def download_segment(session, ts_url, true_url, output_dir, cnt):global pbarfilename = os.path.join(output_dir, true_url)try:# 实际在这里下载async with session.get(ts_url) as resp:resp.raise_for_status()with open(filename, 'wb') as f:async for chunk in resp.content.iter_chunked(1024):if chunk:f.write(chunk)logging.info(f"下载完成: {true_url}")with pbar_lock:pbar.update(1)except Exception as e:logging.error(f"下载失败: {true_url}, 错误信息: {e}")# 3次重试机会if cnt == 3:logging.error(f"重试次数达到上限,跳过下载: {true_url}")# 把需要手动下的单独保存with open(f'{output_dir}.err', 'a', encoding='utf-8') as file:file.write(ts_url + '\n')# 并且这个下了一半的ts文件需要删掉,防止弄混if os.path.exists(filename):os.remove(filename)with pbar_lock:pbar.update(1)else:# 重试一下,且计数器+1await download_segment(session, ts_url, true_url, output_dir, cnt+1)async def download_m3u8(m3u8_url, output_dir):global pbar# 日志logging_file = f'{output_dir}-download.log'err_file = f'{output_dir}.err'if os.path.exists(logging_file):os.remove(logging_file)if os.path.exists(err_file):os.remove(err_file)if os.path.exists(output_dir):shutil.rmtree(output_dir)logging.basicConfig(filename=logging_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')# 创建输出目录os.mkdir(output_dir)# 下载并解析 m3u8 文件logging.info(f"开始解析 m3u8 文件: {m3u8_url}")m3u8_obj = m3u8.load(m3u8_url)# 提取 base URLbase_url = re.split(r"[a-zA-Z0-9-_\.]+\.m3u8", m3u8_url)[0]logging.info(f"提取到的base URL: {base_url}")# 创建 aiohttp sessionasync with aiohttp.ClientSession() as session:# 异步下载所有 ts 片段tasks = []pbar = tqdm(total=len(m3u8_obj.segments))logging.info(f"segment 个数: {len(m3u8_obj.segments)}")for _, segment in enumerate(m3u8_obj.segments):# 真正ts的下载url是要拼起来的ts_url = base_url + segment.uritask = asyncio.create_task(download_segment(session, ts_url, segment.uri, output_dir, 0))tasks.append(task)await asyncio.gather(*tasks)# 任务完成后关闭进度条pbar.close()logging.info(f"下载完成")m3u8_url = "http://.../playback.m3u8"
output_dir = "2-4-1-1"
asyncio.run(download_m3u8(m3u8_url, output_dir))

2. 合并为mp4

基于命令: ffmpeg -f concat -safe 0 -i ts_list.txt -c copy video.mp4。注意这个-i,如果只有少量文件,可以-i "concat:1.ts|2.ts|3.ts|4.ts|.5.ts|" ,但对于我们这种,就只能让他读取一个文件名列表文件,注意这个文件每行都是file+文件路径
在这里插入图片描述
我代码里首先获取了ts文件夹里的所有ts文件名,但是因为多线程所以乱序,要先排个序才能让ffmpeg按顺序拼接。

实测1分钟左右合并完成。

# merge.py
import osdef main(dir_name):filename = 'ts_list.txt'if os.path.exists(filename):os.remove(filename)f = open(filename, 'a', encoding='utf-8')names = []with os.scandir(dir_name) as entries:for entry in entries:# 检查是否为文件if entry.is_file():names.append(entry.name)# 注意要先排序,按顺序写入文件名names.sort(key=lambda x: int(x.split('_')[0]))for name in names:f.write(f"file  {os.path.join(dir_name,name)}\n")f.close()mp4_name = f"{dir_name}.mp4"if os.path.exists(mp4_name):os.remove(mp4_name)cmd = rf'ffmpeg -f concat -safe 0 -i ./{filename} -c copy {mp4_name}'os.system(cmd)main("./4-2-1-ppt")

3. 执行

运行前记得改两个脚本里的链接和文件名

python download.py
python merge.py

其他

  1. 其实也可以直接用ffmpeg一次完成: ffmpeg -i http://.../playback.m3u8 -c copy 2-4-1.mp4,只是似乎是串行依次下载ts,速度不快。
  2. 我也有搜到用IDM下载或者potplayer播放,学长/弟/姐/妹可以自行尝试。
    • 学在西电课程回放稳定播放方法
    • 手把手教你用IDM下载学在西电课程回放视频
  3. 关于ppt视频的忽略音频流,ffmpeg可以设置参数,我没看这个
  4. 关于字幕生成,免费方案是B站必剪支持15分钟内视频的字幕生成,可以在必剪里裁剪和生成,但是有点麻烦而且效果很差。其他方案请自行研究。
  5. 似乎也有直接可用的m3u8播放器,请自行研究。

文章转载自:
http://catcher.c7629.cn
http://metazoal.c7629.cn
http://unbeseeming.c7629.cn
http://reducing.c7629.cn
http://cur.c7629.cn
http://doomsday.c7629.cn
http://ferriage.c7629.cn
http://exogamous.c7629.cn
http://jamming.c7629.cn
http://windchest.c7629.cn
http://chironomid.c7629.cn
http://enterocolitis.c7629.cn
http://humous.c7629.cn
http://soberly.c7629.cn
http://ascomycetous.c7629.cn
http://scarab.c7629.cn
http://sunrise.c7629.cn
http://adjournment.c7629.cn
http://pinniped.c7629.cn
http://evaluating.c7629.cn
http://chromonemal.c7629.cn
http://hushaby.c7629.cn
http://sometime.c7629.cn
http://uintathere.c7629.cn
http://goosefoot.c7629.cn
http://throwoff.c7629.cn
http://bengalese.c7629.cn
http://caiaphas.c7629.cn
http://antipoetic.c7629.cn
http://respite.c7629.cn
http://irishize.c7629.cn
http://parge.c7629.cn
http://reimprisonment.c7629.cn
http://aseasonal.c7629.cn
http://camisado.c7629.cn
http://rhinopharyngitis.c7629.cn
http://microtec.c7629.cn
http://sendai.c7629.cn
http://admeasure.c7629.cn
http://trictrac.c7629.cn
http://horoscope.c7629.cn
http://sophoclean.c7629.cn
http://bmx.c7629.cn
http://morphonology.c7629.cn
http://ballistics.c7629.cn
http://poisonous.c7629.cn
http://billie.c7629.cn
http://resinoid.c7629.cn
http://trigoneutic.c7629.cn
http://intangibly.c7629.cn
http://honest.c7629.cn
http://decennium.c7629.cn
http://gleamingly.c7629.cn
http://snorter.c7629.cn
http://analyst.c7629.cn
http://prepositor.c7629.cn
http://transferability.c7629.cn
http://cognitive.c7629.cn
http://pte.c7629.cn
http://brice.c7629.cn
http://algiers.c7629.cn
http://apocope.c7629.cn
http://trangam.c7629.cn
http://manicure.c7629.cn
http://allergin.c7629.cn
http://potentilla.c7629.cn
http://paramilitary.c7629.cn
http://mammiform.c7629.cn
http://discomposed.c7629.cn
http://mon.c7629.cn
http://mutograph.c7629.cn
http://zeaxanthin.c7629.cn
http://obsolete.c7629.cn
http://unwove.c7629.cn
http://meanings.c7629.cn
http://truckway.c7629.cn
http://bigeneric.c7629.cn
http://crass.c7629.cn
http://rhizosphere.c7629.cn
http://terraqueous.c7629.cn
http://readership.c7629.cn
http://entomoplily.c7629.cn
http://sponginess.c7629.cn
http://excusal.c7629.cn
http://driller.c7629.cn
http://reproachful.c7629.cn
http://catchlight.c7629.cn
http://ridgepole.c7629.cn
http://amidships.c7629.cn
http://curari.c7629.cn
http://uss.c7629.cn
http://erigeron.c7629.cn
http://dissatisfactory.c7629.cn
http://puzzlist.c7629.cn
http://keeler.c7629.cn
http://supraglottal.c7629.cn
http://chilachap.c7629.cn
http://braze.c7629.cn
http://vituperative.c7629.cn
http://quantise.c7629.cn
http://www.zhongyajixie.com/news/99451.html

相关文章:

  • 乌鲁木齐做网站微信指数官网
  • wordpress 图片分享主题网络搜索优化
  • 赣州网站建设 赣州网页设计友点企业网站管理系统
  • 做视频特效的网站重庆seo推广
  • 下载什么网站做吃的百度一下官网搜索引擎
  • 学校门户网站每日关键词搜索排行
  • 贵州省建设厅公示网站产品宣传方式有哪些
  • 研磨 东莞网站建设2022年搜索引擎优化指南
  • 公司网站备案怎么办理淘宝店铺转让价格表
  • 网站建设深百度搜索资源平台token
  • 三丰云做网站步骤凤凰军事新闻最新消息
  • 网站建设和咨询服务合同东莞网站推广的公司
  • 阿里巴巴网站威海哪里做十大广告联盟
  • 网站空间一定要买吗网站建设推广服务
  • 用自己的电脑做网站需要备案吗网站推广的方法有哪些?
  • 网站开发管理系统有哪些一键免费生成网页的网站
  • 郑州交友网站建设企业网站有哪些功能
  • 移动网站开发公司seo发帖论坛
  • 海南省澄迈住房和城乡建设厅网站百度推广登录首页
  • 中国个人优秀网站长沙seo网络优化
  • 与建设部网站2023必考十大时政热点
  • 外贸网站开发哪家好目前病毒的最新情况
  • wordpress快速建站教程视频深圳网络营销推广外包
  • 小语种网站建设宁波优化推广找哪家
  • 做网站公司促销海报电子商务网站建设的步骤
  • 龙川网站建设黑帽seo工具
  • 济南汇展做网站b站引流推广
  • 武汉网站建设询搜点网络临沂色度广告有限公司
  • 深圳做专业网站免费发广告的平台
  • 国示范校建设网站免费外链代发