Esempio n. 1
0
GArray *read_ini_array(INIFile *inifile, const gchar *section, const gchar *key)
{
    gchar *temp;
    GArray *a;

    if (! (temp = read_ini_string (inifile, section, key)))
        return NULL;

    a = string_to_garray(temp);
    g_free(temp);
    return a;
}
Esempio n. 2
0
static guint playlist_load_ins(char * filename, long pos)
{
    FILE *file;
    char *line, *ext;
    guint entries = 0;
    int linelen = 1024;
    gboolean extm3u = FALSE;
    char *ext_info = NULL, *ext_title = NULL;
    int ext_len = -1;

    ext = strrchr(filename, '.');
    if (ext && !strcasecmp(ext, ".pls"))
    {
        int noe, i;

        line = read_ini_string(filename, "playlist", "NumberOfEntries");
        if (line == NULL)
            return 0;

        noe = atoi(line);
        g_free(line);

        for (i = 1; i <= noe; i++)
        {
            char key[15];
            g_snprintf(key, 15, "File%d", i);
            line = read_ini_string_no_comment(filename,
                                              "playlist", key);
            g_snprintf(key, 15, "Title%d", i);
            if (cfg.use_pl_metadata)
                ext_title = read_ini_string_no_comment(
                                filename, "playlist", key);
            else
                ext_title = NULL;
            if (line != NULL)
            {
                playlist_load_ins_file(line, filename, pos,
                                       ext_title, -1);
                entries++;
                if (pos >= 0)
                    pos++;
                g_free(line);
            }
            g_free(ext_title);
        }
        playlist_generate_shuffle_list();
        playlistwin_update_list();
        return entries;
    }

    /*
     * Seems like an m3u.  Maybe we should do some sanity checking
     * here?  If someone accidentally selects something else, we
     * will try to read it.
     */

    if ((file = fopen(filename, "r")) == NULL)
        return 0;

    line = g_malloc(linelen);
    while (fgets(line, linelen, file))
    {
        while (strlen(line) == linelen - 1 &&
                line[strlen(line) - 1] != '\n')
        {
            linelen += 1024;
            line = g_realloc(line, linelen);
            fgets(&line[strlen(line)], 1024, file);
        }
        while (line[strlen(line) - 1] == '\r' ||
                line[strlen(line) - 1] == '\n')
            line[strlen(line) - 1] = '\0';

        if (!strncmp(line, "#EXTM3U", 8))
        {
            extm3u = TRUE;
            continue;
        }

        if (extm3u && !strncmp(line, "#EXTINF:", 8))
        {
            if (ext_info)
                g_free(ext_info);
            ext_info = g_strdup(line);
            continue;
        }

        if (line[0] == '#')
        {
            if (ext_info)
            {
                g_free(ext_info);
                ext_info = NULL;
            }
            continue;
        }

        if (extm3u)
        {
            if (cfg.use_pl_metadata)
                parse_extm3u_info(ext_info, &ext_title, &ext_len);
            g_free(ext_info);
            ext_info = NULL;
        }

        playlist_load_ins_file(line, filename, pos, ext_title, ext_len);

        g_free(ext_title);
        ext_title = NULL;
        ext_len = -1;

        entries++;
        if (pos >= 0)
            pos++;
    }
    fclose(file);
    g_free(line);
    playlist_generate_shuffle_list();
    playlistwin_update_list();

    return entries;
}