aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-24 18:32:26 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-24 18:32:26 +0200
commit62f918559616138de1cc0ab8f5759f5d714e9287 (patch)
tree7c8886051590b8f0b0806633563fd120ebc6726f /plugins
parent591c78ff6b148ddd3c97ad48dce15ec697456fe5 (diff)
Youtube: load english subtitles when available
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Page.hpp8
-rw-r--r--plugins/Youtube.hpp2
2 files changed, 10 insertions, 0 deletions
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
index f793c65..e60c752 100644
--- a/plugins/Page.hpp
+++ b/plugins/Page.hpp
@@ -111,6 +111,11 @@ namespace QuickMedia {
const char* get_title() const override { return "Related videos"; }
};
+ struct SubtitleData {
+ std::string url;
+ std::string title;
+ };
+
class VideoPage : public Page {
public:
VideoPage(Program *program, std::string url) : Page(program), url(std::move(url)) {}
@@ -140,8 +145,11 @@ namespace QuickMedia {
virtual std::string get_audio_url(std::string &ext) { (void)ext; return ""; }
virtual std::string url_get_playable_url(const std::string &url) { return url; }
virtual bool video_should_be_skipped(const std::string &url) { (void)url; return false; }
+ // This needs to be called before the other functions are called
virtual PluginResult load(std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters) { (void)title; (void)channel_url; (void)chapters; return PluginResult::OK; }
virtual void mark_watched() {};
+ // Should not do any network request to not slow down video loading
+ virtual void get_subtitles(SubtitleData &subtitle_data) { (void)subtitle_data; }
protected:
std::string url;
};
diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp
index c3945de..e2bc2a4 100644
--- a/plugins/Youtube.hpp
+++ b/plugins/Youtube.hpp
@@ -153,6 +153,7 @@ namespace QuickMedia {
std::string get_audio_url(std::string &ext) override;
PluginResult load(std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters) override;
void mark_watched() override;
+ void get_subtitles(SubtitleData &subtitle_data) override;
private:
PluginResult parse_video_response(const Json::Value &json_root, std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters);
void parse_format(const Json::Value &format_json, bool is_adaptive);
@@ -163,6 +164,7 @@ namespace QuickMedia {
std::string livestream_url;
std::vector<YoutubeVideoFormat> video_formats;
std::vector<YoutubeAudioFormat> audio_formats;
+ std::map<std::string, SubtitleData> subtitle_urls_by_lang_code;
std::string playback_url;
std::string watchtime_url;