20240102使用python3将视频切片改名之后合并

20240102使用python3将视频切片改名之后合并
2024/1/2 22:12


缘起:将迅雷下载的视频切片排序之后再通过ffmpeg合并!
https://pri-cdn-tx.xiaoeknow.com/app1cE7gLFM1187/confusion_index/1703599111EAPoRE.m3u8?sign=f17e1a2cc0ddd77801f3c5110116369e&t=6593e36d&time=1704190828870&uuid=u_61657799613cc_jnj1eQYPEW
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_243725670_1.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_354940031_2.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_2082117154_3.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_1907493871_4.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_1832752498_5.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_700430004_6.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_671856050_7.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/12c957743270835014325912026/2399712155_79673079_1.ts?resolution=1920x1080&sign=43662e620db9bba569d591aebac7a2cd&t=12182fa06&us=DNDqKZeGEf
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/12c957743270835014325912026/2399712155_884155923_2.ts?resolution=1920x1080&sign=43662e620db9bba569d591aebac7a2cd&t=12182fa06&us=DNDqKZeGEf


下载之后就是,
2399712155_243725670_1.ts
2399712155_354940031_2.ts
2399712155_2082117154_3.ts
2399712155_1907493871_4.ts
2399712155_1832752498_5.ts
2399712155_700430004_6.ts
2399712155_671856050_7.ts
2399712155_79673079_1.ts
2399712155_884155923_2.ts


需要改名为:【规则有序的才方便合并!】
001.ts
002.ts
003.ts
004.ts
005.ts
006.ts
007.ts
008.ts
009.ts


百度:python 字符串 split
https://www.python100.com/html/L5CS7538Y4TN.html
Python中如何分离字符串?
更新:2023-06-10 08:09
Python作为一种非常流行的编程语言,在实际开发中,对字符串的处理非常重要。字符串是一个不可分割的文本序列,它通常用来存储和展示信息。在Python中,有许多方法可以帮助我们分离字符串,这篇文章将介绍一些常见的方法。

一、split()函数
Python中最常见的分离字符串的方法是使用split()函数。该函数用于将字符串分割成子字符串,并返回一个子字符串列表。


# 示例代码
string = "hello world"
separated_string = string.split()
print(separated_string)
运行以上示例代码,将会输出["hello", "world"]。

可以使用split()函数的分隔符参数来自定义分隔符。默认情况下,分隔符是空格。


# 示例代码
string = "hello,world"
separated_string = string.split(",")
print(separated_string)
运行以上示例代码,将会输出["hello", "world"]。

百度:python _ 分离字符
百度:python获取当前目录下所有文件名

https://www.jb51.net/python/2966784ma.htm
Python获取当前目录下所有文件的6种方法总结
 更新时间:2023年08月30日 08:30:10   作者:小龙在山东  

os模块中的walk()函数
使用os模块中的walk()函数递归遍历当前目录下的所有文件和文件夹,并可以通过filter函数过滤出需要的文件。

import os
dir_path = '当前目录'
for dirpath, dirnames, filenames in os.walk(dir_path):
    for filename in filenames:
        if filename == '需要获取的文件名字':
            print(os.path.join(dirpath, filename))


参考资料:
SyntaxError: Non-UTF-8 code starting with '\xb5' in file H:\迅雷下载\视频任
https://blog.csdn.net/m0_57098592/article/details/129195911
SyntaxError: Non-UTF-8 code starting with ‘\xb5‘ in file

# -*- encoding:utf-8 -*-

百度:python if
百度:python 改名
百度:python 改名

https://www.python100.com/html/97487.html
Python文件改名全攻略
更新:2023-05-20 01:44
一、Python文件改名字
想要改变Python文件的名称,只需要使用os.rename()函数即可。该函数的参数有两个,第一个参数为原始文件名,第二个参数为修改后的文件名。以下是一个简单的代码示例:

import os
os.rename('old-name.py', 'new-name.py')
需要注意的是,如果你想将该文件移动到其他文件夹,请在第二个参数中填写新文件夹地址和文件名。


百度:python 出错不要退出FileExistsError: [WinError 183] 当文件已存在时,无法创建该
百度:python 文件是否存在

https://pythonjishu.com/unzkbnhrnjsupwf/
Python判断文件或文件夹是否存在的三种方法
2023年6月2日 下午6:22 • python
当我们编写Python脚本时,经常需要判断某个文件或文件夹是否存在,这在数据处理、文件操作等应用场景中尤其常见。本文将介绍Python中判断文件或文件夹是否存在的三种方法。

方法一:使用os模块中的path.exists()函数
os模块是Python中对操作系统进行调用的接口,其中的path模块提供了一些用于处理文件或者目录路径的函数。path.exists()函数可用于判断指定路径的文件或文件夹是否存在,该函数的参数为要判断的路径名(可以是相对或绝对路径)。

以下是一个示例代码:

import os

file_path = 'data/example.txt'
folder_path = 'data'

# 判断文件是否存在
if os.path.exists(file_path):
    print('文件存在!')
else:
    print('文件不存在!')

# 判断文件夹是否存在
if os.path.exists(folder_path):
    print('文件夹存在!')
else:
    print('文件夹不存在!')
在上述代码中,我们通过os.path.exists()函数判断文件data/example.txt和文件夹data是否存在,并分别输出结果。

https://pri-cdn-tx.xiaoeknow.com/app1cE7gLFM1187/confusion_index/1703599111EAPoRE.m3u8?sign=f17e1a2cc0ddd77801f3c5110116369e&t=6593e36d&time=1704190828870&uuid=u_61657799613cc_jnj1eQYPEW
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_243725670_1.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_354940031_2.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_2082117154_3.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_1907493871_4.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_1832752498_5.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_700430004_6.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/5672d15a3270835014326519262/2399712155_671856050_7.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/12c957743270835014325912026/2399712155_79673079_1.ts?resolution=1920x1080&sign=43662e620db9bba569d591aebac7a2cd&t=12182fa06&us=DNDqKZeGEf
https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/12c957743270835014325912026/2399712155_884155923_2.ts?resolution=1920x1080&sign=43662e620db9bba569d591aebac7a2cd&t=12182fa06&us=DNDqKZeGEf

通过Ultraedit9修改为:

2399712155_243725670_1.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
2399712155_354940031_2.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
2399712155_2082117154_3.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
2399712155_1907493871_4.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
2399712155_1832752498_5.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
2399712155_700430004_6.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
2399712155_671856050_7.ts?resolution=1920x1080&sign=165eeea830f24949ca87d874142f440d&t=12182fa06&us=imDEzTHxRU
2399712155_79673079_1.ts?resolution=1920x1080&sign=43662e620db9bba569d591aebac7a2cd&t=12182fa06&us=DNDqKZeGEf
2399712155_884155923_2.ts?resolution=1
920x1080&sign=43662e620db9bba569d591aebac7a2cd&t=12182fa06&us=DNDqKZeGEf

然后通过python3替换为:

001.ts
002.ts
003.ts
004.ts
005.ts
006.ts
007.ts
008.ts
009.ts

源码:

import requests
from multiprocessing import Pool

import os

f = open("1574r.txt")

for n in range(1,4000):
    line = f.readline()
    #lst = filename.split("_")
    lst = line.split("?")
    #print(lst[0])
    
    #os.rename('old-name.py', 'new-name.py')
    #os.rename(filename, lst[-1])
    #os.rename(lst[0], "./1574/%03d.ts"%(n+1))
    os.rename(lst[0], "%03d.ts"%n)

之后就可以合并了!

相关推荐

  1. Python3 列表--20240104

    2024-01-03 15:10:03       37 阅读
  2. python视频合并

    2024-01-03 15:10:03       46 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-03 15:10:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-03 15:10:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-03 15:10:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-03 15:10:03       20 阅读

热门阅读

  1. Mysql8.2安装

    2024-01-03 15:10:03       45 阅读
  2. 复试 || 就业day06(2024.01.01)算法篇

    2024-01-03 15:10:03       42 阅读
  3. uml基础-类图

    2024-01-03 15:10:03       33 阅读
  4. 防勒索病毒攻击的关键措施

    2024-01-03 15:10:03       38 阅读
  5. AI+金融:大模型引爆金融科技革命

    2024-01-03 15:10:03       38 阅读
  6. Linux zip 命令

    2024-01-03 15:10:03       32 阅读
  7. Oracle 19C DBA管理常用命令

    2024-01-03 15:10:03       36 阅读
  8. k8s---Pod的生命周期

    2024-01-03 15:10:03       28 阅读