File lib/get_song.c


Included Files


Global Variable PROCNAME

char PROCNAME[128]
Included from include/ubs.h

Global Variable CUR_TIME

struct tm* CUR_TIME
Included from include/ubs.h

Global Variable GLOBAL

ubs_table GLOBAL
Included from include/ubs.h

Global Variable LOGLEVEL

int LOGLEVEL
Included from include/ubs.h

Global Variable WEEK

An array that holds all of the half-hour slots for an entire week, which is the period of time that the ubs runs off of. This array contains integers which correspond to show ID's

int WEEK[7][48]
Included from include/ubs-sched.h


Global Variable ALLSHOWS

All the known shows

struct show* ALLSHOWS
Included from include/ubs-sched.h


Global Variable SCHED

ubs_table SCHED
Included from include/ubs-sched.h

Global Function check_against_cur()

Checks to see if a filename is currently playing on the air. Since the ubs-play daemon pulls the file from the queue before playing it, there is a slim chance that a file could be queued twice once it is on the air.

int check_against_cur ( char* filename )

int check_against_cur
Returns NO if no match, YES if a match is found, and NO_FILE if the now_playing file cannot be opened.
char* filename
Filename to check
Prototyped in: include/ubs.h
Calls: check_against_tags(), chomp_line(), fclose(), fgets(), fopen(), log_error_msg(), strcasecmp()

Global Function check_against_log()

Scans the playlist logfile to see if a filename has been recently played.

int check_against_log ( char* filename, char* logfile, int backnum )

int check_against_log
Returns NO if the file is not in the last backnum lines of the playlist log, YES if the file is matched, NO_FILE if the target logfile can't be opened, NO_MEM if malloc fails
char* filename
The filename to check
char* logfile
The logfile to check in
int backnum
The number of lines (at the tail end of the file) to scan
Prototyped in: include/ubs.h
Calls: check_against_tags(), fclose(), fgets(), fopen(), free(), log_error_msg(), malloc(), memset(), read_log(), strcasecmp(), strncpy()

Global Function check_against_queue()

Checks to see if a filename is already in the present queue

int check_against_queue ( char* filename )

int check_against_queue
Returns NO (same as OK) if the filename isn't in the queue, YES if the filename is in the queue, and NO_FILE if the queue can't be opened
char* filename
The filename to check
Prototyped in: include/ubs.h
Calls: check_against_tags(), chomp_line(), fclose(), fgets(), fopen(), log_error_msg(), strcasecmp(), ubs_table_data()

Global Function get_song()

This function reads in the current filecache (all the known songs for the current show) and picks one at random. It does nothing to see if this song was recently played or anything of the sort. That functionality is handled by the check_against_log function.

int get_song ( char* sname )

int get_song
Returns OK on success and NO_FILE if the filecache can't be opened
char* sname
A pointer to a character array which this function will write the selected filename to
Prototyped in: include/ubs.h
Calls: chomp_line(), fclose(), fgets(), fopen(), fscanf(), log_error_msg(), rand()

Global Function make_cache()

This function gets called whenever the UBS starts up, and whenever it detects that a show change has occurred. Basically, it scans all the files in the directory for the current show and writes them to a big file, one filename per line. This was made recursive as of version 0.7.

int make_cache ( char* path )

int make_cache
Returns OK on success, NO_FILE if the filecache can't be opened, NO_FILE if the numfiles file can't be opened
char* path
The pathname of the directory to scan
Prototyped in: include/ubs.h
Calls: parse_dir()lib/get_song.c
  fclose(), fopen(), fprintf(), log_error_msg()

Global Function parse_dir()

Finds the number of files in a directory, and writes out all files it finds to a file pointer.

int parse_dir ( FILE* fp, char* path )

int parse_dir
Returns the number of files found in the given show directory, and all its child directories. If this functon finds another directory within the current one, it will call itself recursively and keep adding to the filecache. NO_DIR is returned if a directory cannot be opened for whatever reason.
FILE* fp
A filepointer, which should be opened with write permissions
char* path
The directory to start scanning at
Prototyped in: include/ubs.h
Calls: parse_dir()lib/get_song.c
  closedir(), fprintf(), log_error_msg(), opendir(), readdir(), snprintf(), stat(), strcmp()
Called by: make_cache()lib/get_song.c
  parse_dir()lib/get_song.c