Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dirent.h>
- #include <limits.h>
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "audio_len.h"
- bool isAudioFiles(char const *name) {
- size_t len = strlen(name);
- if (len > 4 &&
- (strcmp(name + len - 4, ".mp3") && strcmp(name + len - 4, ".mp4") &&
- strcmp(name + len - 4, ".wav")) == 0)
- return true;
- else
- return false;
- }
- void process(fileDir d) {
- bool isAudioFiles(char const *name);
- char *getTime(const char *s, char *n);
- DIR *dir;
- struct dirent *entry;
- FILE *file;
- char *path = (char *)malloc(sizeof(char));
- sprintf(path, "%s/%s", d.dst, d.op);
- file = fopen(path, "w+");
- if ((dir = opendir(d.src)) == NULL)
- fprintf(stderr, "could't open %s\n", d.src), exit(1);
- else {
- fprintf(file, "NOME,DURAÇÃO\n");
- while ((entry = readdir(dir)) != NULL) {
- if (isAudioFiles(entry->d_name) == true) {
- fprintf(file, "%s,%s", entry->d_name, getTime(d.src, entry->d_name));
- }
- }
- fclose(file);
- closedir(dir);
- }
- }
- char *getTime(const char *s, char *n) {
- FILE *fp;
- char time[15];
- char *result = (char *) malloc(CHAR_MAX * sizeof(char));
- char cmd[100];
- sprintf(cmd, "soxi -D %s/%s 2>/dev/null", s, n);
- fp = popen(cmd, "r");
- if (fp == NULL)
- fprintf(stderr, "soxi command failed\n");
- if (fgets(time, 15, fp) != NULL)
- result = time;
- else
- fprintf(stderr, "fgets error\n");
- pclose(fp);
- return result;
- free(result);
- }
- void help() {
- fprintf(stderr, "\nUSAGE: audio_length [OPTIOMS] -n <FILENAME.csv>\n"
- "Options:\n"
- " -s <path for source directory>\n"
- " -d <path for destination file>\n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement