2016-11-06 1 views
1

を持ってYouTubeの自動生成されたキャプションファイルは、私は非連続的なタイミングで次のファイルを持って、私は自動キャプションに応じて、彼らのキャプションファイルを要求することで、その後の動画をアップロードするYouTubeのAPI 3を使用しています非連続的なタイミング


00:00:0万 - > 00:00:06629

良い週末ええと、私の週末だったか、私たち

00:00:05549 - > 00:00:14960

私たちは

これを行わない

00:00:06629 - > 00:00:14960

ええ、それはよくそういいローマンだ私はダメ


サンプル動画:https://youtu.be/F2TVsMD_bDQ

なぜ、各字幕スロットの終わりは、次の字幕スロットの最初ではありませんか?

+0

あなたはこれでどのようなリクエストを使用していますか? YouTubeのドキュメントで「試してみてください」と試しましたか? – KENdi

+0

@KENdi私はちょうどドキュメントhttps://developers.google.com/youtube/v3/docs/videos/insertに従いました ビデオをYouTubeにアップロードするには、https://developers.google.com/youtubeでキャプションをリクエストしてください/ v3/docs/caption/download – YouYou

+0

YouTubeダッシュボードダウンロードしたファイルで同じ問題が発生したとき – YouYou

答えて

1

YouTubeのドキュメントを検索した後、私はこの問題を解決するために何も見つけなかったので、自分自身でこの状況を解決しました。正規表現を使用して字幕のタイミングを修正するコードを作成しました。

/** 
* 
* @author youans 
*/ 
public class SubtitleCorrector { 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     try { 
      String fileContent = null; 
      File inFile = new File("/IN_DIRECTORY/Test Video Bad Format.srt"); 
      BufferedReader br = new BufferedReader(new FileReader(inFile)); 
      try { 
       StringBuilder sb = new StringBuilder(); 
       String line = br.readLine(); 

       while (line != null) { 
        sb.append(line); 
        sb.append("\n"); 
        line = br.readLine(); 
       } 
       fileContent = sb.toString(); 
      } finally { 
       br.close(); 
      } 
      String ragex = "\\d{2}:\\d{2}:\\d{2},\\d{3}"; 
      List<String> slotsTiming = new ArrayList(new TreeSet(getAllMatches(fileContent, ragex))); 

      System.out.println(slotsTiming.size()); 

      String timingRagex = "(((^1\n)|(\\n\\d+\n))(\\d{2}:\\d{2}:\\d{2},\\d{3}.*\\d{2}:\\d{2}:\\d{2},\\d{3}))"; 
      ragex = timingRagex + "[A-Za-z-,;'\"\\s]+"; 

      List<String> subtitleSlots = getAllMatches(fileContent, ragex); 
      List<String> textOnlySlots = new ArrayList(); 

      for (String subtitleSlot : subtitleSlots) { 
       textOnlySlots.add(subtitleSlot.replaceAll(timingRagex + "|\n", "")); 
      } 
      StringBuilder sb = new StringBuilder(""); 

      for (int i = 0; i < textOnlySlots.size(); i++) { 
       sb.append((i + 1)).append("\n").append(slotsTiming.get(i)).append(" --> ").append(slotsTiming.get(i + 1)).append("\n").append(textOnlySlots.get(i)).append("\n\n"); 
      } 

      File outFile = new File("/OUT_DIRECTOR/" + inFile.getName().replaceFirst("[.][^.]+$|bad format", "") + "_edited.SRT"); 
      PrintWriter pw = new PrintWriter(outFile); 

      pw.write(sb.toString()); 
      pw.flush(); 
      pw.close(); 

     } catch (Exception ex) { 
      ex.printStackTrace(); 
     } 

    } 

    public static List<String> getAllMatches(String text, String regex) { 
     List matches = new ArrayList<>(); 
     Matcher m = Pattern.compile("(?=(" + regex + "))").matcher(text); 
     while (m.find()) { 
      matches.add(m.group(1)); 
     } 
     return matches; 
    } 

} 
関連する問題