Advertisement
voyeg3r

pysubedit.py

Mar 5th, 2014
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # # -*- coding: UTF-8 -*-"
  3. # ----------------------------------------------------------
  4. #         CREATED:  Qua 05/Mar/2014 hs 10:24
  5. #     LAST CHANGE:  2014 Mar 05 11:53:20
  6. # THIS SCRIPT AIM:  fix subtitle files
  7. #          AUTHOR:  Sergio Luiz Araujo Silva
  8. #            SITE:  http://vivaotux.blogspot.com
  9. #         TWITTER:  @voyeg3r
  10. # ----------------------------------------------------------
  11.  
  12. # aqui um pequeno guia do pysrt
  13. # http://tuxbalaji.wordpress.com/2013/10/05/how-to-fix-subtitles-delay-or-ealier-with-your-movies-by-python-code/
  14.  
  15. # aqui dois tutorial do argparse
  16. # http://www.pythonforbeginners.com/argparse/argparse-tutorial
  17. # http://www.cyberciti.biz/faq/python-command-line-arguments-argv-example/
  18.  
  19. # >>> subs.shift(seconds=-2) # Move all subs 2 seconds earlier
  20. # >>> subs.shift(minutes=1)  # Move all subs 1 minutes later
  21.  
  22.  
  23. #subs=open("/home/bala/Pirates of the Caribbean -The Curse of the Black Pearl(2003).srt")
  24. #subs.shift(minutes=-2) # Move all subs 2 minutes earlier
  25. #subs.save('/home/bala/new.srt', encoding='utf-8')#saves file with new.srt in your home directory
  26.  
  27. import pysrt, argparse
  28.  
  29. parser = argparse.ArgumentParser(description='This is a demo script by nixCraft.')
  30. parser.add_argument('-i','--input', help='Input file name', required=True)
  31. parser.add_argument('-o','--output', help='Output file name', required=True)
  32. parser.add_argument('-t','--time', help='time shift', required=True)
  33. args = parser.parse_args()
  34.  
  35. subs=open(args.input)
  36. subs.shift(seconds=int(args.time)) #nessa linha tinha que converter para inteiro
  37. subs.save(args.output, encoding='utf-8')
  38.  
  39. ## show values ##
  40. #print ("Input file: %s" % args.input )
  41. #print ("Output file: %s" % args.output )
  42. #print ("Time shift: %s" % args.time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement