<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Python腳本,它將遍歷指定目錄下的所有.srt文件,移除其中的不必要的英文字符、不必要的空行以及不必要的空格。該腳本會保留字幕索引、字幕時間線以及字幕中的中文內容,并且只保留字幕中的中文內容。它還會保留字幕行與字幕之間的換行符,同時去掉字幕與字幕之間的不必要的換行符。處理后的內容將被保存為新的.srt文件。

      代碼:

      import os
      import re
      
      def is_index_line(line):
          # 檢查是否為索引行,通常索引行以數字開頭
          return bool(re.match(r'^\d+$', line))
      
      def is_time_line(line):
          # 檢查是否為時間線,包含"-->"的行
          return bool(re.search(r'-->', line))
      
      def clean_srt_file(file_path):
          with open(file_path, 'r', encoding='utf-8') as file:
              lines = file.readlines()
      
          new_content = []
          subtitle_block = []
          in_subtitle = False
      
          for line in lines:
              # 清除空白行
              if not line.strip():
                  if subtitle_block:  # 如果當前有字幕塊,則添加一個換行符
                      new_content.append(line)
                  in_subtitle = False  # 重置字幕塊狀態
                  continue
      
              if is_index_line(line) or is_time_line(line):
                  # 如果當前行為索引或時間線,則保存之前的字幕塊(如果存在)
                  if subtitle_block:
                      new_content.extend(subtitle_block)
                      new_content.append('')  # 保留字幕塊之間的換行符
                      subtitle_block = []
                  # 添加索引行和時間線
                  new_content.append(line)
                  in_subtitle = True
              elif in_subtitle:
                  # 僅保留字幕中的中文內容
                  chinese_only_line = re.sub(r'[^\u4e00-\u9fa5\n]', '', line)
                  if chinese_only_line.strip():  # 如果行內有中文字符
                      subtitle_block.append(chinese_only_line)
      
          # 添加最后一個字幕塊
          if subtitle_block:
              new_content.extend(subtitle_block)
              new_content.append('')  # 在文件末尾添加一個換行符
      
          # 保存為新的srt文件
          new_file_path = file_path.replace('.srt', '_cleaned.srt')
          with open(new_file_path, 'w', encoding='utf-8') as new_file:
              new_file.writelines(new_content)
      
          print(f'Processed and saved cleaned file to: {new_file_path}')
      
      def process_directory(directory_path):
          for filename in os.listdir(directory_path):
              if filename.endswith('.srt'):
                  file_path = os.path.join(directory_path, filename)
                  clean_srt_file(file_path)
      
      # 指定目錄路徑
      directory_path = r'C:\caijian\29-51'
      process_directory(directory_path)

       

      代碼2(改進):

      import os
      import re
      
      def clean_and_save_srt(file_path):
          with open(file_path, 'r', encoding='utf-8') as file:
              lines = file.readlines()
      
          new_content = []
          in_subtitle_block = False
          subtitle_block = []
      
          for line in lines:
              line = line.strip()
      
              if is_index_line(line) or is_time_line(line):
                  if subtitle_block:
                      new_content.extend(subtitle_block)
                      new_content.append('')  # 保留字幕塊之間的換行符
                      subtitle_block = []
                  new_content.append(line)
                  in_subtitle_block = True
              elif in_subtitle_block:
                  if line:  # 非空行
                      cleaned_line = re.sub(r'[^\S\r\n]+', '', line)  # 去除多余的空格
                      cleaned_line = re.sub(r'[^\u4e00-\u9fa5,。?!、《》()【】:",。?!]', '', cleaned_line)  # 只保留中文和部分標點
                      if cleaned_line:
                          subtitle_block.append(cleaned_line)
                  else:  # 空行
                      if subtitle_block:  # 如果字幕塊不為空,則結束當前字幕塊
                          new_content.extend(subtitle_block)
                          new_content.append('')  # 保留字幕塊之間的換行符
                          subtitle_block = []
                          in_subtitle_block = False
      
          if subtitle_block:  # 添加最后一個字幕塊
              new_content.extend(subtitle_block)
      
          new_file_path = file_path.replace('.srt', '_cleaned.srt')
          with open(new_file_path, 'w', encoding='utf-8') as new_file:
              new_file.write('\n'.join(new_content))
      
          print(f'Processed and saved cleaned file to: {new_file_path}')
      
      def is_index_line(line):
          return bool(re.match(r'^\d+$', line))
      
      def is_time_line(line):
          return bool(re.search(r'-->', line))
      
      def process_directory(directory_path):
          for filename in os.listdir(directory_path):
              if filename.endswith('.srt'):
                  file_path = os.path.join(directory_path, filename)
                  clean_and_save_srt(file_path)
      
      # 指定目錄路徑
      directory_path = r'C:\caijian\29-51'
      process_directory(directory_path)

       

      posted on 2024-10-23 13:08  大話人生  閱讀(73)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 欧美日韩视频综合一区无弹窗| 国产喷水1区2区3区咪咪爱av| 韩国 日本 亚洲 国产 不卡| 中文激情一区二区三区四区| 成在人线av无码免费高潮水老板 | 日韩老熟女av搜索结果| 天堂中文最新版在线官网在线| 精品免费看国产一区二区| 成熟女人特级毛片www免费| 国产三级国产精品久久成人| 国产不卡精品视频男人的天堂| 国产又爽又黄又爽又刺激| 国产精品久久国产精麻豆99网站| 人妻加勒比系列无码专区| 中文字幕 欧美日韩| 亚洲日产韩国一二三四区| 蜜臀av一区二区国产在线| jk白丝喷浆| 久久人妻精品国产| 黄瓜一区二区三区自拍视频| 亚洲中文字幕乱码一区| 日本高清视频网站www| 干老熟女干老穴干老女人| 男女激情一区二区三区| 日本熟妇浓毛| 无码av最新无码av专区| 在线看国产精品自拍内射| 亚洲av无码乱码在线观看牲色| 成人精品动漫一区二区| 亚洲中文字幕无码中文字| 国产极品粉嫩馒头一线天| 久久国产成人av蜜臀| 中文字幕在线国产精品| 久久人人97超碰人人澡爱香蕉| 99精品国产一区二区三区不卡 | 日本高清一区免费中文视频| 亚洲AV旡码高清在线观看| 国内自拍小视频在线看| 国产精品免费久久久免费| 四虎国产精品永久在线看| 欧洲中文字幕国产精品|