1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
package de.danoeh.antennapod.feed;
import de.danoeh.antennapod.util.vorbiscommentreader.VorbisCommentReaderException;
import java.util.concurrent.TimeUnit;
public class VorbisCommentChapter extends Chapter {
public static final int CHAPTERTYPE_VORBISCOMMENT_CHAPTER = 3;
private static final int CHAPTERXXX_LENGTH = "chapterxxx".length();
private int vorbisCommentId;
public VorbisCommentChapter(int vorbisCommentId) {
this.vorbisCommentId = vorbisCommentId;
}
public VorbisCommentChapter(long start, String title, FeedItem item,
String link) {
super(start, title, item, link);
}
@Override
public String toString() {
return "VorbisCommentChapter [id=" + id + ", title=" + title
+ ", link=" + link + ", start=" + start + "]";
}
public static long getStartTimeFromValue(String value)
throws VorbisCommentReaderException {
String[] parts = value.split(":");
if (parts.length >= 3) {
try {
long hours = TimeUnit.MILLISECONDS.convert(
Long.parseLong(parts[0]), TimeUnit.HOURS);
long minutes = TimeUnit.MILLISECONDS.convert(
Long.parseLong(parts[1]), TimeUnit.MINUTES);
if (parts[2].contains("-->")) {
parts[2] = parts[2].substring(0, parts[2].indexOf("-->"));
}
long seconds = TimeUnit.MILLISECONDS.convert(
((long) Float.parseFloat(parts[2])), TimeUnit.SECONDS);
return hours + minutes + seconds;
} catch (NumberFormatException e) {
throw new VorbisCommentReaderException(e);
}
} else {
throw new VorbisCommentReaderException("Invalid time string");
}
}
/**
* Return the id of a vorbiscomment chapter from a string like CHAPTERxxx*
*
* @return the id of the chapter key or -1 if the id couldn't be read.
* @throws VorbisCommentReaderException
* */
public static int getIDFromKey(String key)
throws VorbisCommentReaderException {
if (key.length() >= CHAPTERXXX_LENGTH) { // >= CHAPTERxxx
try {
String strId = key.substring(8, 10);
return Integer.parseInt(strId);
} catch (NumberFormatException e) {
throw new VorbisCommentReaderException(e);
}
}
throw new VorbisCommentReaderException("key is too short (" + key + ")");
}
/**
* Get the string that comes after 'CHAPTERxxx', for example 'name' or
* 'url'.
*/
public static String getAttributeTypeFromKey(String key) {
if (key.length() > CHAPTERXXX_LENGTH) {
return key.substring(CHAPTERXXX_LENGTH, key.length());
}
return null;
}
@Override
public int getChapterType() {
return CHAPTERTYPE_VORBISCOMMENT_CHAPTER;
}
public void setTitle(String title) {
this.title = title;
}
public void setLink(String link) {
this.link = link;
}
public void setStart(long start) {
this.start = start;
}
public int getVorbisCommentId() {
return vorbisCommentId;
}
public void setVorbisCommentId(int vorbisCommentId) {
this.vorbisCommentId = vorbisCommentId;
}
}
|