當前位置: 首頁>>代碼示例>>Python>>正文


Python Dejavu.clear_data方法代碼示例

本文整理匯總了Python中dejavu.Dejavu.clear_data方法的典型用法代碼示例。如果您正苦於以下問題:Python Dejavu.clear_data方法的具體用法?Python Dejavu.clear_data怎麽用?Python Dejavu.clear_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dejavu.Dejavu的用法示例。


在下文中一共展示了Dejavu.clear_data方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Generate

# 需要導入模塊: from dejavu import Dejavu [as 別名]
# 或者: from dejavu.Dejavu import clear_data [as 別名]
class Generate(object):

    """
        Given a labelled output file and the corresponding video tags, extracts the commercial segments and fingerprints them.
    """

    def __init__(self, labels_fname, video_name):
        
        label_file_type = mimetypes.guess_type(labels_fname)[0]
        video_file_type = mimetypes.guess_type(video_name)[0]
        
        if label_file_type[:3] != "tex":
            #The file is not a labels file
            print "Incorrect label file"
            raise Exception(INCORRECT_LABEL_FILE_ERROR)
        
        if video_file_type[:3] != "vid":
            #The file is not a video file
            print "Incorrect video file"
            raise Exception(INCORRECT_VIDEO_FILE_ERROR)
            
        self.labels = LabelsFile(labels_fname)
        self.video_name = video_name
        self.djv = Dejavu(CONFIG)
        self.db_content = []
            
    def build_db(self, aud_ext=".wav", vid_ext=".mpg"):
        
        """
            Build a sql db with the commercials
        """
        
        #This returns the entire contents of the file, more about structure of return type in fileHandler.py
        labels = self.labels.read_lables()
        
        #Number of files in the directory + 1
        filename = len(os.listdir(DB_AUDIO)) + 1
        
        #Try reading contents from csv file, if it already exists
        try:
            #Already exists
            #We open and read the content first
            with open(DBNAME) as f:
                lines = f.readlines()
                self.db_content = [line.split(',')[1] for line in lines[1:]] #Only names of commercials
            f = open(DBNAME, "a")
            
        except:
            #Creating for the first time
            print "File does not exist so creating..."
            f = open(DBNAME, "w")
            f.write("name, duration, path\n")
        
        for data in labels:
            
            #Extracting based on structure of return type
            start = data[0]
            end = data[1]
            name = data[2]
            
            if self.db_content != [] and (name in self.db_content):
                print "Already Fingerprinted"
                continue

            duration = timeFunc.get_delta_string(start, end)
            
            #Create a file in the db folder, audio and video are stored seperately 
            ffmpeg.create_video(start, duration, self.video_name, DB_VIDEO + str(filename) + vid_ext)
            ffmpeg.create_audio(DB_VIDEO + str(filename) + vid_ext, DB_AUDIO + str(filename) + aud_ext)
            
            #Create a corresponding entry in the csv file
            s = ",".join([name, duration])
            s = s + "," + DB_VIDEO + str(filename) + vid_ext + "\n" #Check verified to be true since human tagged
            f.write(s)
            filename += 1

    def fingerprint_db(self, aud_ext=".wav", no_proc=1):

        #This fingerprints the entire directory
        self.djv.fingerprint_directory(DB_AUDIO, [aud_ext])
        
    def clean_db(self, aud_ext=".wav", vid_ext=".mpg"):
        
        choice = raw_input("Are you sure you want to remove all commercials in the database? (yes/no)")
        if choice == "yes":
            #Clear the mysql db
            self.djv.clear_data() 
            print "Cleaning database.."
            
            #Now we remove files from db/audio and db/video
            filename = len(os.listdir(DB_AUDIO)) + 1
            for i in range(1, filename):
                try:
                    os.remove(DB_AUDIO + str(i) + aud_ext)
                    os.remove(DB_VIDEO + str(i) + vid_ext)
                except:
                    print "File already removed, or you don't have permission"
                    
            os.remove(DBNAME)
            print "Database is empty"
#.........這裏部分代碼省略.........
開發者ID:EvanWeiner,項目名稱:CommercialDetection,代碼行數:103,代碼來源:generate.py


注:本文中的dejavu.Dejavu.clear_data方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。