static void activate_temp (void) { gint playlists = playlist_count (); const gchar * title = _("Temporary Playlist"); for (gint playlist = 0; playlist < playlists; playlist ++) { gchar * title2 = playlist_get_title (playlist); if (! strcmp (title2, title)) { playlist_set_active (playlist); g_free (title2); return; } g_free (title2); } if (! playlist_entry_count (playlist_get_active ())) playlist_set_title (playlist_get_active (), title); else { playlist_insert (playlists); playlist_set_title (playlists, title); playlist_set_active (playlists); } }
int main() { kr_mkv_t *mkv_output; kr_mkv_t *mkv_input; kr_mkv_t *settings; krad_system_init(); // krad_system_log_on("derp.log"); playlist_t *playlist = playlist_init("test.txt"); mkv_output = kr_mkv_create_stream(argv[1], atoi(argv[2]), argv[3], argv[4]); if(splice_init(settings, mkv_output, playlist) < 0) { perror("splice_init"); } printf("resolution: %d x %d\n", mkv_output->tracks[VIDEO_TRACK].width, mkv_output->tracks[VIDEO_TRACK].height); uint32_t i; while(1) { playlist->current_entry = 0; for(i = 0; i < playlist_count(playlist); i++) { if(playlist_current_video(playlist) > 0) { printf("playing: %s\n", playlist_current_video(playlist)); mkv_input = kr_mkv_open_file(playlist_current_video(playlist)); if(!mkv_input) { perror(playlist_current_video(playlist)); } splice(mkv_input, mkv_output); kr_mkv_destroy(&mkv_input); playlist_next(playlist); } } } kr_mkv_destroy(&mkv_output); playlist_destroy(playlist); return(0); }
void playlist_shuffle(struct playlist *pl) { struct playlist_entry *save_current = pl->current; bool save_replaced = pl->current_was_replaced; int count = playlist_count(pl); struct playlist_entry **arr = talloc_array(NULL, struct playlist_entry *, count); for (int n = 0; n < count; n++) { arr[n] = pl->first; playlist_unlink(pl, pl->first); } for (int n = 0; n < count; n++) { int other = (int)((double)(count) * rand() / (RAND_MAX + 1.0)); struct playlist_entry *tmp = arr[n]; arr[n] = arr[other]; arr[other] = tmp; } for (int n = 0; n < count; n++) playlist_add(pl, arr[n]); talloc_free(arr); pl->current = save_current; pl->current_was_replaced = save_replaced; }
static void save_playlists_real (void) { int lists = playlist_count (); const char * folder = get_path (AUD_PATH_PLAYLISTS_DIR); /* save playlists */ char * * order = g_malloc (sizeof (char *) * (lists + 1)); GHashTable * saved = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (int i = 0; i < lists; i ++) { int id = playlist_get_unique_id (i); order[i] = g_strdup_printf ("%d", id); if (playlist_get_modified (i)) { char * path = g_strdup_printf ("%s/%d.audpl", folder, id); char * uri = filename_to_uri (path); playlist_save (i, uri); playlist_set_modified (i, FALSE); g_free (path); g_free (uri); } g_hash_table_insert (saved, g_strdup_printf ("%d.audpl", id), NULL); } order[lists] = NULL; char * order_string = g_strjoinv (" ", order); g_strfreev (order); GError * error = NULL; char * order_path = g_strdup_printf ("%s/order", get_path (AUD_PATH_PLAYLISTS_DIR)); char * old_order_string; g_file_get_contents (order_path, & old_order_string, NULL, NULL); if (! old_order_string || strcmp (old_order_string, order_string)) { if (! g_file_set_contents (order_path, order_string, -1, & error)) { fprintf (stderr, "Cannot write to %s: %s\n", order_path, error->message); g_error_free (error); } } g_free (order_string); g_free (order_path); g_free (old_order_string); /* clean up deleted playlists and files from old naming scheme */ char * path = make_playlist_path (0); remove (path); g_free (path); DIR * dir = opendir (folder); if (! dir) goto DONE; struct dirent * entry; while ((entry = readdir (dir))) { if (! g_str_has_suffix (entry->d_name, ".audpl") && ! g_str_has_suffix (entry->d_name, ".xspf")) continue; if (! g_hash_table_lookup_extended (saved, entry->d_name, NULL, NULL)) { char * path = g_strdup_printf ("%s/%s", folder, entry->d_name); remove (path); g_free (path); } } closedir (dir); DONE: g_hash_table_destroy (saved); }
static void load_playlists_real (void) { /* old (v3.1 and earlier) naming scheme */ int count; for (count = 0; ; count ++) { char * path = make_playlist_path (count); if (! g_file_test (path, G_FILE_TEST_EXISTS)) { g_free (path); break; } char * uri = filename_to_uri (path); playlist_insert (count); playlist_insert_playlist_raw (count, 0, uri); playlist_set_modified (count, TRUE); g_free (path); g_free (uri); } /* unique ID-based naming scheme */ char * order_path = g_strdup_printf ("%s/order", get_path (AUD_PATH_PLAYLISTS_DIR)); char * order_string; g_file_get_contents (order_path, & order_string, NULL, NULL); g_free (order_path); if (! order_string) goto DONE; char * * order = g_strsplit (order_string, " ", -1); g_free (order_string); for (int i = 0; order[i]; i ++) { char * path = g_strdup_printf ("%s/%s.audpl", get_path (AUD_PATH_PLAYLISTS_DIR), order[i]); if (! g_file_test (path, G_FILE_TEST_EXISTS)) { g_free (path); path = g_strdup_printf ("%s/%s.xspf", get_path (AUD_PATH_PLAYLISTS_DIR), order[i]); } char * uri = filename_to_uri (path); playlist_insert_with_id (count + i, atoi (order[i])); playlist_insert_playlist_raw (count + i, 0, uri); playlist_set_modified (count + i, FALSE); if (g_str_has_suffix (path, ".xspf")) playlist_set_modified (count + i, TRUE); g_free (path); g_free (uri); } g_strfreev (order); DONE: if (! playlist_count ()) playlist_insert (0); playlist_set_active (0); }