Add !yt YouTube title lookup command via oEmbed API. (0.41.0)
Added new !yt command (cmd_yt.h) that fetches the title and channel name of a YouTube video using the YouTube oEmbed API. The video URL is percent-encoded via a new yt_url_encode() helper before being passed as a query parameter. The JSON response is parsed for 'title' and 'author_name' fields using the existing json_find() helper, and the result is formatted as 'Title - Channel'. - New file: cmd_yt.h with yt_url_encode() and cmd_yt() command handler - CMakeLists.txt: added WITH_YT feature toggle (ON by default) - zynk.c: added conditional #include for cmd_yt.h - irc.h: added cmd_yt() dispatch in handle_privmsg() - cmd_help.h: added !yt <url> to the help listing - zynk.c: added doc comments to json_find() function - cmd_yt.h: added doc comments to yt_url_encode() and cmd_yt() - CHANGELOG.md: added 0.41.0 entry documenting all changes - README.md: updated feature summary, features list, feature toggles table, minimal build command, and IRC commands utilities table
This commit is contained in:
parent
084a41cfbd
commit
d59d4dc46c
7 changed files with 186 additions and 27 deletions
20
zynk.c
20
zynk.c
|
|
@ -644,6 +644,23 @@ int try_compile_and_restart(Session *s, const char *target) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* json_find - Locate a key in a flat JSON string and return a pointer to its value.
|
||||
*
|
||||
* Searches for the first occurrence of key in haystack using strstr(), then
|
||||
* skips past the key, any whitespace, an optional colon, more whitespace, and
|
||||
* any leading '[' or space characters to return a pointer to the value. This
|
||||
* is a simple helper for parsing flat JSON responses (e.g. from Yahoo Finance
|
||||
* or YouTube oEmbed APIs) without a full JSON parser. Not suitable for nested
|
||||
* or complex JSON structures.
|
||||
*
|
||||
* Parameters:
|
||||
* haystack - The JSON string to search (must be NUL-terminated).
|
||||
* key - The JSON key to find, including quotes (e.g. "\"title\":").
|
||||
*
|
||||
* Returns: A pointer into haystack at the start of the value, or NULL if the
|
||||
* key is not found.
|
||||
*/
|
||||
const char *json_find(const char *haystack, const char *key) {
|
||||
const char *p = strstr(haystack, key);
|
||||
if (!p) return NULL;
|
||||
|
|
@ -714,6 +731,9 @@ const char *json_find(const char *haystack, const char *key) {
|
|||
#ifdef HAS_CMD_RESTART
|
||||
#include "cmd_restart.h"
|
||||
#endif
|
||||
#ifdef HAS_CMD_YT
|
||||
#include "cmd_yt.h"
|
||||
#endif
|
||||
#ifdef HAS_CMD_GREETING_OR_CHAT
|
||||
#include "cmd_greeting_or_chat.h"
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue