vlc_common: move decoder_synchro_t to synchro.h
[vlc.git] / src / playlist / export.c
blobe9f3ab5e0582772620b8d32f0d1571dc585e8da5
1 /*****************************************************************************
2 * playlist/export.c
3 *****************************************************************************
4 * Copyright (C) 2019 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_playlist_export.h>
27 #include <errno.h>
28 #include <stdio.h>
30 #include <vlc_common.h>
31 #include <vlc_fs.h>
32 #include <vlc_modules.h>
33 #include <vlc_url.h>
34 #include "playlist.h"
35 #include "libvlc.h"
37 struct vlc_playlist_view
39 vlc_playlist_t *playlist;
42 size_t
43 vlc_playlist_view_Count(struct vlc_playlist_view *view)
45 return vlc_playlist_Count(view->playlist);
48 vlc_playlist_item_t *
49 vlc_playlist_view_Get(struct vlc_playlist_view *view, size_t index)
51 return vlc_playlist_Get(view->playlist, index);
54 int
55 vlc_playlist_Export(struct vlc_playlist *playlist, const char *filename,
56 const char *type)
58 vlc_playlist_AssertLocked(playlist);
60 struct vlc_playlist_export *export =
61 vlc_custom_create(vlc_player_GetObject(playlist->player),
62 sizeof(*export), "playlist export");
64 if (!export)
65 return VLC_ENOMEM;
67 int ret = VLC_EGENERIC;
69 struct vlc_playlist_view playlist_view = { .playlist = playlist };
71 export->playlist_view = &playlist_view;
72 export->base_url = vlc_path2uri(filename, NULL);
73 export->file = vlc_fopen(filename, "wt");
74 if (!export->file)
76 msg_Err(export, "Could not create playlist file %s, %s",
77 filename, vlc_strerror_c(errno));
78 goto close_file;
81 // this will actually export
82 module_t *module = module_need(export, "playlist export", type, true);
84 if (!module)
86 msg_Err(export, "Could not export playlist");
87 goto out;
90 module_unneed(export, module);
92 if (!ferror(export->file))
93 ret = VLC_SUCCESS;
94 else
95 msg_Err(export, "Could not write playlist file: %s",
96 vlc_strerror_c(errno));
98 close_file:
99 fclose(export->file);
100 out:
101 free(export->base_url);
102 vlc_object_delete(export);
103 return ret;