Files
cnuktube/c.c
pance lalkov 73521d3cd5 Initial commit
2023-12-22 19:05:56 +01:00

1400 lines
54 KiB
C

/*
stuff i use:
nuklear gui library
glfw
next_bro font by khurasan
dependancies:
glfw?
yt-dlp
mpv
---RSS
done :)
---PORTABILITY
TOD ohh god
---OPTIMIZATION
TOD -extra- maybe somehow start caching all NEW videos with mpv/yt-dlp so that when you end up mpving them they load faster?
TOD -extra- remake all bash scripts as c functions
TODO -extra- make hearts not take up resources if fallen out of the screen
---KEYBINDINGS
TODO c (inside of i) to display comments
TODO r to remove a channel from rss/channels.txt && update? (text field)
maybe curl -s (the first video from that channel) | curl_get_rss_link then remove that line with sed
TODO i to display info
TOD -extra- have a seperate keyboard cheatsheet for each diffrent drawer
---PLAYING OR DOWNLOADING
TOD --NUKLEAR-- confirmation that video will soon start playing
TOD --NUKLEAR-- when you leave fullscreen it places the video on a box at the side and aloows you to continue using the program
TOD --YT-DLP-- saving position (yt-dlp save-position-on-quit? / write-watch-later-config?)
TOD --YT-DLP-- yt-dlp cache?
---SUBSCRIPTIONS
done :)
TODO-extra- mark as streams/shorts
TODO-extra- remove same stream names
TODO-extra- ability to mark specific channels as "you care about theyre new videos" meaning dont show theyre channel as golden even if they have new videos
---SEARCH
TODO if(selected_search_link == 0){ somehow have the input box selected and allow to type }
TODO i believe it crases if it get a title with foreign chars
---START
TODO explain the reason this program exists
done :)
---SETTINGS
done :)
---HISTORY
done :)
---BOOKMARKS
done :)
*/
#include <GL/glew.h>
#include <time.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <signal.h>
#include <curl/curl.h>
// for the text input?
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <math.h>
#include <assert.h>
#include <limits.h>
#include <GLFW/glfw3.h>
#define MAX_VERTEX_BUFFER 512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#define NK_GLFW_GL3_IMPLEMENTATION
#define NK_KEYSTATE_BASED_INPUT
#define MORE_LINES 1024
#define MORE_CHARS 1024
#include "./base_includes/nuklear.h"
#include "./base_includes/nuklear_glfw_gl3.h"
#include "./base_includes/style.c"
//FUNCTIONS
char** reading_cfg(){
FILE *file = fopen("./base_includes/settings.cfg", "r");
if(file == NULL){fprintf(stderr, "Error opening settings.cfg file.\n"); exit(1);}
char **temp = malloc(sizeof(char*) * 1);
for(int i =0 ; i < 1; ++i){
temp[i] = malloc(sizeof(char) * 100);
}
for(int i = 0; i < 1; i++){
fgets(temp[i], 100, file);
}
fclose(file);
return temp;
}
int get_number_of_histories(){
DIR * directory;
struct dirent * entry;
directory = opendir("./history");
if(directory == NULL){fprintf(stderr, "Could not find history directory"); exit(EXIT_FAILURE);}
int i = 0;
while((entry = readdir(directory)) != NULL){
if(entry->d_type == DT_REG){
i++;
}
}
free(entry);
closedir(directory);
return i;
}
char** reading_histories(int number_of_histories_func){
DIR * directory;
struct dirent * entry;
directory = opendir("./history");
if(directory == NULL){fprintf(stderr, "Could not find history directory"); exit(EXIT_FAILURE);}
char **temp = malloc(sizeof(char*)*(number_of_histories_func));
int i = 0;
while((entry = readdir(directory)) != NULL) {
if(entry->d_type == DT_REG){
int n = strlen(entry->d_name);
temp[i] = (char *) malloc(sizeof(char) * n+1);// +1 for new line char? probably dont need it
strncpy(temp[i], entry->d_name, n);
temp[i][n] = '\0';
i++;
}
}
int order[number_of_histories_func];
for(int i = 0; i < number_of_histories_func; i++){
if(temp[i][1] == 32){
order[i] = (temp[i][0])-48;
}else if(temp[i][2] == 32){
order[i] = (temp[i][1]-48) + ((temp[i][0]-48) * 10);
}else if(temp[i][3] == 32){
order[i] = (temp[i][2]-48) + ((temp[i][1]-48) * 10) + ((temp[i][0]-48) * 100);
}
}
char **temp_ordered = malloc(sizeof(char*)*(number_of_histories_func));
int count = number_of_histories_func;
for(int i = 0; i < number_of_histories_func; i++){
for(int j = 0; j < number_of_histories_func; j++){
if(order[j] == count){
int n = strlen(temp[j]);
temp_ordered[i] = (char *) malloc(sizeof(char) * n+1);
strncpy(temp_ordered[i], temp[j], n);
temp_ordered[i][n] = '\0';
}
}
count--;
}
//free(count);
for(int i = 0; i < number_of_histories_func; i++){
//free(order[i]);
free(temp[i]);
}
//free(order);
free(temp);
free(entry);
//free(i);
closedir(directory);
printf("histories loaded\n");
return temp_ordered;
}
int get_number_of_bookmarks(){
DIR * directory;
struct dirent * entry;
directory = opendir("./bookmarks");
if(directory == NULL){fprintf(stderr, "Could not find bookmarks directory"); exit(EXIT_FAILURE);}
int i = 0;
while((entry = readdir(directory)) != NULL){
if(entry->d_type == DT_REG){
i++;
}
}
free(entry);
closedir(directory);
return i;
}
char** reading_bookmarks(int number_of_bookmarks_func){
DIR * directory;
struct dirent * entry;
directory = opendir("./bookmarks");
if(directory == NULL){fprintf(stderr, "Could not find bookmarks directory"); exit(EXIT_FAILURE);}
char **temp = malloc(sizeof(char*)*(number_of_bookmarks_func));
int i = 0;
while((entry = readdir(directory)) != NULL) {
if(entry->d_type == DT_REG){
int n = strlen(entry->d_name);
temp[i] = (char *) malloc(sizeof(char) * n+1);
strncpy(temp[i], entry->d_name, n);
temp[i][n] = '\0';
i++;
}
}
int order[number_of_bookmarks_func];
for(int i = 0; i < number_of_bookmarks_func; i++){
if(temp[i][1] == 32){
order[i] = (temp[i][0])-48;
}else if(temp[i][2] == 32){
order[i] = (temp[i][1]-48) + (temp[i][0] * 10);
}else if(temp[i][3] == 32){
order[i] = (temp[i][2]-48) + (temp[i][1] * 10) + (temp[i][0] * 100);
}
}
char **temp_ordered = malloc(sizeof(char*)*(number_of_bookmarks_func));
for(int i = 0; i < number_of_bookmarks_func; i++){
for(int j = 0; j < number_of_bookmarks_func; j++){
if(order[j] == i+1){
int n = strlen(temp[j]);
temp_ordered[i] = (char *) malloc(sizeof(char) * n+1);
strncpy(temp_ordered[i], temp[j], n);
temp_ordered[i][n] = '\0';
}
}
}
for(int i = 0; i < number_of_bookmarks_func; i++){
//free(order[i]);
free(temp[i]);
}
//free(order);
free(temp);
free(entry);
//free(i);
closedir(directory);
printf("bookmarks loaded\n");
return temp_ordered;
}
char** reading_info(){
FILE *info_file = fopen("./info/info.info", "r");
if(info_file == NULL){fprintf(stderr, "Error opening file.\n"); exit(1);}
char **info = malloc(sizeof(char*) * 9);
for(int i =0 ; i < 9; ++i){
info[i] = malloc(sizeof(char) * 100);
}
for(int i = 0; i < 9; i++){
fgets(info[i], 100, info_file);
}
fclose(info_file);
return info;
}
char** reading_description(int* description_number_of_lines_func){
FILE *file = fopen("./info/description.description", "r");
if(file == NULL){fprintf(stderr, "Error opening file.\n");exit(1);}
char **lines;
lines = malloc(sizeof(char *) * MORE_LINES);
size_t total_lines = 0;
size_t total_chars = 0;
char c;
do{
c = fgetc(file);
if(ferror(file)){fprintf(stderr, "Error reading from file.\n");exit(1);}
if(feof(file)){
if(total_chars != 0){
lines[total_lines] = realloc(lines[total_lines], total_chars + 1);
lines[total_lines][total_chars] = '\0';
total_lines++;
}
break;
}
if(total_chars == 0)
lines[total_lines] = malloc(MORE_CHARS);
lines[total_lines][total_chars] = c;
total_chars++;
if(c == '\n'){
lines[total_lines] = realloc(lines[total_lines], total_chars + 1 );
lines[total_lines][total_chars] = '\0';
total_lines++;
total_chars = 0;
if(total_lines % MORE_LINES == 0){
size_t new_size = total_lines + MORE_LINES;
lines = realloc(lines, sizeof(char *) * new_size);
}
}else if(total_chars % MORE_CHARS == 0){
size_t new_size = total_chars + MORE_CHARS;
lines[total_lines] =
realloc(lines[total_lines], new_size);
}
}while(1);
lines = realloc(lines, sizeof(char *) * total_lines);
fclose(file);
*description_number_of_lines_func = total_lines;
return lines;
}
char** reading_feeds(int *link_count_func, char* channel_func){
char feeds_path[120];
sprintf(feeds_path, "./rss/feeds/%s", channel_func);
FILE *file = fopen(feeds_path, "r");
if(file == NULL){fprintf(stderr, "Error opening file.\n");exit(1);}
char **lines;
lines = malloc(sizeof(char *) * MORE_LINES);
size_t total_lines = 0;
size_t total_chars = 0;
char c;
do{
c = fgetc(file);
if(ferror(file)){fprintf(stderr, "Error reading from file.\n");exit(1);}
if(feof(file)){
if(total_chars != 0){
lines[total_lines] = realloc(lines[total_lines], total_chars + 1);
lines[total_lines][total_chars] = '\0';
total_lines++;
}
break;
}
if(total_chars == 0)
lines[total_lines] = malloc(MORE_CHARS);
lines[total_lines][total_chars] = c;
total_chars++;
if(c == '\n'){
lines[total_lines] = realloc(lines[total_lines], total_chars + 1 );
lines[total_lines][total_chars] = '\0';
total_lines++;
total_chars = 0;
if(total_lines % MORE_LINES == 0){
size_t new_size = total_lines + MORE_LINES;
lines = realloc(lines, sizeof(char *) * new_size);
}
}else if(total_chars % MORE_CHARS == 0){
size_t new_size = total_chars + MORE_CHARS;
lines[total_lines] =
realloc(lines[total_lines], new_size);
}
}while(1);
lines = realloc(lines, sizeof(char *) * total_lines);
fclose(file);
*link_count_func = total_lines;
return lines;
}
static void text_input(GLFWwindow *win, unsigned int codepoint){
nk_input_unicode((struct nk_context*)glfwGetWindowUserPointer(win), codepoint);
}
// ??? what are the following two?
static void error_callback(int e, const char *d)
{printf("Error %d: %s\n", e, d);}
typedef struct{
char *string;
size_t size;
} Response;
size_t write_chunk(void *data, size_t size, size_t nmemb, void *userdata){
size_t real_size = size * nmemb;
Response *response = (Response *) userdata;
char *ptr = realloc(response->string, response->size + real_size + 1);
if (ptr == NULL){
return CURL_WRITEFUNC_ERROR;
}
response->string = ptr;
memcpy(&(response->string[response->size]), data, real_size);
response->size += real_size;
response->string[response->size] = 0; // '\0';
return real_size;
}
void add_to_channels(char* url_func){
CURL *curl;
CURLcode result;
curl = curl_easy_init();
if(curl == NULL){fprintf(stderr, "HTTP request failed\n");exit(EXIT_FAILURE);}
Response response;
response.string = malloc(1);
response.size = 0;
char full_url_for_curl[120];
sprintf(full_url_for_curl, "https://www.youtube.com/%s/videos", url_func);
curl_easy_setopt(curl, CURLOPT_URL, full_url_for_curl);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_chunk);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &response);
result = curl_easy_perform(curl);
if(result != CURLE_OK){fprintf(stderr, "Error: %s\n", curl_easy_strerror(result));exit(EXIT_FAILURE);}
if(strlen(response.string) < 5000){fprintf(stderr, "That YouTube Channel does not exist\n");exit(EXIT_FAILURE);}
int start_of_rss_link = 0;
int end_of_rss_link = 0;
for(int i = strlen(response.string); i != 0; i--){
if(response.string[i] == 102){
if(response.string[i+1] == 101){
if(response.string[i+2] == 101){
if(response.string[i+3] == 100){
if(response.string[i+4] == 115){
if(response.string[i+5] == 47){
start_of_rss_link = i-24;
end_of_rss_link = i+51;
char link[80];
int k = 0;
for(int j = start_of_rss_link; j <= end_of_rss_link; j++){
link[k] = response.string[j];
k++;
if(j == end_of_rss_link){
link[k] = '\0';
}
}
FILE *f = fopen ("./rss/channels.txt", "a");
fprintf(f, "%s\n", link);
fclose(f);
break;
}
}
}
}
}
}
}
curl_easy_cleanup(curl);
free(response.string);
}
char** searching(char* search_input_func){
CURL *curl;
CURLcode result;
curl = curl_easy_init();
if(curl == NULL)
{fprintf(stderr, "HTTP request failed\n"); exit(EXIT_FAILURE);}
Response response;
response.string = malloc(1);
response.size = 0;
for(size_t i = 0; i < strlen(search_input_func); i++){
if(search_input_func[i] == 32){
search_input_func[i] = 43;
}
}
char url[120];
sprintf(url, "https://www.youtube.com/results?search_query=%s", search_input_func);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_chunk);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &response);
// ??? wtf is result
result = curl_easy_perform(curl);
if(result != CURLE_OK)
{fprintf(stderr, "Error: %s\n", curl_easy_strerror(result)); exit(1);}
char **search_links_and_titles = malloc(sizeof(char*) * 10);
int while_i = 20000;
for(int i = 0; i < 10; i++){
search_links_and_titles[i] = malloc(sizeof(char) * 100);
while(1){
if(response.string[while_i] == 118 && response.string[while_i+1] == 105 && response.string[while_i+2] == 100 && response.string[while_i+3] == 101 && response.string[while_i+4] == 111 && response.string[while_i+5] == 82 && response.string[while_i+6] == 101 && response.string[while_i+7] == 110 && response.string[while_i+8] == 100 && response.string[while_i+9] == 101 && response.string[while_i+10] == 114 && response.string[while_i+11] == 101 && response.string[while_i+12] == 114 && response.string[while_i+13] == 34 && response.string[while_i+14] == 58 && response.string[while_i+15] == 123 && response.string[while_i+16] == 34 && response.string[while_i+17] == 118 && response.string[while_i+18] == 105 && response.string[while_i+19] == 100 && response.string[while_i+20] == 101 && response.string[while_i+21] == 111 && response.string[while_i+22] == 73 && response.string[while_i+23] == 100){
for(int j = 0; j < 11; j++){
search_links_and_titles[i][j] = response.string[while_i+27+j];
}
search_links_and_titles[i][11] = 32;
search_links_and_titles[i][12] = 32;
search_links_and_titles[i][13] = 32;
search_links_and_titles[i][14] = 32;
search_links_and_titles[i][15] = '\0';
// at this point sear...tles[i][0-10 are the urlID, 11-14 are spaces]
//for now 15 is \0
// so 15 - (the end) should be the title
while_i++;
int new_search_i = while_i;
while(1){
if(response.string[new_search_i] == 34 && response.string[new_search_i+1] == 116 && response.string[new_search_i+2] == 105 && response.string[new_search_i+3] == 116 && response.string[new_search_i+4] == 108 && response.string[new_search_i+5] == 101 && response.string[new_search_i+6] == 34 && response.string[new_search_i+7] == 58 && response.string[new_search_i+8] == 123 && response.string[new_search_i+9] == 34 && response.string[new_search_i+10] == 114 && response.string[new_search_i+11] == 117 && response.string[new_search_i+12] == 110 && response.string[new_search_i+13] == 115 && response.string[new_search_i+14] == 34 && response.string[new_search_i+15] == 58 && response.string[new_search_i+16] == 91 && response.string[new_search_i+17] == 123 && response.string[new_search_i+18] == 34 && response.string[new_search_i+19] == 116 && response.string[new_search_i+20] == 101 && response.string[new_search_i+21] == 120 && response.string[new_search_i+22] == 116 && response.string[new_search_i+23] == 34 && response.string[new_search_i+24] == 58 && response.string[new_search_i+25] == 34){
for(int j = 0; j < 100; j++){
if(response.string[26+j+new_search_i] == 34){
search_links_and_titles[15+j] = '\0';
break; // out of for j<100
}
if(response.string[new_search_i+26+j] > 47 && response.string[new_search_i+26+j] !=58 && response.string[new_search_i+26+j] !=59 && response.string[new_search_i+26+j] !=60 && response.string[new_search_i+26+j] !=61 && response.string[new_search_i+26+j] !=62 && response.string[new_search_i+26+j] !=63 && response.string[new_search_i+26+j] !=64 && response.string[new_search_i+26+j] !=91 && response.string[new_search_i+26+j] !=92 && response.string[new_search_i+26+j] !=93 && response.string[new_search_i+26+j] !=94 && response.string[new_search_i+26+j] !=95 && response.string[new_search_i+26+j] !=96 && response.string[new_search_i+26+j] < 123){
search_links_and_titles[i][15+j] = response.string[26+j+new_search_i];
}else{
search_links_and_titles[i][15+j] = 32;
}
}//for100
break;
}//if "title":{"runs":[{"text":"
new_search_i++;
}
break;
}//if == videoRenderer":{"videoId
while_i++;
}//while
}// for i 0<20
for(int i = 0; i < 10; i++){
printf("%d %s\n", i, search_links_and_titles[i]);
}
curl_easy_cleanup(curl);
free(response.string);
return search_links_and_titles;
}
int keyboard_events(int* currently_playing_from_search_func, int do_we_have_search_results_func, int *selected_settings_theme_func, int *selected_settings_func, int *open_info_window_func, int *open_add_to_channels_input_box_func, char* add_to_channels_input_func, int *searched_func, int *selected_search_link_func, int number_of_bookmarks_func, int number_of_histories_func, int *selected_history_func, int *selected_bookmark_func, char *bookmarks_func, char *histories_func,char *subscription_channels_func, int channel_link_amount_func, int number_of_channels_func, int *selected_subscription_channel_func, int *selected_subscriptions_link_func, int *selected_drawer_func, struct nk_input *in, int *update_or_not_func){
if(in->keyboard.keys[NK_KEY_U].down && in->keyboard.keys[NK_KEY_U].clicked && *selected_search_link_func != 0 && *open_add_to_channels_input_box_func == 0 && *open_info_window_func == 0){
*update_or_not_func = 1;
}
// DRAWERS
if(in->keyboard.keys[NK_KEY_Q].down && in->keyboard.keys[NK_KEY_Q].clicked && *selected_search_link_func != 0 && *open_add_to_channels_input_box_func == 0 && *open_info_window_func == 0){
return 6969;
}
if(*open_info_window_func == 1 && in->keyboard.keys[NK_KEY_Q].down && in->keyboard.keys[NK_KEY_Q].clicked){
*open_info_window_func = 0;
}
if(*selected_subscriptions_link_func == -1 && *selected_search_link_func != 0 && *selected_settings_func == 0){
if(in->keyboard.keys[NK_KEY_LEFT].down && in->keyboard.keys[NK_KEY_LEFT].clicked){
if(*selected_drawer_func != 1){
*selected_drawer_func = *selected_drawer_func - 1;
}
}
if(in->keyboard.keys[NK_KEY_RIGHT].down && in->keyboard.keys[NK_KEY_RIGHT].clicked){
if(*selected_drawer_func != 7){
*selected_drawer_func = *selected_drawer_func + 1;
}
}
if(*selected_drawer_func == 7 && in->keyboard.keys[NK_KEY_ENTER].down){
return 6969;
}
}
if(*selected_drawer_func == 1){
// SETTINGS MOVEMENTS
if(*selected_settings_func == 1){
if(in->keyboard.keys[NK_KEY_LEFT].down && in->keyboard.keys[NK_KEY_LEFT].clicked){
if(*selected_settings_theme_func != 0){
*selected_settings_theme_func = *selected_settings_theme_func - 1;
}
}
if(in->keyboard.keys[NK_KEY_RIGHT].down && in->keyboard.keys[NK_KEY_RIGHT].clicked){
if(*selected_settings_theme_func != 2){
*selected_settings_theme_func = *selected_settings_theme_func + 1;
}
}
if(in->keyboard.keys[NK_KEY_ENTER].down && in->keyboard.keys[NK_KEY_ENTER].clicked && *selected_settings_theme_func == 1){
system("./shells/change_theme CNUK");
}
if(in->keyboard.keys[NK_KEY_ENTER].down && in->keyboard.keys[NK_KEY_ENTER].clicked && *selected_settings_theme_func == 2){
system("./shells/change_theme MOON");
}
}
if(in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked){
if(*selected_settings_func != 0)
*selected_settings_func = *selected_settings_func - 1;
}
if(in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked){
if(*selected_settings_func != 1)
*selected_settings_func = *selected_settings_func + 1;
}
}//if drawer 1
//SUBSCRIPTIONS - KEYBOARD EVENTS
if(*selected_drawer_func == 2){
//ADD TO CHANNELS
if(in->keyboard.keys[NK_KEY_A].down && in->keyboard.keys[NK_KEY_A].clicked){
*open_add_to_channels_input_box_func = 1;
}
if(*open_add_to_channels_input_box_func == 1 && in->keyboard.keys[NK_KEY_ENTER].down && in->keyboard.keys[NK_KEY_ENTER].clicked){
add_to_channels(add_to_channels_input_func);
*open_add_to_channels_input_box_func = 0;
}
if(*open_add_to_channels_input_box_func == 1 && in->keyboard.keys[NK_KEY_Q].down && in->keyboard.keys[NK_KEY_Q].clicked){
*open_add_to_channels_input_box_func = 0;
}
// PLAYING
if(in->keyboard.keys[NK_KEY_ENTER].down && in->keyboard.keys[NK_KEY_ENTER].clicked && *selected_subscriptions_link_func > 0 && *open_add_to_channels_input_box_func == 0){
char do_it[150];
sprintf(do_it, "./shells/play_from_subscriptions \"%s\" %d", subscription_channels_func, *selected_subscriptions_link_func);
system(do_it);
}
// DOWNLOADING
if(in->keyboard.keys[NK_KEY_D].down && in->keyboard.keys[NK_KEY_D].clicked && *selected_subscriptions_link_func > 0 && *open_add_to_channels_input_box_func == 0){
char do_it[150];
sprintf(do_it, "./shells/download_from_subscriptions \"%s\" %d", subscription_channels_func, *selected_subscriptions_link_func);
system(do_it);
}
// BOOKMARK
if(in->keyboard.keys[NK_KEY_B].down && in->keyboard.keys[NK_KEY_B].clicked && *selected_subscriptions_link_func > 0 && *open_add_to_channels_input_box_func == 0){
char do_it[150];
sprintf(do_it, "./shells/yt_dlp_data/add_to_bookmarks_from_subscriptions \"%s\" %d", subscription_channels_func, *selected_subscriptions_link_func);
system(do_it);
}
// MARKING AS OLD
if(in->keyboard.keys[NK_KEY_O].down && in->keyboard.keys[NK_KEY_O].clicked && *selected_subscriptions_link_func > 0 && *open_add_to_channels_input_box_func == 0){
char do_it[150];
sprintf(do_it, "./shells/mark_as_old \"%s\" %d", subscription_channels_func, *selected_subscriptions_link_func);
system(do_it);
}
// INFO
if(in->keyboard.keys[NK_KEY_I].down && in->keyboard.keys[NK_KEY_I].clicked && *selected_subscriptions_link_func > 0 && *open_add_to_channels_input_box_func == 0){
char do_it[150];
sprintf(do_it, "./shells/get_info_from_subscriptions \"%s\" %d", subscription_channels_func, *selected_subscriptions_link_func);
system(do_it);
*open_info_window_func = 1;
}
// SUBSCRIPTION CHANNEL LEFT AND RIGHT
if(in->keyboard.keys[NK_KEY_LEFT].down && in->keyboard.keys[NK_KEY_LEFT].clicked && *open_add_to_channels_input_box_func == 0){
if(*selected_subscriptions_link_func == 0){
if(*selected_subscription_channel_func != 0){
*selected_subscription_channel_func = *selected_subscription_channel_func - 1;
}
}else if(*selected_subscriptions_link_func > 0){
*selected_drawer_func = *selected_drawer_func - 1;
}
}
if(in->keyboard.keys[NK_KEY_RIGHT].down && in->keyboard.keys[NK_KEY_RIGHT].clicked && *open_add_to_channels_input_box_func == 0){
if(*selected_subscriptions_link_func == 0){
if(*selected_subscription_channel_func != number_of_channels_func-1){
*selected_subscription_channel_func = *selected_subscription_channel_func + 1;
}
}else if(*selected_subscriptions_link_func > 0){
*selected_drawer_func = *selected_drawer_func + 1;
}
}
// SUBSCRIPTIONS LINKS UP AND DOWN
if(in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked && *open_add_to_channels_input_box_func == 0){
if(*selected_subscriptions_link_func != -1)
*selected_subscriptions_link_func = *selected_subscriptions_link_func - 1;
}
if(in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked && *open_add_to_channels_input_box_func == 0){
if(*selected_subscriptions_link_func != channel_link_amount_func)
*selected_subscriptions_link_func = *selected_subscriptions_link_func + 1;
}
}//if dwarer 2
//SEARCH
if(*selected_drawer_func == 3){
if(*selected_search_link_func == 0){
if(in->keyboard.keys[NK_KEY_ENTER].down && in->keyboard.keys[NK_KEY_ENTER].clicked){
*searched_func = 1;
}
}
if(*selected_search_link_func > 0){
// PLAYING
if(in->keyboard.keys[NK_KEY_ENTER].down && in->keyboard.keys[NK_KEY_ENTER].clicked){
*currently_playing_from_search_func = 1;
}
// // DOWNLOADING
// if(in->keyboard.keys[NK_KEY_D].down && in->keyboard.keys[NK_KEY_D].clicked){
// char do_it[150];
// sprintf(do_it, "./shells/download_from_history \"%s\"", selected_search_link_as_link_func);
// system(do_it);
// }
// // INFO
// if(in->keyboard.keys[NK_KEY_I].down && in->keyboard.keys[NK_KEY_I].clicked){
// char do_it[150];
// sprintf(do_it, "./shells/get_info_from_history \"%s\"", selected_search_link_as_link_func);
// system(do_it);
// *open_info_window_func = 1;
// }
}
// SEARCH LINKS UP AND DOWN
if(do_we_have_search_results_func == 0){
if(in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked && *selected_search_link_func != -1){
*selected_search_link_func = *selected_search_link_func - 1;
}
if(in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked && *selected_search_link_func != 0){
*selected_search_link_func = *selected_search_link_func + 1;
}
}else if(do_we_have_search_results_func == 1){
if(in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked && *selected_search_link_func != -1){
*selected_search_link_func = *selected_search_link_func - 1;
}
if(in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked && *selected_search_link_func != 10){
*selected_search_link_func = *selected_search_link_func + 1;
}
}
}//if dwarer 3
//HISTORY
if(*selected_drawer_func == 5){
// PLAYING
if(in->keyboard.keys[NK_KEY_ENTER].down && in->keyboard.keys[NK_KEY_ENTER].clicked && *selected_history_func > -1){
char do_it[150];
sprintf(do_it, "./shells/play_from_history \"%s\"", histories_func);
system(do_it);
}
// DOWNLOADING
if(in->keyboard.keys[NK_KEY_D].down && in->keyboard.keys[NK_KEY_D].clicked && *selected_history_func > -1){
char do_it[150];
sprintf(do_it, "./shells/download_from_history \"%s\"", histories_func);
system(do_it);
}
// INFO
if(in->keyboard.keys[NK_KEY_I].down && in->keyboard.keys[NK_KEY_I].clicked && *selected_history_func > -1){
char do_it[150];
sprintf(do_it, "./shells/get_info_from_history \"%s\"", histories_func);
system(do_it);
*open_info_window_func = 1;
}
// HISTORIES LINKS UP AND DOWN
if(in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked){
if(*selected_history_func != -1){
*selected_history_func = *selected_history_func - 1;
}
}
if(in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked){
if(*selected_history_func != number_of_histories_func-1){
*selected_history_func = *selected_history_func + 1;
}
}
}//if dwarer 5
//BOOKMARKS
if(*selected_drawer_func == 6){
// PLAYING
if(in->keyboard.keys[NK_KEY_ENTER].down && in->keyboard.keys[NK_KEY_ENTER].clicked && *selected_bookmark_func > -1){
char do_it[150];
sprintf(do_it, "./shells/play_from_bookmarks \"%s\"", bookmarks_func);
system(do_it);
}
// DOWNLOADING
if(in->keyboard.keys[NK_KEY_D].down && in->keyboard.keys[NK_KEY_D].clicked && *selected_bookmark_func > -1){
char do_it[150];
sprintf(do_it, "./shells/download_from_bookmarks \"%s\"", bookmarks_func);
system(do_it);
}
// REMOVE FROM BOOKMARKS
if(in->keyboard.keys[NK_KEY_R].down && in->keyboard.keys[NK_KEY_R].clicked && *selected_bookmark_func > -1){
char do_it[150];
sprintf(do_it, "./shells/remove_from_bookmarks \"%s\"", bookmarks_func);
system(do_it);
}
// INFO
if(in->keyboard.keys[NK_KEY_I].down && in->keyboard.keys[NK_KEY_I].clicked && *selected_bookmark_func > -1){
char do_it[150];
sprintf(do_it, "./shells/get_info_from_bookmarks \"%s\"", bookmarks_func);
system(do_it);
*open_info_window_func = 1;
}
// HISTORIES LINKS UP AND DOWN
if(in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked){
if(*selected_bookmark_func != -1){
*selected_bookmark_func = *selected_bookmark_func - 1;
}
}
if(in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked){
if(*selected_bookmark_func != number_of_bookmarks_func-1){
*selected_bookmark_func = *selected_bookmark_func + 1;
}
}
}//if dwarer 6
return *selected_drawer_func;
}
void play_from_search(char* searches_func){
char do_it[150];
sprintf(do_it, "./shells/play_from_search \"%s\"", searches_func);
system(do_it);
}
// // DOWNLOADING
// if(in->keyboard.keys[NK_KEY_D].down && in->keyboard.keys[NK_KEY_D].clicked){
// char do_it[150];
// sprintf(do_it, "./shells/download_from_history \"%s\"", selected_search_link_as_link_func);
// system(do_it);
// }
// // INFO
// if(in->keyboard.keys[NK_KEY_I].down && in->keyboard.keys[NK_KEY_I].clicked){
// char do_it[150];
// sprintf(do_it, "./shells/get_info_from_history \"%s\"", selected_search_link_as_link_func);
// system(do_it);
// *open_info_window_func = 1;
// }
void mouse_event(struct nk_rect bounds, struct nk_input *in){
if((in->mouse.buttons[NK_BUTTON_LEFT].down && in->mouse.buttons[NK_BUTTON_LEFT].clicked) && (in->mouse.pos.x > bounds.x && in->mouse.pos.x < bounds.w) && (in->mouse.pos.y > bounds.y && in->mouse.pos.y < bounds.h)){
printf("you clicked x=%f , y=%f\n" , in->mouse.pos.x, in->mouse.pos.y);
}
}
int main(void){
int rss_fork = fork();
if(rss_fork == 0){
execl("./rss/cnuk_rss_update", "cnuk_rss_update", (char*) 0);
}else{
// TODO make these dynamicly be set to current terminal width and height
int win_width = 1920;
int win_height = 1080;
// GLFW
struct nk_glfw glfw = {0};
static GLFWwindow *win;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
{fprintf(stdout, "[GFLW] failed to init!\n");exit(1);}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
win = glfwCreateWindow(win_width, win_height, "c_nuklear_youtube_viewer", NULL, NULL);
glfwMakeContextCurrent(win);
glfwSetCharCallback(win, text_input);
// GLEW
glewExperimental = 1;
if (glewInit() != GLEW_OK)
{fprintf(stderr, "Failed to setup GLEW\n");exit(1);}
// CONTEXT
struct nk_context *ctx_search = nk_glfw3_init(&glfw, win, NK_GLFW3_INSTALL_CALLBACKS);
{struct nk_font_atlas *atlas;
nk_glfw3_font_stash_begin(&glfw, &atlas);
struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "./base_includes/next_bro.ttf", 32, 0);
nk_glfw3_font_stash_end(&glfw);
nk_style_set_font(ctx_search, &droid->handle);
}
struct nk_context *ctx = nk_glfw3_init(&glfw, win, NK_GLFW3_INSTALL_CALLBACKS);
{struct nk_font_atlas *atlas;
nk_glfw3_font_stash_begin(&glfw, &atlas);
struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "./base_includes/next_bro.ttf", 32, 0);
nk_glfw3_font_stash_end(&glfw);
nk_style_set_font(ctx, &droid->handle);
}
// MISC
int rng[2];
int rng_direction[2];
srand ( time(NULL) );
for(int i = 0; i < 2; i++){
rng[i] = rand() % (1920-100);
}
for(int i = 0; i < 2; i++){
rng_direction[i] = rand() % 2;
}
int raise = 1;
float direction = 0;
struct nk_rect space;
int cfg_theme = 0;
int selected_settings = 0;
int selected_settings_theme = 0;
int selected_drawer = 4;
int selected_subscriptions_link = -1;
int selected_subscription_channel = 0;
int selected_history = -1;
int selected_bookmark = -1;
int selected_search_link = -1;
int open_add_to_channels_input_box = 0;
static char add_to_channels_input[255];
static int add_to_channels_input_length;
static char text[255];
static int text_length;
int update_or_not = 1;
int searched = 0;
int open_info_window = 0;
char **info;
char **description;
int number_of_description_lines = 0;
int do_we_have_search_results = 0;
char **searches;
char **cfg = reading_cfg();
int currently_playing_from_search = 0;
int number_of_bookmarks = get_number_of_bookmarks();
int number_of_histories = get_number_of_histories();
char **bookmarks = reading_bookmarks(number_of_bookmarks);
char **histories = reading_histories(number_of_histories);
// GUI WHILE
while(!glfwWindowShouldClose(win)){
cfg = reading_cfg();
if(strstr(cfg[0], "theme = MOON") != NULL){
set_style(ctx, THEME_MOON);
set_style(ctx_search, THEME_MOON);
cfg_theme = 2;
}else{
set_style(ctx, THEME_PERSONAL_ORANGE);
set_style(ctx_search, THEME_PERSONAL_ORANGE);
cfg_theme = 1;
}
if(update_or_not == 1){
for(int i = 0; i < number_of_histories; i++){
free(histories[i]);
}
free(histories);
for(int i = 0; i < number_of_bookmarks; i++){
free(bookmarks[i]);
}
free(bookmarks);
number_of_bookmarks = get_number_of_bookmarks();
number_of_histories = get_number_of_histories();
bookmarks = reading_bookmarks(number_of_bookmarks);
histories = reading_histories(number_of_histories);
update_or_not = 0;
}
// READING - SUBSCRIPTION CHANNELS
DIR * dirp;
struct dirent * entry;
dirp = opendir("./rss/feeds");
if(dirp == NULL){fprintf(stderr, "Please make sure you copy the TODO to your /home/(user)/ directory"); exit(1);}
int number_of_channels = 0;
while((entry = readdir(dirp)) != NULL) {
if(entry->d_type == DT_REG){
number_of_channels++;
}
}
char subscription_channels[number_of_channels][40];
char **channel_feeds[number_of_channels];
int channel_link_amount[number_of_channels];
int i = 0;
rewinddir(dirp);
while((entry = readdir(dirp)) != NULL) {
if(entry->d_type == DT_REG){
strncpy(subscription_channels[i], entry->d_name, 40);
channel_feeds[i] = reading_feeds(&channel_link_amount[i], subscription_channels[i]);
i++;
}
}
int channel_has_new[number_of_channels];
for(int i = 0; i < number_of_channels; i++){
channel_has_new[i] = 0;
for(int j = 0; j < channel_link_amount[i]; j++){
if(strstr(channel_feeds[i][j], "NEW ") != NULL){
channel_has_new[i] = 1;
}
}
}
free(entry);
closedir(dirp);
for(int i = 0; i < number_of_channels; i++){
for(int j = 0; j < channel_link_amount[i]; j++){
for(size_t k = 0; k < strlen(channel_feeds[i][j]); k++){
if(channel_feeds[i][j][k] == 104 && channel_feeds[i][j][k+1] == 116 && channel_feeds[i][j][k+2] == 116 && channel_feeds[i][j][k+3] == 112 && channel_feeds[i][j][k+4] == 115){
channel_feeds[i][j][k] = '\0';
}
}
}
}
// INPUT
glfwPollEvents();
nk_glfw3_new_frame(&glfw);
static float motion_Y = 0;
selected_drawer = keyboard_events(&currently_playing_from_search, do_we_have_search_results, &selected_settings_theme, &selected_settings, &open_info_window, &open_add_to_channels_input_box, add_to_channels_input, &searched, &selected_search_link, number_of_bookmarks, number_of_histories, &selected_history, &selected_bookmark, bookmarks[selected_bookmark], histories[selected_history],subscription_channels[selected_subscription_channel], channel_link_amount[selected_subscription_channel], number_of_channels, &selected_subscription_channel, &selected_subscriptions_link, &selected_drawer, &ctx->input, &update_or_not);
mouse_event(space, &ctx->input);
// LABEL STYLES
struct nk_style_button button_style_original = ctx->style.button;
struct nk_style_button button_style_selected = ctx->style.button;
if(cfg_theme == 1){
button_style_selected.normal = nk_style_item_color(nk_rgb(190,50,70));
button_style_selected.hover = nk_style_item_color(nk_rgb(190,50,70));
button_style_selected.active = nk_style_item_color(nk_rgb(190,50,70));
}
if(cfg_theme == 2){
button_style_selected.normal = nk_style_item_color(nk_rgb(1,70,150));
button_style_selected.hover = nk_style_item_color(nk_rgb(1,70,150));
button_style_selected.active = nk_style_item_color(nk_rgb(1,70,150));
}
struct nk_style_button button_style_new = ctx->style.button;
if(cfg_theme == 1){
button_style_new.normal = nk_style_item_color(nk_rgb(255,190,0));
button_style_new.hover = nk_style_item_color(nk_rgb(190,50,70));
button_style_new.active = nk_style_item_color(nk_rgb(190,50,70));
}
if(cfg_theme == 2){
button_style_new.normal = nk_style_item_color(nk_rgb(210,190,30));
button_style_new.hover = nk_style_item_color(nk_rgb(210,190,30));
button_style_new.active = nk_style_item_color(nk_rgb(210,190,30));
}
// GUI
if(nk_begin(ctx, "c_nuklear_youtube_viewer", nk_rect(0, 0, win_width+10, win_height), 0)){ // if win_width is not +10 then on the subscription there is about 10 pixels on the right side that are transparent
nk_layout_row_dynamic(ctx, 40, 7);
ctx->style.button = button_style_original;
if(selected_subscriptions_link == -1 && selected_drawer == 1){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "Settings")){
fprintf(stdout, "button home pressed\n");
selected_drawer = 1;
}
ctx->style.button = button_style_original;
if(selected_subscriptions_link == -1 && selected_drawer == 2){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "Subscriptions")){
fprintf(stdout, "button subscriptions pressed\n");
selected_drawer = 2;
}
ctx->style.button = button_style_original;
if(selected_subscriptions_link == -1 && selected_search_link == -1 && selected_drawer == 3){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "Search")){
fprintf(stdout, "button search pressed\n");
selected_drawer = 3;
}
ctx->style.button = button_style_original;
if(selected_subscriptions_link == -1 && selected_drawer == 4){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "Welcome!")){
fprintf(stdout, "button start pressed\n");
selected_drawer = 4;
}
ctx->style.button = button_style_original;
if(selected_subscriptions_link == -1 && selected_drawer == 5 && selected_history == -1){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "History")){
fprintf(stdout, "button history pressed\n");
selected_drawer = 5;
}
ctx->style.button = button_style_original;
if(selected_subscriptions_link == -1 && selected_drawer == 6 && selected_bookmark == -1){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "Bookmarks")){
fprintf(stdout, "button bookmarks pressed\n");
selected_drawer = 6;
}
ctx->style.button = button_style_original;
if(selected_subscriptions_link == -1 && selected_drawer == 7){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "Exit")){
nk_end(ctx);
selected_drawer = 7;
}
ctx->style.button = button_style_original;
// SETTINGS
if(selected_drawer == 1){
selected_subscriptions_link = -1;
selected_history = -1;
selected_bookmark = -1;
selected_search_link = -1;
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "Settings", NK_TEXT_CENTERED);
nk_layout_row_dynamic(ctx, 50, 3);
if(selected_settings == 1 && selected_settings_theme == 0){
if(cfg_theme == 1){
nk_label_colored(ctx, "Theme:", NK_TEXT_LEFT, nk_rgba(190, 50, 70, 255));
}
if(cfg_theme == 2){
nk_label_colored(ctx, "Theme:", NK_TEXT_LEFT, nk_rgba(1, 100, 255, 255));
}
}else{
nk_label(ctx, "Theme:", NK_TEXT_LEFT);
}
if(selected_settings == 1 && selected_settings_theme == 1){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "CNUK")){
selected_settings_theme = 1;
}
ctx->style.button = button_style_original;
if(selected_settings == 1 && selected_settings_theme == 2){
ctx->style.button = button_style_selected;
}
if(nk_button_label(ctx, "Moon")){
selected_settings_theme = 2;
}
ctx->style.button = button_style_original;
}
// SUBSCRIPTIONS
if(selected_drawer == 2){
selected_history = -1;
selected_bookmark = -1;
selected_search_link = -1;
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "Subscriptions", NK_TEXT_CENTERED);
//channels
nk_layout_row_dynamic(ctx, 50, 8);
for(int i = 0; i < number_of_channels; i++){
if(selected_subscriptions_link == 0 && selected_subscription_channel == i){
ctx->style.button = button_style_selected;
if(nk_button_label(ctx, subscription_channels[i])){
selected_subscription_channel = i;
}
ctx->style.button = button_style_original;
}else if(channel_has_new[i] == 1){
ctx->style.button = button_style_new;
if(nk_button_label(ctx, subscription_channels[i])){
selected_subscription_channel = i;
}
ctx->style.button = button_style_original;
}else{
if(nk_button_label(ctx, subscription_channels[i])){
selected_subscription_channel = i;
}
}
if(i == 7 || i == 15 || i == 23){
if((number_of_channels - (i+1)) < 8){
nk_layout_row_dynamic(ctx, 50, (number_of_channels-(i+1)));
}else{
nk_layout_row_dynamic(ctx, 50, 8);
}
}
}
//links
nk_layout_row_dynamic(ctx, 50, 1);
for(int i = 0; i < channel_link_amount[selected_subscription_channel] ; i++){
if(cfg_theme == 1){
if(selected_subscriptions_link == i+1){
nk_label_colored(ctx, channel_feeds[selected_subscription_channel][i], NK_TEXT_LEFT, nk_rgba(190, 50, 70, 255));
}else if(strstr(channel_feeds[selected_subscription_channel][i], "NEW ") != NULL){
nk_label_colored(ctx, channel_feeds[selected_subscription_channel][i], NK_TEXT_LEFT, nk_rgba(255, 190, 0, 255));
}else{
nk_label(ctx, channel_feeds[selected_subscription_channel][i], NK_TEXT_LEFT);
}
}else if(cfg_theme == 2){
if(selected_subscriptions_link == i+1){
nk_label_colored(ctx, channel_feeds[selected_subscription_channel][i], NK_TEXT_LEFT, nk_rgba(1, 100, 255, 255));
}else if(strstr(channel_feeds[selected_subscription_channel][i], "NEW ") != NULL){
nk_label_colored(ctx, channel_feeds[selected_subscription_channel][i], NK_TEXT_LEFT, nk_rgba(210, 190, 30, 255));
}else{
nk_label(ctx, channel_feeds[selected_subscription_channel][i], NK_TEXT_LEFT);
}
}
}
}
// SEARCH
if(selected_drawer == 3){
selected_subscriptions_link = -1;
selected_history = -1;
selected_bookmark = -1;
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "Search for a video:", NK_TEXT_CENTERED);
nk_edit_string(ctx, NK_EDIT_SIMPLE, text, &text_length, 256, nk_filter_ascii);
if(searched == 1){
searches = searching(text);
bzero(text, 255);
searched = 0;
do_we_have_search_results = 1;
}
if(currently_playing_from_search == 1){
play_from_search(searches[selected_search_link-1]);
currently_playing_from_search = 0;
}
if(do_we_have_search_results == 1){
for(int i = 0; i < 10; i++){
if(selected_search_link == i+1){
if(cfg_theme == 1){
nk_label_colored(ctx, searches[i], NK_TEXT_LEFT, nk_rgba(190, 50, 70, 255));
}
if(cfg_theme == 2){
nk_label_colored(ctx, searches[i], NK_TEXT_LEFT, nk_rgba(1, 100, 255, 255));
}
}else{
nk_label(ctx, searches[i], NK_TEXT_LEFT);
}
}
}
}
// START
if(selected_drawer == 4){
selected_subscriptions_link = -1;
selected_history = -1;
selected_bookmark = -1;
selected_search_link = -1;
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "Welcome to CNUK TUBE! :)", NK_TEXT_CENTERED);
nk_label(ctx, "", NK_TEXT_CENTERED);
nk_label(ctx, "This program is meant to allow people to watch videos", NK_TEXT_CENTERED);
nk_label(ctx, "without ads and without spending too much reasources opening up a browser and a website.", NK_TEXT_CENTERED);
nk_label(ctx, "", NK_TEXT_CENTERED);
nk_layout_row_dynamic(ctx, 50, 2);
nk_label(ctx, "CNUK TUBE keybindings cheatsheet:", NK_TEXT_LEFT);
nk_label(ctx, "Video player (MPV) keybindings cheatsheet:", NK_TEXT_LEFT);
nk_label(ctx, "Move around with arrow keys", NK_TEXT_LEFT);
nk_label(ctx, "9/0 - change volume", NK_TEXT_LEFT);
nk_label(ctx, "Enter - play the selected video", NK_TEXT_LEFT);
nk_label(ctx, "Left/Right - move 10 seconds", NK_TEXT_LEFT);
nk_label(ctx, "D - download the selected video", NK_TEXT_LEFT);
nk_label(ctx, "Up/Down - move 1 minute", NK_TEXT_LEFT);
nk_label(ctx, "O - mark selected subscription video as OLD", NK_TEXT_LEFT);
nk_label(ctx, "Page Up/Page Down - move trough chapters", NK_TEXT_LEFT);
nk_label(ctx, "I - get informatin about selected video", NK_TEXT_LEFT);
nk_label(ctx, "F - fullscreen", NK_TEXT_LEFT);
nk_label(ctx, "C - usable inside of information window to get comments", NK_TEXT_LEFT);
nk_label(ctx, "S - screenshot", NK_TEXT_LEFT);
nk_label(ctx, "I - video information", NK_TEXT_LEFT);
nk_label(ctx, "Space - pause/play", NK_TEXT_LEFT);
nk_label(ctx, "A - add a channel to subscriptions", NK_TEXT_LEFT);
nk_label(ctx, "", NK_TEXT_LEFT);
nk_label(ctx, "U - update history and bookmarks", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "", NK_TEXT_CENTERED);
nk_label(ctx, "Version 1 is unstable, and probobly wont work on Windows or Mac.", NK_TEXT_CENTERED);
nk_label(ctx, "from the search drawer you can not download or get info, only play", NK_TEXT_CENTERED);
nk_label(ctx, "With version 2, hopefully we will have the following features:", NK_TEXT_CENTERED);
nk_label(ctx, "No reliance on bashs scripts, only C functions", NK_TEXT_CENTERED);
nk_label(ctx, "No reliance on glfw, maybe?", NK_TEXT_CENTERED);
nk_label(ctx, "More details and also a info popup for searches", NK_TEXT_CENTERED);
nk_label(ctx, "Not crashing when a foreign char is in the search results", NK_TEXT_CENTERED);
nk_label(ctx, "RAM useage lowered hopefully", NK_TEXT_CENTERED);
nk_label(ctx, "CPU usage will be more optimised", NK_TEXT_CENTERED);
nk_label(ctx, "Ability to scroll longer lists without mouse", NK_TEXT_CENTERED);
nk_label(ctx, "Ablility to select the text input boxes without mouse", NK_TEXT_CENTERED);
nk_label(ctx, "Filters for search, history and bookmarks", NK_TEXT_CENTERED);
nk_label(ctx, "A popup saying loading...", NK_TEXT_CENTERED);
nk_label(ctx, "default video resolution", NK_TEXT_CENTERED);
nk_label(ctx, "a popup asking what resolution you would like to download in", NK_TEXT_CENTERED);
nk_label(ctx, "can change mpv arrow keys movement amount", NK_TEXT_CENTERED);
nk_label(ctx, "history displays %watched ... 25% 50% 75% 100% watched", NK_TEXT_CENTERED);
nk_label(ctx, "search history", NK_TEXT_CENTERED);
nk_label(ctx, "option to notify-send new videos from subscriptions", NK_TEXT_CENTERED);
nk_label(ctx, "keybinding S - opens up a new window that has 20 suggested videos", NK_TEXT_CENTERED);
nk_label(ctx, "better handleing of live streams", NK_TEXT_CENTERED);
nk_label(ctx, "more themes", NK_TEXT_CENTERED);
nk_layout_row_dynamic(ctx, win_height-120, 1);
struct nk_command_buffer *canvas = nk_window_get_canvas(ctx);
nk_widget(&space, ctx);
for(int i = 0; i < 2; i++){
if(rng_direction[i] == 0){
if(cfg_theme == 1){
nk_fill_circle(canvas, nk_rect(40+(rng[i])-direction, (win_height-40)-motion_Y, 40, 1), nk_rgb(255, 0, 0));
nk_fill_circle(canvas, nk_rect(70+(rng[i])-direction, (win_height-40)-motion_Y, 40, 1), nk_rgb(255, 0, 0));
nk_fill_triangle(canvas, 40+(rng[i])-direction, (win_height-34)-motion_Y, 110+(rng[i])-direction, (win_height-34)-motion_Y, 72+(rng[i])-direction, (win_height+15)-motion_Y, nk_rgb(255, 0, 0));
}
if(cfg_theme == 2){
nk_fill_circle(canvas, nk_rect(40+(rng[i])-direction, (win_height-40)-motion_Y, 80, 1), nk_rgb(222, 222, 222));
nk_fill_circle(canvas, nk_rect(37+(rng[i])-direction, (win_height-40)-motion_Y, 65, 1), nk_rgb(1, 10, 30));
}
}
if(rng_direction[i] == 1){
if(cfg_theme == 1){
nk_fill_circle(canvas, nk_rect(40+(rng[i])+direction, (win_height-40)-motion_Y, 40, 1), nk_rgb(255, 0, 0));
nk_fill_circle(canvas, nk_rect(70+(rng[i])+direction, (win_height-40)-motion_Y, 40, 1), nk_rgb(255, 0, 0));
nk_fill_triangle(canvas, 40+(rng[i])+direction, (win_height-34)-motion_Y, 110+(rng[i])+direction, (win_height-34)-motion_Y, 72+(rng[i])+direction, (win_height+15)-motion_Y, nk_rgb(255, 0, 0));
}
if(cfg_theme == 2){
nk_fill_circle(canvas, nk_rect(40+(rng[i])+direction, (win_height-40)-motion_Y, 80, 1), nk_rgb(222, 222, 222));
nk_fill_circle(canvas, nk_rect(37+(rng[i])+direction, (win_height-40)-motion_Y, 65, 1), nk_rgb(1, 10, 30));
}
}
}
}
direction = direction + (motion_Y / 400);
if(raise == 1){
motion_Y = motion_Y + 4;
} else if(raise == 0){
motion_Y = motion_Y - 4;
}
if(motion_Y == 700){
raise = 0;
}
// HISTORY
if(selected_drawer == 5){
selected_subscriptions_link = -1;
selected_bookmark = -1;
selected_search_link = -1;
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "History", NK_TEXT_CENTERED);
for(int i = 0; i < number_of_histories; i++){
if(selected_history == i){
if(cfg_theme == 1){
nk_label_colored(ctx, histories[i], NK_TEXT_LEFT, nk_rgba(190, 50, 70, 255));
}
if(cfg_theme == 2){
nk_label_colored(ctx, histories[i], NK_TEXT_LEFT, nk_rgba(1, 100, 255, 255));
}
}else{
nk_label(ctx, histories[i], NK_TEXT_LEFT);
}
}
}
// BOOKMARKS
if(selected_drawer == 6){
selected_subscriptions_link = -1;
selected_history = -1;
selected_search_link = -1;
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "Bookmarks", NK_TEXT_CENTERED);
for(int i = 0; i < number_of_bookmarks; i++){
if(selected_bookmark == i){
if(cfg_theme == 1){
nk_label_colored(ctx, bookmarks[i], NK_TEXT_LEFT, nk_rgba(190, 50, 70, 255));
}
if(cfg_theme == 2){
nk_label_colored(ctx, bookmarks[i], NK_TEXT_LEFT, nk_rgba(1, 100, 255, 255));
}
}else{
nk_label(ctx, bookmarks[i], NK_TEXT_LEFT);
}
}
}
// EXIT
if(selected_drawer == 7){
selected_subscriptions_link = -1;
selected_history = -1;
selected_bookmark = -1;
selected_search_link = -1;
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "Enter to exit", NK_TEXT_CENTERED);
}
if(selected_drawer == 6969){
nk_end(ctx);
}
}// if(nk_begin
nk_end(ctx);
// popup windows
if(open_add_to_channels_input_box == 1){
if(nk_begin(ctx, "search box window", nk_rect((win_width/2)-425, (win_height/2)-300, (win_width/2)-100, (win_height/2)-300), NK_WINDOW_BORDER)){
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "add channel name with @ , example @PewDiePie", NK_TEXT_CENTERED);
nk_label(ctx, "as seen in the url: https://www.youtube.com/@PewDiePie", NK_TEXT_CENTERED);
nk_edit_string(ctx, NK_EDIT_SIMPLE, add_to_channels_input, &add_to_channels_input_length, 256, nk_filter_ascii);
nk_label(ctx, "Q to quit", NK_TEXT_LEFT);
}
nk_end(ctx);
//bzero(add_to_channels_input, 255);
}
if(open_info_window == 1){
info = reading_info();
description = reading_description(&number_of_description_lines);
if(nk_begin(ctx, "info window", nk_rect(100, 50, win_width-200, win_height-50), NK_WINDOW_BORDER)){
nk_layout_row_dynamic(ctx, 50, 2);
for(int i = 0; i < 9; i++){
nk_label(ctx, info[i], NK_TEXT_CENTERED);
}
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "", NK_TEXT_CENTERED);
nk_label(ctx, "", NK_TEXT_CENTERED);
nk_layout_row_dynamic(ctx, 50, 2);
for(int i = 0; i < number_of_description_lines; i++){
nk_label(ctx, description[i], NK_TEXT_CENTERED);
}
nk_layout_row_dynamic(ctx, 50, 1);
nk_label(ctx, "Q to quit", NK_TEXT_CENTERED);
}
nk_end(ctx);
//bzero(add_to_channels_input, 255);
}
for(int i = 0; i < number_of_channels; i++){
for(int j = 0; j < channel_link_amount[i]; j++){
free(channel_feeds[i][j]);
}
free(channel_feeds[i]);
}
for(int i = 0; i < 1; i++){
free(cfg[i]);
}
free(cfg);
// DRAW
glViewport(0, 0, win_width, win_height);
glClear(GL_COLOR_BUFFER_BIT);
nk_glfw3_render(&glfw, NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
glfwSwapBuffers(win);
}// main while loop
nk_glfw3_shutdown(&glfw);
glfwTerminate();
}
return 0;
}//int main