Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. # Meu input
  2. '''
  3. Talvez.
  4. 00:29:04.27\00:29:06.09
  5. Eu não sabia
  6. o que dizer.
  7. 00:29:09.20\00:29:11.13
  8. Que tal: "Oi. Olá.
  9. Quanto tempo! Como está você?"
  10. 00:29:12.07\00:29:16.16
  11. -Oi.
  12. -Olá. Quanto tempo!
  13. 00:29:20.29\00:29:23.24
  14. '''
  15.  
  16. # Meu pattern:
  17.  
  18.  
  19. pattern = re.compile(r'''^
  20.    (?P<txt>\.*)    # the text of the subtitle
  21.    (?P<sh>\d{2}):  # start's with 2 decimals (sh) + :
  22.    (?P<sm>\d{2}):  # idem (sm)
  23.    (?P<ss>\d{2})\. # plus 2 decimals (ss) and a dot
  24.    (?P<sl>\d{2})\\ # 2 decimals (sm) and a slash
  25.    (?P<fh>\d{2})\: # 2 decimals (fh) and :
  26.    (?P<fm>\d{2})\: # idem (fm)
  27.    (?P<fs>\d{2})\. # 2 decimals (fs) and a dot
  28.    (?P<fl>\d{2})   # last 2 decimals (fm)''', re.X
  29. )
  30.  
  31. # Resultado, algo assim, para cada match:
  32.  
  33. {
  34. 'txt': 'Aqui a legenda\ncom quebra de linha\nblablabla!',
  35. 'sh': '00',
  36. 'sm': '00',
  37. 'ss': '00',
  38. 'sl': '00',
  39. 'fh': '00',
  40. 'fm': '00',
  41. 'fs': '00',
  42. 'fl': '00',
  43. }
  44.  
  45. # Porém o ?P<txt> eu não to conseguindo captruar com a quebra de linha, no idea why
Add Comment
Please, Sign In to add comment