很久没有更新了。

这次新增支持四种格式的解析。

filelist

slicelist

download.cfg

third_party_download.cfg

还是2个文件。替换之前版本即可。

初步测试正常,但时间轴不对。

# -*- coding: UTF-8 -*-

import os
import io
import codecs
import string
import shutil
import moviefmt
import traceback def coroutine(func):
def start(*args,**kwargs):
g = func(*args,**kwargs)
g.next()
return g
return start @coroutine
def enum_movie_file(target):
selectedFolder = (yield)
for fileitem in os.listdir(selectedFolder):
targetFO = os.path.join(selectedFolder,fileitem)
if(os.path.isfile(targetFO) == True):
continue;
target.send(targetFO) @coroutine
def read_movie_file(funcDisp,target):
while(True):
filmFolder = (yield)
for fileitem in os.listdir(filmFolder):
targetfile = os.path.join(filmFolder,fileitem)
if(os.path.isfile(targetfile) == False):
continue;
filebasename , fext = os.path.splitext(fileitem);
if(filebasename[0] == "."):
continue
if(funcDisp.has_key(string.lower(fext))):
pfn = funcDisp[string.lower(fext)];
(targetFmt,targetObjects,filmFolderEx,filebasenameEx) = pfn(targetfile)
if(targetFmt is None):
continue;
outputs = filmFolder,filebasename, (targetFmt,targetObjects,filmFolderEx,filebasenameEx);
# outputs = filmFolder,filebasename, pfn(targetfile);
target.send(outputs)
break def getWindowsText(orgText):
try:
return orgText.encode('gbk')
except Exception as exc:
print("%s" % exc);
return orgText @coroutine
def create_report(outputfile):
objTar = codecs.open(outputfile,"w+")
while(1):
filmFolder,filebasename,(extname,piece_list,filmFolderEx,filebasenameEx) = (yield)
if(extname == None) :
break; objTar.write('cd \"%s\"\r\n' % (filmFolderEx if filmFolderEx else filmFolder)) objTar.write('attrib -h *.*\r\n ') if(len(piece_list) >1):
objTar.write('copy /b ')
else:
objTar.write('copy ') if(len(piece_list) == 1):
objTar.write('\"%s \"' %(getWindowsText(piece_list[0])))
else:
bFirst = True
for line in piece_list:
if(bFirst == False):
objTar.write('+\"%s\"' %(getWindowsText(line)))
else:
objTar.write('\"%s\"' %(getWindowsText(line)))
bFirst = False relpath = os.path.dirname(filmFolder)
currentPath = os.path.join(getWindowsText(relpath),getWindowsText(filebasenameEx if filebasenameEx else filebasename))
objTar.write(' %s.%s\r\n' % (currentPath,extname)) objTar.write('cd %s\r\n' %(relpath)) objTar.close() if __name__ == '__main__':
funcDisp = dict()
funcDisp['.bdv_0000']= moviefmt.read_bdv_file;
funcDisp['.rmvb_0000']= moviefmt.read_rmvb_file;
funcDisp['.mkv_0000']= moviefmt.read_mkv_file;
funcDisp['.bdv']= moviefmt.read_bdv_index;
funcDisp['.mp4_0000']= moviefmt.read_mp4_file;
funcDisp['']= moviefmt.read_mkv_2_file; funcDisp['.filelist'] = moviefmt.read_filelist_index;
funcDisp['.slicelist'] = moviefmt.read_slicelist_index;
funcDisp['.cfg'] = moviefmt.read_cfg_index; try:
rmf = enum_movie_file(read_movie_file(funcDisp,create_report('film.bat')))
rmf.send(os.getcwd())
rmf.close()
except StopIteration:
pass
except Exception as exc:
print("%s" % exc);
info = traceback.format_exc()
print(info)
print("done");

  

# -*- coding: UTF-8 -*-

import os
import io
import sys
import string
import shutil
import codecs
import glob
import re def read_bdv_index_V1(objFile):
piece_list= list()
for line in objFile:
if(line[0:4] != 'file'):
continue;
strings = string.split(line,'/')
tarfile = strings[len(strings)-1]
tempText = string.strip(tarfile)
piece_list.append(tempText)
return "avi",piece_list,None,None def read_bdv_index_V2(objFile):
piece_list= list()
for line in objFile:
nPos = line.count('bdv')
if( nPos <=0):
continue;
tarfile = line[0:len(line)-2]
piece_list.append(tarfile)
return "mpeg",piece_list,None,None def read_bdv_index_V3(objFile):
piece_list= list()
oneFile= os.path.basename(objFile)
piece_list.append(oneFile)
return "avi",piece_list,None,None def read_bdv_index_V4(objFile):
piece_list= list()
#skip #EXT-X-MEDIA-SEQUENCE
objFile.readline();
for line in objFile:
if(line.startswith('#')==True):
continue;
piece_list.append(line.replace('\r\n',''))
return "avi",piece_list,None,None def count_file_item(objFile,extText):
cItem = 0;
folderName = os.path.dirname(objFile)
for fileitem in os.listdir(folderName):
filebasename , fext = os.path.splitext(fileitem);
if(fext == extText):
cItem = cItem +1
return cItem def read_bdv_index(filename):
piece_list= list()
ext_type = None
filmFolderEx = None
filebasenameEx = None
# total file count
cItem = count_file_item(filename,".bdv")
if(cItem == 1):
ext_type,piece_list,filmFolderEx,filebasenameEx = read_bdv_index_V3(filename)
else:
objFile = codecs.open(filename,'r','utf-8')
topline = objFile.readline();
bdv_ver = topline.replace("\r\n","")
if(bdv_ver == '#EXTM3U'):
v3Text = objFile.readline();
if(v3Text.startswith('#EXT-X-TARGETDURATION') == False):
ext_type,piece_list = read_bdv_index_V2(objFile)
else:
ext_type,piece_list = read_bdv_index_V4(objFile)
else:
ext_type,piece_list = read_bdv_index_V1(objFile) objFile.close() return (ext_type ,piece_list,filmFolderEx,filebasenameEx) def read_bdv_file(filename):
piece_list= list()
piece_list.append('*.bdv_*')
return ('avi',piece_list,None,None) def read_rmvb_file(filename):
piece_list= list()
piece_list.append('*.rmvb_*')
return ('rmvb',piece_list,None,None) def read_mkv_file(filename):
piece_list= list()
piece_list.append('*.mkv_*')
return ('mkv',piece_list,None,None) def read_mp4_file(filename):
piece_list= list()
piece_list.append('*.mp4_*')
return ('mp4',piece_list,None,None) def read_mkv_2_file(filename):
piece_list= list()
piece_list.append('video_*')
return ('mkv',piece_list,None,None) def read_filelist_index(filename):
filmFolderEx = None
filebasenameEx = None
objFile = codecs.open(filename,'r','utf-8')
topline = objFile.readline();
bdv_ver = topline.replace("\r\n","")
if(bdv_ver == '#EXTM3U'):
v3Text = objFile.readline();
if(v3Text.startswith('#EXT-X-TARGETDURATION') == False):
ext_type,piece_list,filmFolderEx,filebasenameEx = read_bdv_index_V2(objFile)
else:
ext_type,piece_list,filmFolderEx,filebasenameEx = read_bdv_index_V4(objFile)
else:
ext_type,piece_list,filmFolderEx,filebasenameEx = read_bdv_index_V1(objFile) objFile.close()
return ("mp4" ,piece_list,filmFolderEx,filebasenameEx) def read_slicelist_index(filename):
piece_list= list()
objFile = codecs.open(filename,'r','utf-8')
topline = objFile.readline();
bdv_ver = topline.replace("\r\n","")
if(bdv_ver == '#BD-SECTION'):
while(True):
currentLine = objFile.readline();
if(currentLine is None or len(currentLine) ==0):
break
piece_list.append(currentLine.replace("\r\n",""))
objFile.close()
return ('mp4',piece_list,None,None) def read_cfg_index(filename):
piece_list= list()
simpleFileName = os.path.basename(filename)
if(simpleFileName == 'download.cfg'):
simpleFolderName = os.path.dirname(filename)
chkLst =glob.glob(os.path.join(simpleFolderName, '*.filelist'));
if(chkLst is not None and len(chkLst) >0):
return (None,None,None,None)
chkLst =glob.glob(os.path.join(simpleFolderName, '*.bdv'));
piece_list.append(chkLst[0]);
return ('avi',piece_list) if(simpleFileName != 'third_party_download.cfg'):
raise Exception('unknown format file : %s' %(filename)) reObj = re.compile('(?P<var_key>\S+):(?P<var_value>\S+)',re.IGNORECASE)
lineDict = dict()
# [orgLines.append(orgLine.replace("\r\n","") ) for orgLine in codecs.open(filename,'r','utf-8')]
for orgLine in codecs.open(filename,'r','utf-8'):
orgLine = orgLine.replace("\r\n","")
results = reObj.findall(orgLine)
if(len(results) > 0):
lineDict[results[0][0]] =results[0][1] resID = lineDict["resource"]
vid = lineDict[ '%s_vid'%(resID)]
targetName = lineDict["video_name"]
simpleFolderName = os.path.dirname(filename)
upLevelFolderName = os.path.dirname(simpleFolderName)
targetFolder = os.path.join(upLevelFolderName,vid)
targetFolder = os.path.join(targetFolder,vid) chkLst =glob.glob(os.path.join(targetFolder, '*.%s*' %(resID)));
targetFile = chkLst[0] #skip #EXT-X-MEDIA-SEQUENCE
for line in codecs.open(targetFile,'r','utf-8'):
if(line.startswith('#')==True):
continue;
line = os.path.basename(line.replace('\r\n',''))
line = os.path.basename(line.replace('\r',''))
line = os.path.basename(line.replace('\n',''))
piece_list.append(line ) return ('avi',piece_list,targetFolder,targetName)

  

合并百度影音的离线数据 with python 2.3 格式更新的更多相关文章

  1. 合并百度影音的离线数据 with python 2.1 bdv格式的更新

    最近百度影音的离线下载文件,格式有新变化. 经过分析,是bdv格式又有新格式,从最初的bdv0001,到bdv.config 的file....,这次更新的格式是直接包含一个片段,其中还有使用guid ...

  2. 合并百度影音的离线数据 with python 2.2 bdv格式的更新

    百度影音的bdv格式又有变化. 此次存在2种bdv格式. 格式1:每个文件夹内就一个bdv文件,文件合并后改名avi即可. 格式2:每个文件夹内一个bdv文件作为索引,其他附加guid的文件作为数据. ...

  3. 合并百度影音的离线数据 with python 第二版 基于yield

    重新整理了一下代码. 增加了bdv,mkv的处理流程. 目前暂时支持windows平台. bdv,mkv,rmvb的不同处理流程 # -*- coding: UTF-8 -*- import os i ...

  4. Python获得百度统计API的数据并发送邮件

    Python获得百度统计API的数据并发送邮件 小工具  本来这么晚是不准备写博客的,当是想到了那个狗子绝对会在开学的时候跟我逼逼这个事情,所以,还是老老实实地写一下吧.   Baidu统计API的使 ...

  5. AdMaster技术副总裁谈Hadoop、营销数据、Python和挖掘平台

    http://www.infoq.com/cn/news/2014/09/admaster-hadoop 卢亿雷是现任AdMaster技术副总裁,曾在联想研究院.百度基础架构部.Carbonite C ...

  6. Python处理json格式的数据文件(一些坑、一些疑惑)

    这里主要说最近遇到的一个问题,不过目前只是换了一种思路先解决了,脑子里仍然有疑惑,只能怪自己太菜. 最近要把以前爬的数据用一下了,先简单的过滤一下,以前用scrapy存数据的时候为了省事也为了用一下它 ...

  7. 利用百度云接口实现车牌识别·python

    一个小需求---实现车牌识别. 目前有两个想法 1. 调云在线的接口或者使用SDK做开发(配置环境和变异第三方库麻烦,当然使用python可以避免这些问题) 2. 自己实现车牌识别算法(复杂) 一开始 ...

  8. C#开发BIMFACE系列46 服务端API之离线数据包下载及结构详解

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在前一篇博客<C#开发BIMFACE系列45 服务端API之创建离线数据包>中通过调用接口成功的创建一个离线数 ...

  9. C#开发BIMFACE系列48 Nginx部署并加载离线数据包

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在前一篇博客<C#开发BIMFACE系列47 IIS部署并加载离线数据包>中详细介绍了IIS部署并访问的完整步 ...

随机推荐

  1. Unable to instantiate receiver XXXXXX

    运行一个工程的时候时logcat中出现了“Unable to instantiate receiver XX..”. 检查后发现,由于是东拼西凑的代码,所以在Manifest文件里注册了Receive ...

  2. ng2中文文档地址

    https://angular.cn/docs/ts/latest/guide/displaying-data.html

  3. python-----windows下安装face_recognition库

    如果直接在cmd命令界面 输入:pip install face_recognition 如下图所示: 如果第一次就会出现一系列的问题,解决此问题就安装如下步骤: 一.如果你本机没有安装vistual ...

  4. laravel 自定义分页 offset 和 limit 的使用

    laravel 本身有一个自带的快速分页方法 paginate,只需要传入每页显示多少条数据就可以 了,但是如果想使用自定义从哪里开始呢,这时候就可以使用offset 和 limit 的组合,offs ...

  5. centos7更改远程端口

    centos7更改远程端口 一.创建个普通账户(useradd work),给普通账户创建密码(password work) 二.查看应有的软件是否安装 1.查看semanager是否安装执行下面命令 ...

  6. 【201】SeaDAS代码

    参考: 官方网站:http://seadas.gsfc.nasa.gov/ L2GEN User's Guide l2gen 代码: l2gen, ifile="ifile", g ...

  7. 用script标签加载

    此文已由作者杨帆授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 注:经过更深入的测试,实在不好意思,这篇文章是有问题的 更改script的type属性 并不能通过src来加载 ...

  8. poj3187【dfs】

    挑战-搜索 题意: 给一个n和sum,代表n层的杨辉三角,然后给一个和,问最低层的数字情况. 思路: ①:预处理一个底层对于和的系数数组, sum = 0Cn-1*num[1] + 1Cn-1*num ...

  9. Codeforces404C【构造】

    题意: 一个图有n个点,每一个点最多连接k条直线,给出多有起点到终点的距离,没有环,不能输出重边,输出所有有连接的单向边 思路: 就是简单想-不知道怎么说了,画个图,我们建边,那么距离是 i 就是连距 ...

  10. 洛谷P2585 [ZJOI2006]三色二叉树(树形dp)

    传送门 设$dp[u][i]$表示点$u$颜色为$i$时最多(最少)的绿点个数(这里用$0$表示绿点) 然后直接用树形dp就可以了 记得把情况讨论清楚 //minamoto #include<b ...