Merge lp:~didrocks/unity-lens-music/add-local-radio into lp:unity-lens-music

Proposed by Didier Roche-Tolomelli
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 86
Merged at revision: 83
Proposed branch: lp:~didrocks/unity-lens-music/add-local-radio
Merge into: lp:unity-lens-music
Diff against target: 668 lines (+354/-74)
10 files modified
Makefile.am (+1/-1)
configure.ac (+1/-0)
src/categories.vala (+2/-1)
src/daemon.vala (+5/-1)
src/rhythmbox-collection.vala (+99/-70)
src/rhythmbox-scope.vala (+1/-1)
src/track.vala (+7/-0)
tests/Makefile.am (+45/-0)
tests/assertions.vapi (+23/-0)
tests/test-rhythmbox-parser.vala (+170/-0)
To merge this branch: bzr merge lp:~didrocks/unity-lens-music/add-local-radio
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
Review via email: mp+111875@code.launchpad.net

Commit message

adds local radio detection from rhythmbox. The category will
only be placed after the "for purchase one" to be unobstrusive (LP: #969697)
Also fix the non translated "Unknown" album filter appearing for non english
users (LP: #1009069)
Add some tests for the parser part (radios and songs)

Description of the change

This branch adds local radio detection from rhythmbox. The category will
only be placed after the "for purchase one" to be unobstrusive (LP: #969697)

Also fix the non translated "Unknown" album filter appearing for non english
users (LP: #1009069)

Add some tests for the parser part (radios and songs)

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

1) I think we may need to adjust album handling logic in "search" method, as iradio records seem to have empty album names - I think we should skip album if TYPE == RADIO; see lines 654 - 665, i.e.
 bool first_track_from_album = !(album in albums_list_nosearch);
 ...
 if (first_track_from_album)
 ...
    add_result (search.results_model, model, iter, ResultType.ALBUM, category_id);

2) Can you use TrackType as the type of Track - type_track instead of int?

review: Needs Fixing
86. By Didier Roche-Tolomelli

add it to an album if only it's a song, make type_track TypeTrack

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Good spot! Changes made :)

I only add albums for now if the type is a song. Please rereview

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good now, and works fine. Well done!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile.am'
--- Makefile.am 2011-09-14 18:16:32 +0000
+++ Makefile.am 2012-06-29 15:58:20 +0000
@@ -1,4 +1,4 @@
1SUBDIRS = src data po1SUBDIRS = src data po tests
22
3#3#
4# Install the music.lens and musicstore.scope files4# Install the music.lens and musicstore.scope files
55
=== modified file 'configure.ac'
--- configure.ac 2012-04-27 07:45:16 +0000
+++ configure.ac 2012-06-29 15:58:20 +0000
@@ -121,6 +121,7 @@
121 src/Makefile121 src/Makefile
122 src/config.vala122 src/config.vala
123 po/Makefile.in123 po/Makefile.in
124 tests/Makefile
124])125])
125AC_OUTPUT126AC_OUTPUT
126127
127128
=== modified file 'src/categories.vala'
--- src/categories.vala 2012-01-20 11:48:10 +0000
+++ src/categories.vala 2012-06-29 15:58:20 +0000
@@ -23,7 +23,8 @@
23 SONGS,23 SONGS,
24 ALBUMS,24 ALBUMS,
25 PURCHASE,25 PURCHASE,
26 MUSIC26 MUSIC,
27 RADIOS
27 }28 }
2829
29}30}
3031
=== modified file 'src/daemon.vala'
--- src/daemon.vala 2012-04-23 12:35:38 +0000
+++ src/daemon.vala 2012-06-29 15:58:20 +0000
@@ -74,7 +74,7 @@
74 filter.add_option ("1960", _("60s"));74 filter.add_option ("1960", _("60s"));
75 filter.add_option ("1970", _("70s"));75 filter.add_option ("1970", _("70s"));
76 filter.add_option ("1980", _("80s"));76 filter.add_option ("1980", _("80s"));
77 filter.add_option ("1990", _("90s"));77 filter.add_option ("1990", _("90s"));
78 filter.add_option ("2000", _("00s"));78 filter.add_option ("2000", _("00s"));
79 filter.add_option ("2010", _("10s"));79 filter.add_option ("2010", _("10s"));
8080
@@ -135,6 +135,10 @@
135 new FileIcon (icon_dir.get_child ("group-songs.svg")));135 new FileIcon (icon_dir.get_child ("group-songs.svg")));
136 categories.append (cat);136 categories.append (cat);
137137
138 cat = new Unity.Category (_("Radio"),
139 new FileIcon (icon_dir.get_child ("group-songs.svg")));
140 categories.append (cat);
141
138 lens.categories = categories;142 lens.categories = categories;
139 }143 }
140 }144 }
141145
=== modified file 'src/rhythmbox-collection.vala'
--- src/rhythmbox-collection.vala 2012-04-25 17:26:44 +0000
+++ src/rhythmbox-collection.vala 2012-06-29 15:58:20 +0000
@@ -26,6 +26,7 @@
2626
27 private enum Columns27 private enum Columns
28 {28 {
29 TYPE,
29 URI,30 URI,
30 TITLE,31 TITLE,
31 ARTIST,32 ARTIST,
@@ -43,7 +44,7 @@
4344
44 class RhythmboxCollection : Object45 class RhythmboxCollection : Object
45 {46 {
46 const string UNKNOWN_ALBUM = "Unknown";47 const string UNKNOWN_ALBUM = _("Unknown");
4748
48 SequenceModel all_tracks;49 SequenceModel all_tracks;
49 ModelTag<int> album_art_tag;50 ModelTag<int> album_art_tag;
@@ -56,7 +57,7 @@
5657
57 HashTable<unowned string, Variant> variant_store;58 HashTable<unowned string, Variant> variant_store;
58 HashTable<int, Variant> int_variant_store;59 HashTable<int, Variant> int_variant_store;
59 Variant row_buffer[11];60 Variant row_buffer[12];
6061
61 Analyzer analyzer;62 Analyzer analyzer;
62 Index? index;63 Index? index;
@@ -64,7 +65,7 @@
6465
65 string media_art_dir;66 string media_art_dir;
6667
67 class XmlParser: Object68 public class XmlParser: Object
68 {69 {
69 const MarkupParser parser =70 const MarkupParser parser =
70 {71 {
@@ -91,7 +92,7 @@
91 return context.parse (content, (ssize_t) len);92 return context.parse (content, (ssize_t) len);
92 }93 }
9394
94 bool processing_song;95 bool processing_track;
95 Track current_track;96 Track current_track;
96 int current_data = -1;97 int current_data = -1;
9798
@@ -99,21 +100,24 @@
99 [CCode (array_length = false, array_null_terminated = true)] string[] attr_names, [CCode (array_length = false, array_null_terminated = true)] string[] attr_values)100 [CCode (array_length = false, array_null_terminated = true)] string[] attr_names, [CCode (array_length = false, array_null_terminated = true)] string[] attr_values)
100 throws MarkupError101 throws MarkupError
101 {102 {
102 if (!processing_song)103 if (!processing_track)
103 {104 {
104 switch (name)105 switch (name)
105 {106 {
106 case "rhythmdb": is_rhythmdb_xml = true; break;107 case "rhythmdb": is_rhythmdb_xml = true; break;
107 case "entry":108 case "entry":
108 bool is_song = false;109 string accepted_element_name = null;
109 for (int i = 0; attr_names[i] != null; i++)110 for (int i = 0; attr_names[i] != null; i++)
110 {111 {
111 if (attr_names[i] == "type" && attr_values[i] == "song")112 if (attr_names[i] == "type" && (attr_values[i] == "song"
112 is_song = true;113 || attr_values[i] == "iradio"))
114 accepted_element_name = attr_values[i];
113 }115 }
114 if (!is_song) return;116 if (accepted_element_name == null) return;
115 processing_song = true;117 processing_track = true;
116 current_track = new Track ();118 current_track = new Track ();
119 current_track.type_track = accepted_element_name == "song" ?
120 TrackType.SONG : TrackType.RADIO;
117 break;121 break;
118 }122 }
119 }123 }
@@ -156,14 +160,14 @@
156 if (current_data >= 0) current_data = -1;160 if (current_data >= 0) current_data = -1;
157 break;161 break;
158 case "hidden":162 case "hidden":
159 if (processing_song) processing_song = false;163 if (processing_track) processing_track = false;
160 break;164 break;
161 case "entry":165 case "entry":
162 if (processing_song && current_track != null)166 if (processing_track && current_track != null)
163 {167 {
164 track_info_ready (current_track);168 track_info_ready (current_track);
165 }169 }
166 processing_song = false;170 processing_track = false;
167 break;171 break;
168 }172 }
169 }173 }
@@ -172,7 +176,7 @@
172 string text, size_t text_len)176 string text, size_t text_len)
173 throws MarkupError177 throws MarkupError
174 {178 {
175 if (!processing_song || current_data < 0) return;179 if (!processing_track || current_data < 0) return;
176 switch (current_data)180 switch (current_data)
177 {181 {
178 case Columns.URI: current_track.uri = text; break;182 case Columns.URI: current_track.uri = text; break;
@@ -203,7 +207,7 @@
203207
204 construct208 construct
205 {209 {
206 static_assert (11 == Columns.N_COLUMNS); // sync with row_buffer size210 static_assert (12 == Columns.N_COLUMNS); // sync with row_buffer size
207 media_art_dir = Path.build_filename (211 media_art_dir = Path.build_filename (
208 Environment.get_user_cache_dir (), "media-art");212 Environment.get_user_cache_dir (), "media-art");
209213
@@ -213,7 +217,7 @@
213 direct_equal);217 direct_equal);
214 all_tracks = new SequenceModel ();218 all_tracks = new SequenceModel ();
215 // the columns correspond to the Columns enum219 // the columns correspond to the Columns enum
216 all_tracks.set_schema ("s", "s", "s", "s", "s", "s",220 all_tracks.set_schema ("i", "s", "s", "s", "s", "s", "s",
217 "s", "s", "i", "i", "i");221 "s", "s", "i", "i", "i");
218 assert (all_tracks.get_schema ().length == Columns.N_COLUMNS);222 assert (all_tracks.get_schema ().length == Columns.N_COLUMNS);
219 album_art_tag = new ModelTag<int> (all_tracks);223 album_art_tag = new ModelTag<int> (all_tracks);
@@ -383,6 +387,7 @@
383387
384 private void prepare_row_buffer (Track track)388 private void prepare_row_buffer (Track track)
385 {389 {
390 Variant type = cached_variant_for_int (track.type_track);
386 Variant uri = new Variant.string (track.uri);391 Variant uri = new Variant.string (track.uri);
387 Variant title = new Variant.string (track.title);392 Variant title = new Variant.string (track.title);
388 Variant artist = cached_variant_for_string (track.artist);393 Variant artist = cached_variant_for_string (track.artist);
@@ -395,17 +400,18 @@
395 Variant year = cached_variant_for_int (track.year);400 Variant year = cached_variant_for_int (track.year);
396 Variant play_count = cached_variant_for_int (track.play_count);401 Variant play_count = cached_variant_for_int (track.play_count);
397402
398 row_buffer[0] = uri;403 row_buffer[0] = type;
399 row_buffer[1] = title;404 row_buffer[1] = uri;
400 row_buffer[2] = artist;405 row_buffer[2] = title;
401 row_buffer[3] = album;406 row_buffer[3] = artist;
402 row_buffer[4] = artwork;407 row_buffer[4] = album;
403 row_buffer[5] = mime_type;408 row_buffer[5] = artwork;
404 row_buffer[6] = genre;409 row_buffer[6] = mime_type;
405 row_buffer[7] = album_artist;410 row_buffer[7] = genre;
406 row_buffer[8] = track_number;411 row_buffer[8] = album_artist;
407 row_buffer[9] = year;412 row_buffer[9] = track_number;
408 row_buffer[10] = play_count;413 row_buffer[10] = year;
414 row_buffer[11] = play_count;
409 }415 }
410416
411 public void parse_metadata_file (string path)417 public void parse_metadata_file (string path)
@@ -475,7 +481,7 @@
475 prepare_row_buffer (track);481 prepare_row_buffer (track);
476 var iter = all_tracks.append_row (row_buffer);482 var iter = all_tracks.append_row (row_buffer);
477483
478 if (track.album == UNKNOWN_ALBUM) return;484 if (track.album == "" || track.album == UNKNOWN_ALBUM) return;
479 var album_key = "%s - %s".printf (track.album, track.album_artist != null ? track.album_artist : track.artist);485 var album_key = "%s - %s".printf (track.album, track.album_artist != null ? track.album_artist : track.artist);
480 var arr = album_to_tracks_map[album_key];486 var arr = album_to_tracks_map[album_key];
481 if (arr == null)487 if (arr == null)
@@ -520,7 +526,8 @@
520 private enum ResultType526 private enum ResultType
521 {527 {
522 ALBUM,528 ALBUM,
523 SONG529 SONG,
530 RADIO
524 }531 }
525532
526 private void add_result (Model results_model, Model model,533 private void add_result (Model results_model, Model model,
@@ -556,14 +563,15 @@
556 album_art_tag[model, iter] = current_album_art_tag;563 album_art_tag[model, iter] = current_album_art_tag;
557 }564 }
558565
559 var title_col = result_type == ResultType.SONG ?566 var title_col = (result_type == ResultType.SONG
567 || result_type == ResultType.RADIO) ?
560 Columns.TITLE : Columns.ALBUM;568 Columns.TITLE : Columns.ALBUM;
561 unowned string title = model.get_string (iter, title_col);569 unowned string title = model.get_string (iter, title_col);
562 var uri = model.get_string (iter, Columns.URI);570 var uri = model.get_string (iter, Columns.URI);
563 var dnd_uri = model.get_string (iter, Columns.URI);571 var dnd_uri = model.get_string (iter, Columns.URI);
564 if (result_type == ResultType.ALBUM)572 if (result_type == ResultType.ALBUM)
565 {573 {
566 if (title == UNKNOWN_ALBUM) return;574 if (title == "" || title == UNKNOWN_ALBUM) return;
567 unowned string artist = model.get_string (iter,575 unowned string artist = model.get_string (iter,
568 Columns.ALBUM_ARTIST);576 Columns.ALBUM_ARTIST);
569 if (artist == "")577 if (artist == "")
@@ -598,6 +606,7 @@
598 int min_year;606 int min_year;
599 int max_year;607 int max_year;
600 int category_id;608 int category_id;
609 ResultType result_type;
601610
602 Model model = all_tracks;611 Model model = all_tracks;
603 get_decade_filter (filters, out min_year, out max_year);612 get_decade_filter (filters, out min_year, out max_year);
@@ -639,26 +648,36 @@
639 }648 }
640 }649 }
641650
642 unowned string album = model.get_string (iter,651 if (model.get_int32 (iter, Columns.TYPE) == TrackType.SONG)
643 Columns.ALBUM);652 {
644 // it's not first as in track #1, but first found from album653 category_id = Category.SONGS;
645 bool first_track_from_album = !(album in albums_list_nosearch);654 result_type = ResultType.SONG;
646 albums_list_nosearch.add (album);655
647 656 unowned string album = model.get_string (iter,
648 if (first_track_from_album)657 Columns.ALBUM);
649 {658 // it's not first as in track #1, but first found from album
650 category_id = category_override >= 0 ?659 bool first_track_from_album = !(album in albums_list_nosearch);
651 category_override : Category.ALBUMS;660 albums_list_nosearch.add (album);
652 661
653 add_result (search.results_model, model, iter,662 if (first_track_from_album)
654 ResultType.ALBUM, category_id);663 {
655 }664 category_id = category_override >= 0 ?
656665 category_override : Category.ALBUMS;
657 category_id = category_override >= 0 ?666
658 category_override : Category.SONGS;667 add_result (search.results_model, model, iter,
659668 ResultType.ALBUM, category_id);
669 }
670 }
671 else
672 {
673 category_id = Category.RADIOS;
674 result_type = ResultType.RADIO;
675 }
676 if (category_override >= 0)
677 category_id = category_override;
678
660 add_result (helper_model, model, iter,679 add_result (helper_model, model, iter,
661 ResultType.SONG, category_id);680 result_type, category_id);
662681
663 num_results++;682 num_results++;
664 if (max_results >= 0 && num_results >= max_results) break;683 if (max_results >= 0 && num_results >= max_results) break;
@@ -730,27 +749,37 @@
730 }749 }
731 }750 }
732751
733 unowned string album = model.get_string (model_iter,752
734 Columns.ALBUM);753 if (model.get_int32 (model_iter, Columns.TYPE) == TrackType.SONG)
735754 {
736 // it's not first as in track #1, but first found from album755 category_id = Category.SONGS;
737 bool first_track_from_album = !(album in albums_list);756 result_type = ResultType.SONG;
738 albums_list.add (album);757
739758 unowned string album = model.get_string (model_iter,
740 if (first_track_from_album)759 Columns.ALBUM);
741 {760 // it's not first as in track #1, but first found from album
742 category_id = category_override >= 0 ?761 bool first_track_from_album = !(album in albums_list);
743 category_override : Category.ALBUMS;762 albums_list.add (album);
744763
745 add_result (search.results_model, model, model_iter,764 if (first_track_from_album)
746 ResultType.ALBUM, category_id);765 {
747 }766 category_id = category_override >= 0 ?
748767 category_override : Category.ALBUMS;
749 category_id = category_override >= 0 ?768
750 category_override : Category.SONGS;769 add_result (search.results_model, model, model_iter,
751770 ResultType.ALBUM, category_id);
771 }
772 }
773 else
774 {
775 category_id = Category.RADIOS;
776 result_type = ResultType.RADIO;
777 }
778 if (category_override >= 0)
779 category_id = category_override;
780
752 add_result (helper_model, model, model_iter,781 add_result (helper_model, model, model_iter,
753 ResultType.SONG, category_id);782 result_type, category_id);
754783
755 num_results++;784 num_results++;
756 if (max_results >= 0 && num_results >= max_results) break;785 if (max_results >= 0 && num_results >= max_results) break;
757786
=== modified file 'src/rhythmbox-scope.vala'
--- src/rhythmbox-scope.vala 2012-04-25 17:26:44 +0000
+++ src/rhythmbox-scope.vala 2012-06-29 15:58:20 +0000
@@ -68,7 +68,7 @@
68 yield;68 yield;
69 }69 }
70 /**70 /**
71 * Tells banshee to play the selected uri(s)71 * Tells rhythmbox to play the selected uri(s)
72 */72 */
73 public Unity.ActivationResponse activate (string uri)73 public Unity.ActivationResponse activate (string uri)
74 {74 {
7575
=== modified file 'src/track.vala'
--- src/track.vala 2012-03-27 13:31:14 +0000
+++ src/track.vala 2012-06-29 15:58:20 +0000
@@ -19,8 +19,15 @@
1919
20namespace Unity.MusicLens {20namespace Unity.MusicLens {
21 21
22 public enum TrackType
23 {
24 SONG,
25 RADIO
26 }
27
22 public class Track : GLib.Object28 public class Track : GLib.Object
23 {29 {
30 public TrackType type_track { get; set; }
24 public string title { get; set; }31 public string title { get; set; }
25 public string uri { get; set; }32 public string uri { get; set; }
26 public string artist { get; set; }33 public string artist { get; set; }
2734
=== added directory 'tests'
=== added file 'tests/Makefile.am'
--- tests/Makefile.am 1970-01-01 00:00:00 +0000
+++ tests/Makefile.am 2012-06-29 15:58:20 +0000
@@ -0,0 +1,45 @@
1check_PROGRAMS = test-rhythmbox-parser
2
3TESTS = $(check_PROGRAMS)
4
5AM_CPPFLAGS = \
6 -w \
7 $(LENS_DAEMON_CFLAGS) \
8 -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
9 -I$(top_srcdir)/src \
10 $(NULL)
11
12AM_VALAFLAGS = \
13 -C \
14 --pkg dee-1.0 \
15 --pkg gee-1.0 \
16 --pkg gio-2.0 \
17 --pkg gio-unix-2.0 \
18 --pkg glib-2.0 \
19 --vapidir $(top_srcdir)/src \
20 --pkg tdb \
21 --pkg unity \
22 $(srcdir)/assertions.vapi \
23 $(NULL)
24
25test_libs = \
26 $(LENS_DAEMON_LIBS) \
27 $(NULL)
28
29test_rhythmbox_parser_LDADD = $(test_libs)
30
31test_rhythmbox_parser_SOURCES = \
32 test-rhythmbox-parser.vala \
33 $(top_srcdir)/src/album.vala \
34 $(top_srcdir)/src/categories.vala \
35 $(top_srcdir)/src/config.vala \
36 $(top_srcdir)/src/filter-parser.vala \
37 $(top_srcdir)/src/filter-parser-decade.vala \
38 $(top_srcdir)/src/filter-parser-genre.vala \
39 $(top_srcdir)/src/genre.vala \
40 $(top_srcdir)/src/rhythmbox-collection.vala \
41 $(top_srcdir)/src/track.vala \
42 $(NULL)
43
44CLEANFILES = *.stamp
45
046
=== added file 'tests/assertions.vapi'
--- tests/assertions.vapi 1970-01-01 00:00:00 +0000
+++ tests/assertions.vapi 2012-06-29 15:58:20 +0000
@@ -0,0 +1,23 @@
1[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h")]
2namespace Assertions {
3 public enum OperatorType {
4 [CCode (cname = "==")]
5 EQUAL,
6 [CCode (cname = "!=")]
7 NOT_EQUAL,
8 [CCode (cname = "<")]
9 LESS_THAN,
10 [CCode (cname = ">")]
11 GREATER_THAN,
12 [CCode (cname = "<=")]
13 LESS_OR_EQUAL,
14 [CCode (cname = ">=")]
15 GREATER_OR_EQUAL
16 }
17
18 public void assert_cmpstr (string? s1, OperatorType op, string? s2);
19 public void assert_cmpint (int n1, OperatorType op, int n2);
20 public void assert_cmpuint (uint n1, OperatorType op, uint n2);
21 public void assert_cmphex (uint n1, OperatorType op, uint n2);
22 public void assert_cmpfloat (float n1, OperatorType op, float n2);
23}
024
=== added file 'tests/test-rhythmbox-parser.vala'
--- tests/test-rhythmbox-parser.vala 1970-01-01 00:00:00 +0000
+++ tests/test-rhythmbox-parser.vala 2012-06-29 15:58:20 +0000
@@ -0,0 +1,170 @@
1/*
2 * Copyright (C) 2012 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by Didier Roche <didrocks@ubuntu.com>
17 *
18 */
19
20using Unity.MusicLens;
21using Assertions;
22
23public class Main
24{
25 public static int main (string[] args)
26 {
27 Test.init (ref args);
28
29 Test.add_data_func ("/Unit/ParserChecker/Radios", test_radios);
30 Test.add_data_func ("/Unit/ParserChecker/Songs", test_songs);
31 Test.add_data_func ("/Unit/ParserChecker/LazyLoad", test_lazy_load);
32 Test.add_data_func ("/Unit/ParserChecker/LazyLoad", test_invalid_songload);
33
34 Test.run ();
35
36 return 0;
37 }
38
39 private static void test_radios ()
40 {
41 var parser = new RhythmboxCollection.XmlParser ();
42
43 string collection_to_parse = """<?xml version="1.0" standalone="yes"?>
44<rhythmdb version="1.8">
45 <entry type="iradio">
46 <title>Absolute Radio 80s (Modem)</title>
47 <genre>80's</genre>
48 <artist></artist>
49 <album></album>
50 <location>http://network.absoluteradio.co.uk/core/audio/ogg/live.pls?service=a8</location>
51 <play-count>6</play-count>
52 <last-played>1339693331</last-played>
53 <bitrate>32</bitrate>
54 <date>0</date>
55 <media-type>application/octet-stream</media-type>
56 </entry>
57</rhythmdb>""";
58
59 parser.track_info_ready.connect ((track) =>
60 {
61 assert_cmpstr (track.title, OperatorType.EQUAL, "Absolute Radio 80s (Modem)");
62 assert_cmpstr (track.genre, OperatorType.EQUAL, "other");
63 assert_cmpstr (track.artist, OperatorType.EQUAL, "");
64 assert_cmpstr (track.album, OperatorType.EQUAL, "");
65 assert_cmpstr (track.uri, OperatorType.EQUAL, "http://network.absoluteradio.co.uk/core/audio/ogg/live.pls?service=a8");
66 assert_cmpint (track.year, OperatorType.EQUAL, 0);
67 assert (track.type_track == TrackType.RADIO);
68 });
69 parser.parse(collection_to_parse, collection_to_parse.length);
70 }
71
72
73 private static void test_songs ()
74 {
75 var parser = new RhythmboxCollection.XmlParser ();
76
77 string collection_to_parse = """<?xml version="1.0" standalone="yes"?>
78<rhythmdb version="1.8">
79 <entry type="song">
80 <title>LA PASSION</title>
81 <genre>Dance</genre>
82 <artist>GIGI D'AGOSTINO</artist>
83 <album>Loulou 007</album>
84 <duration>228</duration>
85 <file-size>3661842</file-size>
86 <location>file:///home/moi/Gigi%20d'agostino%20Passion.mp3</location>
87 <mtime>1338273042</mtime>
88 <first-seen>1338536342</first-seen>
89 <last-seen>1340378542</last-seen>
90 <bitrate>128</bitrate>
91 <date>730142</date>
92 <media-type>audio/mpeg</media-type>
93 <comment>http://www.danceparadise.ca.tc</comment>
94 </entry>
95</rhythmdb>""";
96
97 parser.track_info_ready.connect ((track) =>
98 {
99 assert_cmpstr (track.title, OperatorType.EQUAL, "LA PASSION");
100 assert_cmpstr (track.genre, OperatorType.EQUAL, "techno");
101 assert_cmpstr (track.artist, OperatorType.EQUAL, "GIGI D'AGOSTINO");
102 assert_cmpstr (track.album, OperatorType.EQUAL, "Loulou 007");
103 assert_cmpstr (track.uri, OperatorType.EQUAL, "file:///home/moi/Gigi%20d'agostino%20Passion.mp3");
104 assert_cmpint (track.year, OperatorType.EQUAL, 2000);
105 assert_cmpstr (track.mime_type, OperatorType.EQUAL, "audio/mpeg");
106 assert (track.type_track == TrackType.SONG);
107 });
108 parser.parse(collection_to_parse, collection_to_parse.length);
109 }
110
111
112 private static void test_lazy_load ()
113 {
114 var parser = new RhythmboxCollection.XmlParser ();
115
116 string collection_to_parse_chunk = """<?xml version="1.0" standalone="yes"?>
117<rhythmdb version="1.8">
118 <entry type="song">
119 <title>LA PASSION</title>
120 <genre>Dance</genre>
121 <artist>GIGI D'AGOSTINO</artist>
122""";
123 parser.parse(collection_to_parse_chunk, collection_to_parse_chunk.length);
124
125 collection_to_parse_chunk = """
126 <album>Loulou 007</album>
127 <duration>228</duration>
128 <file-size>3661842</file-size>
129 <location>file:///home/moi/Gigi%20d'agostino%20Passion.mp3</location>
130 <mtime>1338273042</mtime>
131 <first-seen>1338536342</first-seen>
132 <last-seen>1340378542</last-seen>
133 <bitrate>128</bitrate>
134 <date>730142</date>
135 <media-type>audio/mpeg</media-type>
136 <comment>http://www.danceparadise.ca.tc</comment>
137 </entry>""";
138 parser.track_info_ready.connect ((track) =>
139 {
140 assert_cmpstr (track.title, OperatorType.EQUAL, "LA PASSION");
141 assert_cmpstr (track.album, OperatorType.EQUAL, "Loulou 007");
142 assert (track.type_track == TrackType.SONG);
143 });
144 parser.parse(collection_to_parse_chunk, collection_to_parse_chunk.length);
145 }
146
147
148 private static void test_invalid_songload ()
149 {
150 var parser = new RhythmboxCollection.XmlParser ();
151
152 string collection_to_parse_chunk = """<?xml version="1.0" standalone="yes"?>
153<rhythmdb version="1.8">
154 <entry type="song">
155 <title>LA PASSION</title>
156 <genre>Dance</genre>
157 <entry type="song">
158 <title>le poisson</title>
159 <genre>Dance</genre>
160 </entry>""";
161
162 parser.track_info_ready.connect ((track) =>
163 {
164 assert_cmpstr (track.title, OperatorType.EQUAL, "le poisson");
165 assert (track.type_track == TrackType.SONG);
166 });
167 parser.parse(collection_to_parse_chunk, collection_to_parse_chunk.length);
168 }
169
170}
0\ No newline at end of file171\ No newline at end of file

Subscribers

People subscribed via source and target branches