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

最近百度影音的离线下载文件,格式有新变化。

经过分析,是bdv格式又有新格式,从最初的bdv0001,到bdv.config 的file。。。。,这次更新的格式是直接包含一个片段,其中还有使用guid绑定索引和文件名。

新版本以“#EXTM3U”作为标识,并且输出格式是mpeg2(通过GSpot检查的)。

以下是新的moviefmt.py脚本,主程序还是复用2.0的mergefilm.py

 

 

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

import os
import io
import sys
import string
import shutil
import codecs


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


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


def read_bdv_index(filename): 
    piece_list= list()   
    ext_type = None
    objFile = codecs.open(filename,'r','utf-8')    
    topline = objFile.readline();
    bdv_ver = topline.replace("\r\n","")
    if(bdv_ver == '#EXTM3U'):
        ext_type,piece_list = read_bdv_index_V2(objFile)
    else:
        ext_type,piece_list  = read_bdv_index_V1(objFile)

    objFile.close()       
    return  (ext_type ,piece_list)        


   

def read_bdv_file(filename):
    piece_list= list()
    piece_list.append('*.bdv_*')
    return  ('avi',piece_list)

def read_rmvb_file(filename):
    piece_list= list()
    piece_list.append('*.rmvb_*')
    return  ('rmvb',piece_list)

def read_mkv_file(filename):
    piece_list= list()    
    piece_list.append('*.mkv_*')
    return  ('mkv',piece_list)

def read_mp4_file(filename):
    piece_list= list()    
    piece_list.append('*.mp4_*')
    return  ('mp4',piece_list)

def read_mkv_2_file(filename):
    piece_list= list()    
    piece_list.append('video_*')
    return  ('mkv',piece_list)

 

你可能感兴趣的:(python)