合并百度影音的离线数据( with python 2.3)

合并百度影音的离线数据( with python 2.3),第1张

概述四种格式的解析:filelistslicelistdownload.cfgthird_party_download.cfg还是2个文件。替换之前版本即可。

四种格式的解析:

fileList

sliceList

download.cfg

third_party_download.cfg

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

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

代码如下:

# -*- Coding: UTF-8 -*-import osimport ioimport codecsimport stringimport shutilimport movIEfmtimport tracebackdef coroutine(func): def start(*args,**kwargs):  g = func(*args,**kwargs)  g.next()  return g return start@coroutinedef 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)  @coroutinedef 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,filebasenameEx);    # outputs = filmFolder,pfn(targetfile);    target.send(outputs)    breakdef getwindowsText(orgText):  try:  return orgText.encode('gbk')  except Exception as exc:   print("%s" % exc);   return orgText@coroutinedef create_report(outputfile): objTar = codecs.open(outputfile,"w+")   while(1):  filmFolder,(extname,pIEce_List,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 osimport ioimport sysimport stringimport shutilimport codecsimport globimport redef 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",None,Nonedef 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",Nonedef read_bdv_index_V3(objfile): pIEce_List= List()    onefile= os.path.basename(objfile)  pIEce_List.append(onefile) return "avi",Nonedef 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",Nonedef 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,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,filebasenameEx)  def read_bdv_file(filename): pIEce_List= List() pIEce_List.append('*.bdv_*') return ('avi',None)def read_rmvb_file(filename): pIEce_List= List() pIEce_List.append('*.rmvb_*') return ('rmvb',None)def read_mkv_file(filename): pIEce_List= List()  pIEce_List.append('*.mkv_*') return ('mkv',None)def read_mp4_file(filename): pIEce_List= List()  pIEce_List.append('*.mp4_*') return ('mp4',None)def read_mkv_2_file(filename): pIEce_List= List()  pIEce_List.append('vIDeo_*') return ('mkv',None)def read_fileList_index(filename): filmFolderEx = None filebasenameEx = None objfile = codecs.open(filename,'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,filebasenameEx = read_bdv_index_V2(objfile)  else:   ext_type,filebasenameEx = read_bdv_index_V4(objfile)    else:  ext_type,filebasenameEx = read_bdv_index_V1(objfile) objfile.close()   return ("mp4",filebasenameEx)    def read_sliceList_index(filename): pIEce_List= List()  objfile = codecs.open(filename,"") 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',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)  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,'utf-8')] for orgline in codecs.open(filename,'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,'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',targetFolder,targetname)

以上就是本文的全部内容,希望大家喜欢。

总结

以上是内存溢出为你收集整理的合并百度影音离线数据( with python 2.3)全部内容,希望文章能够帮你解决合并百度影音的离线数据( with python 2.3)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1205053.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存