66namespace Music.M3U {
77
88 // Standard specification here: https://en.wikipedia.org/wiki/M3U
9- public File [] parse_playlist (File playlist ) {
9+ public File []? parse_playlist (File playlist ) {
1010 debug (" Parsing playlist: %s " , playlist. get_path ());
1111 File [] list = {};
1212
@@ -16,71 +16,52 @@ namespace Music.M3U {
1616 string line;
1717
1818 while ((line = dis. read_line ()) != null ) {
19- print (" %s\n " , line);
19+ debug (" %s " , line);
2020
21- // Skip extended
21+ // Skip extended
2222 if (line. has_prefix (" #EXT" )) {
23- print (" Skipping EXTM3U: " + line + " \n " );
24-
25- } else {
26- File target;
27-
28- if (line. ascii_down (). has_prefix (" file:///" )) {
29- target = File . new_for_uri (line);
30-
31- // FIXME: URL get skipped.
32- // } else if (line.ascii_down ().has_prefix ("http")) {
33- // print ("URL are currently unsupported:" + line + "\n");
34-
35- } else {
36- target = File . new_for_path (line);
23+ debug (" Skipping EXTM3U: " + line);
24+ continue ;
25+ }
3726
38- } ;
27+ File target ;
3928
40- // We do not need to test yet whether files exist
41- list + = target;
29+ if (line. ascii_down (). has_prefix (" file:///" )) {
30+ target = File . new_for_uri (line);
31+ // FIXME: URL get skipped.
32+ // } else if (line.ascii_down ().has_prefix ("http")) {
33+ // debug ("URL are currently unsupported:" + line);
34+ } else {
35+ target = File . new_for_path (line);
4236 }
43- }
4437
38+ // We do not need to test yet whether files exist
39+ list + = target;
40+ }
4541 } catch (Error e) {
46- print (" Error: %s\n " , e. message);
42+ warning (" Error: %s " , e. message);
43+ return null ;
4744 }
4845
4946 return list;
50-
5147 }
5248
53- public void save_playlist (MainWindow parent , ListStore queue_liststore ) {
54- debug (" Saving queue as playlist" + " \n " );
49+ public void save_playlist (ListStore queue_liststore , File playlist ) throws Error {
50+ debug (" Saving queue as playlist" );
5551 string content = " " ;
5652
5753 for (var i = 0 ; i < queue_liststore. n_items; i++ ) {
5854 var item = (Music . AudioObject )queue_liststore. get_item (i);
5955 content = content + item. uri + " \n " ;
6056 }
6157
62- var save_dialog = new Gtk .FileDialog () {
63- initial_name = _ ("New playlist .m3u ")
64- };
65-
66- save_dialog.save.begin (parent , null , (obj , res ) => {
67- try {
68- var file = save_dialog. save. end (res);
69- var dostream = new DataOutputStream (
70- file. replace (
71- null ,
72- false ,
73- GLib . FileCreateFlags . REPLACE_DESTINATION
74- )
75- );
76-
58+ try {
59+ var ostream = playlist. replace (null , false , GLib . FileCreateFlags . REPLACE_DESTINATION );
60+ var dostream = new DataOutputStream (ostream);
7761 dostream. put_string (content);
78-
79- } catch (Error err) {
80- warning (" Failed to save file: %s " , err. message);
81- }
82- });
83-
84-
62+ } catch (Error err) {
63+ warning (" Failed to writing to playlist: %s " , err. message);
64+ throw err;
65+ }
8566 }
8667}
0 commit comments