Advertisement
andy_shev

Tracklist parser v2

Jul 9th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python -tt
  2. # -*- coding: UTF-8 -*-
  3. # vim: ts=4 sw=4 et ai si
  4.  
  5. import sys
  6. import os
  7.  
  8. """Run 'this_script.py video.mp4'."""
  9.  
  10. def to_seconds(timestamp):
  11.     seconds = 0
  12.     for item in timestamp.strip().split(':'):
  13.         seconds = seconds * 60 + int(item)
  14.     return seconds
  15.  
  16. media = sys.argv[1]
  17. tracklist = os.path.splitext(media)[0] + "-tracklist" + os.path.extsep + "txt"
  18.  
  19. # <время начала трека>РАЗДЕЛИТЕЛЬ<время окончания трека>РАЗДЕЛИТЕЛЬ<исполнитель>РАЗДЕЛИТЕЛЬ<название>
  20. # РАЗДЕЛИТЕЛЬ - единичный символ (что в голову взбредет, опробовано "%" и "=")
  21. # <время...> - в виде HH:MM:SS
  22.  
  23. data = []
  24. for line in open(tracklist, 'r').read().splitlines():
  25.     start, end, author, title = line.split('=')
  26.     sec_end = to_seconds(end) - to_seconds(start)
  27.     data.append((start, sec_end, '%s - %s' % (author, title)))
  28.  
  29. for item in data:
  30.     cmd = "ffmpeg -ss %s -i %s -c:a copy -c:v copy -t %d '%s'" % (item[0], media, item[1], item[2])
  31.     print cmd
  32.     #os.system(cmd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement