热门标签 | HotTags
当前位置:  开发笔记 > 后端 > 正文

合并百度影音的离线数据(withpython2.3)

这篇文章主要介绍了合并百度影音的离线数据(withpython2.3)的相关资料
四种格式的解析:

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('(&#63;P\S+):(&#63;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)

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

推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 磁盘健康检查与维护
    在计算机系统运行过程中,硬件或电源故障可能会导致文件系统出现异常。为确保数据完整性和系统稳定性,定期进行磁盘健康检查至关重要。本文将详细介绍如何使用fsck和badblocks工具来检测和修复文件系统及硬盘扇区的潜在问题。 ... [详细]
  • 雨林木风 GHOST XP SP3 经典珍藏版 V2017.11
    雨林木风 GHOST XP SP3 经典珍藏版 V2017.11 ... [详细]
  • 实用正则表达式有哪些
    小编给大家分享一下实用正则表达式有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下 ... [详细]
  • 主板IO用W83627THG,用VC如何取得CPU温度,系统温度,CPU风扇转速,VBat的电压. ... [详细]
  • 本文探讨了如何在Classic ASP中实现与PHP的hash_hmac('SHA256', $message, pack('H*', $secret))函数等效的哈希生成方法。通过分析不同实现方式及其产生的差异,提供了一种使用Microsoft .NET Framework的解决方案。 ... [详细]
  • 本文详细介绍了 Android 开发中 layout_gravity 属性的使用方法及其在不同布局下的效果,旨在帮助开发者更好地理解和利用这一属性来精确控制视图的布局。 ... [详细]
  • Shell脚本中变量操作详解
    本文基于《鸟哥的Linux私房菜》一书,详细介绍了Shell脚本中变量的使用方法,包括变量的赋值规则、字符串处理技巧以及环境变量的管理等,旨在帮助读者更好地理解和使用Shell中的变量。 ... [详细]
  • 本文探讨了如何在VBA中动态执行保存为变量的代码行,特别是针对不同表单的字段引用。通过示例和详细的解答,帮助读者掌握这一技术。 ... [详细]
  • 本文将详细介绍多个流行的 Android 视频处理开源框架,包括 ijkplayer、FFmpeg、Vitamio、ExoPlayer 等。每个框架都有其独特的优势和应用场景,帮助开发者更高效地进行视频处理和播放。 ... [详细]
  • 1,bat由来:BATCH,一批,成批作业,批处理文件后缀BAT就取的前三个字母。2,Pingsz.tencent.com>a.txt>的作用为, ... [详细]
  • 本文介绍了一个基于 Java SpringMVC 和 SSM 框架的综合系统,涵盖了操作日志记录、文件管理、头像编辑、权限控制、以及多种技术集成如 Shiro、Redis 等,旨在提供一个高效且功能丰富的开发平台。 ... [详细]
  • 优化后的摘要:本文详细分析了当前面临的挑战和机遇,结合具体实例探讨了如何通过创新和改革来推动长期可持续发展。文中还介绍了多种可行的解决方案,并强调了在不同阶段实施这些方案的重要性。 ... [详细]
  • 本文介绍了如何在 JavaScript 中对两个结构不同的数组进行数据合并,提供详细的代码示例和解释。 ... [详细]
  • 探讨C#中如何正确访问静态成员,避免使用实例引用导致的错误。 ... [详细]
author-avatar
louning5257_364
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有