Hi,

So I really like freevo and all, much cleaner and nicer then mythtv.
Anyhow, there just is this one issue I have that prevents me from using
freevo over mythtv.

In mythtv you can add your own filetypes. Therefore I have added the
filetype rar and the command it executes would be unrar x %s
/tmp/mythtv/; mplayer /tmp/mythtv/*; rm /tmp/mythtv/*. (I know i know,
it's ugly but works : )

I have started working on compFUSEd. A userland filesystem plugin that
let's you mount compressed files like a directory. Once that is done it
should be quite easy and cleanly to implement something like this in Freevo.

Since this doesn't exist in freevo (yet) I decided to write a little
wrapper for mplayer that'll extract rar files into a temporary
directory, and then pass the arguments on to mplayer. (See attached C
file I dunno python : )
It doesn't work with freevo, it does stand alone. Freevo starts the avi,
but it then loops e.g. mplayer quits and gets restarted from freevo over
and over and over again. How is this possible? What can I do to 'fix'
this. Until freevo has support for rafiles via internal
handling/external handling it makes need to use mythtv, which I really
don't want to : )

Thanks,
Oliver


/*
 * wrapper_mplayer.c v0.01 Oliver ([EMAIL PROTECTED])
 * 
 * Mplayer rar filetype wraper thingy.
 * This thing should be a temporary thing until I get compFUSEd to work with
 * files like rar. It's work in progress so until then, this little dirty
 * thing.
 *
 * Warning , use this at your own risc, I'm not responsible for anything!
 * Note: Right now it extracts all files from the rar archive and plays
 * all avi files in that dir with mplayer. You could change the
 * COMMAND_MPLAYER and use this wrapper with xine too I suppose, since
 * all paramayers are plainly copyed over. The only thing that might get
 * tricky is that the file(s) to be played will be appended to that commandline
 * other then that it should be fine.
 * 
 * It's GPLed so you can change it as much as you want.
 */

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

#define COMMAND_MPLAYER "/usr/bin/mplayer"
#define COMMAND_UNRAR "/usr/bin/unrar"

#define EXTENTION_RAR ".rar"
#define OPTIONS_RAR "e"

int main(int argc, char *argv[]) {
        int retval;
        int i;

        retval = 0;

        /* Search through all the supplied arguments for any reference to 
rarfiles
         * we start at the back, as it's the most likly place to have the file 
in question.
         */
        for (i = argc -1; i > 0; i--) {
                char *extention_location;
                extention_location = strstr(argv[i], EXTENTION_RAR);
                if (extention_location) {
                        char dirtemplate[15] = "/tmp/wm_XXXXXX\0", 
tempdirname[15];
                        char *tempdirname_ptr;
                        char *external_command;
                        int j, external_command_length;
                        
                        DIR *tempdir;
                        struct dirent **tempdirnamelist;
                        int namelist;
                        char *tempfilename;
                        
                        tempdirname_ptr = tempdirname;

                        /* So we found a rar file. Step 1, extract all files to 
a temporary dir */
                        tempdirname_ptr = mkdtemp(dirtemplate);
                        external_command = malloc(
                                                strlen(COMMAND_UNRAR) 
+strlen(OPTIONS_RAR) 
                                                +strlen(tempdirname_ptr) 
+strlen(argv[i]
                                        ) +4/*spaces and \0*/);
                        sprintf(external_command, "%s %s %s %s", COMMAND_UNRAR, 
OPTIONS_RAR, argv[i], tempdirname_ptr);
                        if (system(external_command)) {
                                perror("system");
                                retval = 1;
                        }
                        free(external_command);

                        /* rar file extracted, step 2 assemble new commandline 
*/
                        external_command_length = strlen(COMMAND_MPLAYER) 
+strlen(tempdirname_ptr) +8;
                        external_command = malloc(external_command_length);
                        strcpy(external_command, COMMAND_MPLAYER);
                        for (j = 1; j < argc; j++) {
                                if (j != i) {
                                        external_command_length += 1 
+strlen(argv[j]);
                                        external_command = 
realloc(external_command, external_command_length);
                                        strcat(external_command, " ");
                                        strcat(external_command, argv[j]);
                                }
                        }
                        strcat(external_command, " ");
                        strcat(external_command, tempdirname_ptr);
                        strcat(external_command, "/*.avi");
                        if (system(external_command)) {
                                perror("system");
                                retval = 1;
                        }

                        /* cleanup! */
                        /* remove all files in temporary dir */
                        tempdir = opendir(tempdirname_ptr);
                        if (!tempdir) {
                                perror("opendir");
                                retval = 1;
                        }
                        namelist = scandir(tempdirname_ptr, &tempdirnamelist, 
NULL, alphasort);
                        if (namelist < 0) {
                                perror("scandir");
                        } else {
                                tempfilename = malloc(strlen(tempdirname_ptr));
                                while((namelist--) -2) { /* last 2 entries are 
. .., skip those */
                                        tempfilename = realloc(
                                                                tempfilename, 
strlen(tempdirname_ptr)
                                                                
+strlen(tempdirnamelist[namelist]->d_name)
                                                                +2      
                                                        );
                                        sprintf(tempfilename, "%s/%s", 
tempdirname_ptr, tempdirnamelist[namelist]->d_name);
                                        if (remove(tempfilename)) {
                                                perror("remove");
                                                retval = 1;
                                        }
                                        free(tempdirnamelist[namelist]);
                                }
                                free(tempdirnamelist);
                        }
                        closedir(tempdir);
                        
                        /* remove temporary dir too */
                        if (rmdir(tempdirname_ptr)) {
                                perror("rmdir");
                                retval = 1;
                        }
                        /* all done, we can exit the loop early. */
                        i = 0;
                } else {
                        int j, external_command_length;
                        char *external_command;
                        char *spaces;

                        external_command_length = strlen(COMMAND_MPLAYER) +5;
                        external_command = malloc(external_command_length);
                        strcpy(external_command, COMMAND_MPLAYER);
                        for (j = 1; j < argc; j++) {
                                external_command_length += 1 +strlen(argv[j]);
                                external_command = realloc(external_command, 
external_command_length);
                                strcat(external_command, " ");
                                /* this should fix argv with spaces in it. it's 
ugly I know */
                                spaces = strstr(argv[j], " ");
                                if (spaces) {
                                        strcat(external_command, "\"");
                                        strcat(external_command, argv[j]);
                                        strcat(external_command, "\"");
                                } else {
                                        strcat(external_command, argv[j]);
                                }
                        }
                        printf("extcmd: %s\n", external_command);
                        if (system(external_command)) {
                                perror("system");
                                retval = 1;
                        }
                }
        }
        return retval;
}

Reply via email to