Allow the user to get notified on new videos
This commit is contained in:
parent
6081b9e542
commit
1d06834848
10
README.md
10
README.md
|
@ -42,3 +42,13 @@ This tool is work in progress and some functions might not work (correctly).
|
|||
| extraHeaders | Extra HTTP headers to send to YouTube. This is a JSON array of objects containing `"key"` and `"value"`. Will be sent with each API requres. | `[]` | ✘ |
|
||||
| database | Path of channel/video database | $HOME/.local/share/yttui.db | ✘ |
|
||||
| watchCommand | Command executed to watch a video. `{{vid}}` will be replaced by the Id of the video to watch. | `["xdg-open", "https://youtube.com/watch?v={{vid}}"]` | ✘ |
|
||||
| notifications | Object describing notification settings | `{}` | ✘ |
|
||||
|
||||
#### Notifcation options
|
||||
The `notifications` entry can have the following sub-options:
|
||||
|
||||
|Option | Description | Default value | Required |
|
||||
|-------|-------------|---------------|--------- |
|
||||
| channelNewVideoCommand | Gets executed when refreshing a single channel and there is one new videos. `{{channelName}}` will be replaced with the name of updated channel, `{{title}}` with the title of the new video. | `[]` | ✘ |
|
||||
| channelNewVideosCommand | Gets executed when refreshing a single channel and there are multiple new videos. `{{channelName}}` will be replaced with the name of updated channel, `{{newVideos}}` with the number of new videos. | `[]` | ✘ |
|
||||
| channelsNewVideosCommand | Gets executed when refreshing multiple channels and there are new videos. `{{updatedChannels}}` will be replaced with the number of updated channels, `{{newVideos}}` with the number of new videos across all refreshed channels. | `[]` | ✘ |
|
||||
|
|
40
main.cpp
40
main.cpp
|
@ -329,15 +329,45 @@ bool run_command(const std::vector<std::string> &cmd, const std::vector<std::pai
|
|||
return rc == 0;
|
||||
}
|
||||
|
||||
std::vector<std::string> notify_channel_new_video_command;
|
||||
std::vector<std::string> notify_channel_new_videos_command;
|
||||
std::vector<std::string> notify_channels_new_videos_command;
|
||||
|
||||
void action_refresh_channel() {
|
||||
fetch_videos_for_channel(channels.at(selected_channel));
|
||||
Channel &ch = channels.at(selected_channel);
|
||||
const int new_videos = fetch_videos_for_channel(channels.at(selected_channel));
|
||||
if(new_videos == 0)
|
||||
return;
|
||||
if(new_videos == 1 && !notify_channel_new_video_command.empty()) {
|
||||
run_command(notify_channel_new_video_command, {
|
||||
{"{{channelName}}", ch.name},
|
||||
{"{{videoTitle}}", videos[ch.id].front().title},
|
||||
});
|
||||
} else if(notify_channel_new_videos_command.size()) {
|
||||
run_command(notify_channel_new_videos_command, {
|
||||
{"{{channelName}}", ch.name},
|
||||
{"{{newVideos}}", std::to_string(new_videos)}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void action_refresh_all_channels() {
|
||||
if(message_box("Refresh all channels?", ("Do you want to refresh all " + std::to_string(channels.size()) + " channels?").c_str(), Button::Yes | Button::No, Button::No) != Button::Yes)
|
||||
return;
|
||||
int updated_channels = 0;
|
||||
int new_videos = 0;
|
||||
for(Channel &channel: channels) {
|
||||
fetch_videos_for_channel(channel, true);
|
||||
const int count = fetch_videos_for_channel(channel, true);
|
||||
new_videos += count;
|
||||
if(count)
|
||||
updated_channels++;
|
||||
}
|
||||
if(updated_channels && new_videos && !notify_channels_new_videos_command.empty()) {
|
||||
run_command(notify_channels_new_videos_command, {
|
||||
{"{{updatedChannels}}", std::to_string(updated_channels)},
|
||||
{"{{newVideos}}", std::to_string(new_videos)}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -523,6 +553,12 @@ int main()
|
|||
database_filename = replace(config["database"], "$HOME", user_home);
|
||||
}
|
||||
config_get_string_list(watch_command, config, "watchCommand");
|
||||
if(config.contains("notifications") && config["notifications"].is_object()) {
|
||||
const json ¬ifications = config["notifications"];
|
||||
config_get_string_list(notify_channel_new_video_command, notifications, "channelNewVideoCommand");
|
||||
config_get_string_list(notify_channel_new_videos_command, notifications, "channelNewVideosCommand");
|
||||
config_get_string_list(notify_channels_new_videos_command, notifications, "channelsNewVideosCommand");
|
||||
}
|
||||
|
||||
db_init(database_filename);
|
||||
make_virtual_unwatched_channel();
|
||||
|
|
|
@ -4,5 +4,10 @@
|
|||
{"key": "x-extra", "value": "heder"}
|
||||
],
|
||||
"database": "$HOME/yttui.db",
|
||||
"watchCommand": ["xdg-open", "https://youtube.com/watch?v={{vid}}"]
|
||||
"watchCommand": ["xdg-open", "https://youtube.com/watch?v={{vid}}"],
|
||||
"notifications": {
|
||||
"channelNewVideoCommand": ["notify-send", "--app-name", "yttui", "New video from {{channelName}}", "{{videoTitle}}"],
|
||||
"channelNewVideosCommand": ["notify-send", "--app-name", "yttui", "New videos from {{channelName}}", "There are {{newVideos}} new videos."],
|
||||
"channelsNewVideosCommand": ["notify-send", "--app-name", "yttui", "New videos from multiple channels", "There are {{newVideos}} new videos from {{updatedChannels}} channels."]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue