欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-24 22:21:28
...
四种格式的解析:

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):
   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\S+):(?P\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)

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频