欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

合并百度影音的離線數(shù)據(jù)( with python 2.3)

 更新時(shí)間:2015年08月04日 10:17:34   作者:febwave  
這篇文章主要介紹了合并百度影音的離線數(shù)據(jù)( with python 2.3)的相關(guān)資料

四種格式的解析:

filelist

slicelist

download.cfg

third_party_download.cfg

還是2個(gè)文件。替換之前版本即可。

初步測(cè)試正常,但時(shí)間軸不對(duì)。

代碼如下:

# -*- 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)

以上就是本文的全部?jī)?nèi)容,希望大家喜歡。

相關(guān)文章

  • Python動(dòng)態(tài)規(guī)劃之零錢兌換問題詳解

    Python動(dòng)態(tài)規(guī)劃之零錢兌換問題詳解

    這篇文章主要介紹了Python動(dòng)態(tài)規(guī)劃之零錢兌換問題詳解,這次我們就按照套路模板,再來剖析一道經(jīng)典動(dòng)規(guī)題目零錢兌換,計(jì)算并返回可以湊成總金額所需的 最少的硬幣個(gè)數(shù) 如果沒有任何一種硬幣組合能組成總金額,返回-1,需要的朋友可以參考下
    2023-11-11
  • Python實(shí)現(xiàn)基本數(shù)據(jù)結(jié)構(gòu)中棧的操作示例

    Python實(shí)現(xiàn)基本數(shù)據(jù)結(jié)構(gòu)中棧的操作示例

    這篇文章主要介紹了Python實(shí)現(xiàn)基本數(shù)據(jù)結(jié)構(gòu)中棧的操作,包括基于Python實(shí)現(xiàn)棧的定義、入棧、出棧、判斷棧空或棧滿等情況,需要的朋友可以參考下
    2017-12-12
  • django項(xiàng)目中使用手機(jī)號(hào)登錄的實(shí)例代碼

    django項(xiàng)目中使用手機(jī)號(hào)登錄的實(shí)例代碼

    這篇文章主要介紹了django項(xiàng)目中使用手機(jī)號(hào)登錄的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2019-08-08
  • Python基本語法之運(yùn)算符功能與用法詳解

    Python基本語法之運(yùn)算符功能與用法詳解

    這篇文章主要介紹了Python基本語法之運(yùn)算符功能與用法,結(jié)合實(shí)例形式總結(jié)分析了Python常見運(yùn)算符相關(guān)使用技巧與操作注意事項(xiàng),需要的朋友可以參考下
    2019-10-10
  • Python jieba庫(kù)用法及實(shí)例解析

    Python jieba庫(kù)用法及實(shí)例解析

    這篇文章主要介紹了Python jieba庫(kù)用法及實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Python類型提示Type Hints示例詳解

    Python類型提示Type Hints示例詳解

    在做自動(dòng)化測(cè)試的時(shí)候,類型提示會(huì)讓你寫代碼時(shí)更加流程,當(dāng)你在一個(gè)模塊定義了類型,而其他模塊沒有提示的時(shí)候,是相當(dāng)不方便,這篇文章主要給大家介紹了關(guān)于Python類型提示Type Hints的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • Python使用matplotlib創(chuàng)建Gif動(dòng)圖的思路

    Python使用matplotlib創(chuàng)建Gif動(dòng)圖的思路

    這篇文章主要介紹了Python使用matplotlib創(chuàng)建Gif動(dòng)圖,我們將討論matplotlib提供的名為“Animation”的動(dòng)畫庫(kù)之一,Python二維繪圖庫(kù)是Matplolib可以輕松創(chuàng)建繪圖、直方圖、條形圖、散點(diǎn)圖等,需要的朋友可以參考下
    2022-04-04
  • Python之Anaconda啟動(dòng)過程中的異常錯(cuò)誤問題及解決

    Python之Anaconda啟動(dòng)過程中的異常錯(cuò)誤問題及解決

    這篇文章主要介紹了Python之Anaconda啟動(dòng)過程中的異常錯(cuò)誤問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • python解析xml文件方式(解析、更新、寫入)

    python解析xml文件方式(解析、更新、寫入)

    這篇文章主要介紹了python解析xml文件方式(解析、更新、寫入),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • python發(fā)布模塊的步驟分享

    python發(fā)布模塊的步驟分享

    這篇文章主要介紹了python發(fā)布模塊的步驟,需要的朋友可以參考下
    2014-02-02

最新評(píng)論