Parse podcast:transcript url and store in SQLite (#6739)

This commit is contained in:
Tony Tam
2023-12-06 10:26:20 -10:00
committed by ByteHamster
parent 59c5042a65
commit 8adbad9b66
7 changed files with 106 additions and 4 deletions

View File

@ -43,6 +43,8 @@ public class FeedItem implements Serializable {
private transient Feed feed;
private long feedId;
private String podcastIndexChapterUrl;
private String podcastIndexTranscriptUrl;
private String podcastIndexTranscriptType;
private int state;
public static final int NEW = -1;
@ -83,7 +85,8 @@ public class FeedItem implements Serializable {
* */
public FeedItem(long id, String title, String link, Date pubDate, String paymentLink, long feedId,
boolean hasChapters, String imageUrl, int state,
String itemIdentifier, boolean autoDownloadEnabled, String podcastIndexChapterUrl) {
String itemIdentifier, boolean autoDownloadEnabled, String podcastIndexChapterUrl,
String transcriptType, String transcriptUrl) {
this.id = id;
this.title = title;
this.link = link;
@ -96,6 +99,10 @@ public class FeedItem implements Serializable {
this.itemIdentifier = itemIdentifier;
this.autoDownloadEnabled = autoDownloadEnabled;
this.podcastIndexChapterUrl = podcastIndexChapterUrl;
if (transcriptUrl != null) {
this.podcastIndexTranscriptUrl = transcriptUrl;
this.podcastIndexTranscriptType = transcriptType;
}
}
/**
@ -162,6 +169,9 @@ public class FeedItem implements Serializable {
if (other.podcastIndexChapterUrl != null) {
podcastIndexChapterUrl = other.podcastIndexChapterUrl;
}
if (other.getPodcastIndexTranscriptUrl() != null) {
podcastIndexTranscriptUrl = other.podcastIndexTranscriptUrl;
}
}
public long getId() {
@ -413,6 +423,45 @@ public class FeedItem implements Serializable {
podcastIndexChapterUrl = url;
}
public void setPodcastIndexTranscriptUrl(String type, String url) {
updateTranscriptPreferredFormat(type, url);
}
public String getPodcastIndexTranscriptUrl() {
return podcastIndexTranscriptUrl;
}
public String getPodcastIndexTranscriptType() {
return podcastIndexTranscriptType;
}
public void updateTranscriptPreferredFormat(String type, String url) {
if (StringUtils.isEmpty(type) || StringUtils.isEmpty(url)) {
return;
}
String canonicalSrr = "application/srr";
String jsonType = "application/json";
switch (type) {
case "application/json":
podcastIndexTranscriptUrl = url;
podcastIndexTranscriptType = type;
break;
case "application/srr":
case "application/srt":
case "application/x-subrip":
if (podcastIndexTranscriptUrl == null || !podcastIndexTranscriptType.equals(jsonType)) {
podcastIndexTranscriptUrl = url;
podcastIndexTranscriptType = canonicalSrr;
}
break;
default:
System.out.println("Invalid format for transcript " + type);
break;
}
}
@NonNull
@Override
public String toString() {