Advertisement
andy_shev

Tracklist parser

Jul 9th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  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. for line in open(tracklist, 'r').read().splitlines():
  24.     start, end, author, title = line.split('=')
  25.     sec_end = to_seconds(end)
  26.     cmd = "ffmpeg -ss %s -i %s -c:a copy -c:v copy -t %d '%s - %s'" % (start, media, sec_end, author, title)
  27.     print cmd
  28.     #os.system(cmd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement