workaround for youtube channels

This commit is contained in:
ildar-shaimordanov
2019-03-12 02:13:41 +04:00
parent 689bc19296
commit c9c71d8582

View File

@@ -2,6 +2,7 @@ package com.commafeed.backend.feed;
import java.io.IOException;
import java.util.Date;
import java.util.regex.*;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -96,8 +97,24 @@ public class FeedFetcher {
foundUrl = atom.get(0).attr("abs:href");
} else if (!rss.isEmpty()) {
foundUrl = rss.get(0).attr("abs:href");
} else {
foundUrl = extractYoutubeFeedUrl(baseUri);
}
}
return foundUrl;
}
/*
* Workaround for Youtube channels:
* convert the channel URL to the valid feed URL
* https://www.youtube.com/channel/CHANNEL_ID
* https://www.youtube.com/feeds/videos.xml?channel_id=CHANNEL_ID
*/
private String extractYoutubeFeedUrl(String url) {
Pattern regexp = Pattern.compile("(.*\\byoutube\\.com)\\/channel\\/([^\\/]+)", Pattern.CASE_INSENSITIVE);
Matcher matcher = regexp.matcher(url);
if ( matcher.find() ) {
return matcher.group(1) + "/feeds/videos.xml?channel_id=" + matcher.group(2);
}
}
}