Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ installation
usage
-----

assuming you have a file named ``episode_42.mp3``, ``mp3chaps`` looks for a chapter marks file called ``episode_42.chapters.txt`` in the same directory::
assuming you have a file named ``episode_42.mp3``, ``mp3chaps`` looks for a chapter marks file called ``episode_42.chapters.txt`` in the same directory.

**Important**: File must be encoded in your system default file format, e.g. ANSI for Windows and UTF-8 for Unix

either::

00:00:00.000 Introduction
00:02:00.000 Chapter Title
00:42:24.123 Chapter Title

or (Audacity export format, separated by tab, contains 2x start time in seconds of the chapter)::

0.000000 0.000000 Chapter 1
85.180378 85.180378 Chapter 2
543.822379 543.822379 Chapter 3 - spaces are allowed as you like

add chapter marks
-----------------
add (import) chapter marks from text file (unexpected results may occur if chapters already exist, for best results remove chapters first with -r)
Expand Down
14 changes: 12 additions & 2 deletions mp3chaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ def parse_chapters_file(fname):
chaps = []
with open(chapters_fname, "r") as f:
for line in f.readlines():
time, title = line.split()[0], " ".join(line.split()[1:])
chaps.append((to_millisecs(time), title))
if '\t' in line:
#assume we have audacity format
# e.g. "85.180378<\t>85.180378<\t>Chapter 1"
# (<time in seconds> <tab> <time in seconds> <tab> <chapter name>
time, title = line.split('\t')[0], line.split('\t')[2].strip()
chaps.append((float(time) * 1000, title))
else:
#previous format
# e.g. 00:15:00.000 Chapter 1
# (<hh:mm:ss.ms> <Chapter name>)
time, title = line.split()[0], " ".join(line.split()[1:])
chaps.append((to_millisecs(time), title))
return chaps

def add_chapters(tag, fname):
Expand Down