/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018 - 2026 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://www.cs.uni.edu/~okane
#+     https://threadsafebooks.com/
#+
#+ This program is free software; you can redistribute it and/or modify
#+ it under the terms of the GNU General Public License as published by
#+ the Free Software Foundation; either version 2 of the License, or
#+ (at your option) any later version.
#+
#+ This program is distributed in the hope that it will be useful,
#+ but WITHOUT ANY WARRANTY; without even the implied warranty of
#+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#+ GNU General Public License for more details.
#+
#+ You should have received a copy of the GNU General Public License
#+ along with this program; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	July 2, 2026

#include "includes.h"
#include "defines.h"
#include "common-externs.h"
#include "common-fcn-headers.h"


#include <vlc/libvlc.h>
#include <vlc/libvlc_renderer_discoverer.h>
#include <vlc/libvlc_media.h>
#include <vlc/libvlc_media_player.h>

#define SLASH '/'


int	new_name(char * new, char *old, char *type) {

	char mhd_name[MAX_FILE_NAME], tmp[MAX_FILE_NAME], filename[MAX_FILE_NAME], filetype[256];
	int i, j, k;

	int tmark = 1;

	strcpy(tmp, old); // basename() modifies arg

	strcpy(filename, basename(tmp));

	if (strlen(filename) == 0) {
		char tmp1[16000];
		error_message("File name error",tmp);
		return 0;
		}

	for (j = strlen(filename); j > 0; j--)
		if (filename[j] == '.') break;

	if (j == 0) {
		char tmp1[16000];
		error_message("Missing file extension", filename);
		return 0;
		}

	filename[j] = 0;
	strcpy(filetype, &filename[j+1]);

	while (1) {

		sprintf(tmp, "%s-%s-%02d.mp4",
		        mhd_ref1(filename, mhd_name), type, tmark);

		if (!file_exists(tmp)) break; // does not exist

		tmark ++;

		if (tmark > 100) {
			error_message("Too many instances of the base filename.", NULL);
			return 0;
			}
		}

	strcpy(new, tmp);

	return 1;
	}

int	new_name1(char * new, char *old) {

	char tmp[MAX_FILE_NAME], filename[MAX_FILE_NAME], filetype[256], mhd_name[MAX_FILE_NAME];
	int i, j, k;

	int tmark = 1;

	strcpy(tmp, old); // basename() modifies arg

	strcpy(filename, basename(tmp));

	if (strlen(filename) == 0) {
		char tmp1[16000];
		error_message("Filename error", tmp);
		return 0;
		}

	for (j = strlen(filename); j > 0; j--)
		if (filename[j] == '.') break;

	if (j == 0) {
		char tmp1[16000];
		error_message("Missing file extensio", filename);
		return 0;
		}

	filename[j] = 0;
	strcpy(filetype, &filename[j+1]);

	while (1) {

		sprintf(tmp, "%s-%02d.png", mhd_ref2(filename, mhd_name), tmark);

		if (!file_exists(tmp)) {	// continue until unused name found
			break;
			}

		tmark ++;

		if (tmark >100) {
			error_message("Too many instances of the base filename.", NULL);
			return 0;
			}
		}

	strcpy(new, tmp);

	return 1;
	}

