/
SmartPlayList.cpp
1282 lines (1156 loc) · 51.1 KB
/
SmartPlayList.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "SmartPlayList.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "filesystem/SmartPlaylistDirectory.h"
#include "filesystem/File.h"
#include "utils/CharsetConverter.h"
#include "utils/DatabaseUtils.h"
#include "utils/JSONVariantParser.h"
#include "utils/JSONVariantWriter.h"
#include "utils/URIUtils.h"
#include "utils/Variant.h"
#include "utils/XMLUtils.h"
#include "video/VideoDatabase.h"
#include "Util.h"
#include "XBDateTime.h"
#include "guilib/LocalizeStrings.h"
using namespace std;
using namespace XFILE;
typedef struct
{
char string[17];
Field field;
SortBy sort;
CSmartPlaylistRule::FIELD_TYPE type;
int localizedString;
} translateField;
static const translateField fields[] = {
{ "none", FieldNone, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 231 },
{ "filename", FieldFilename, SortByFile, CSmartPlaylistRule::TEXT_FIELD, 561 },
{ "path", FieldPath, SortByPath, CSmartPlaylistRule::BROWSEABLE_FIELD, 573 },
{ "album", FieldAlbum, SortByAlbum, CSmartPlaylistRule::BROWSEABLE_FIELD, 558 },
{ "albumartist", FieldAlbumArtist, SortByNone, CSmartPlaylistRule::BROWSEABLE_FIELD, 566 },
{ "artist", FieldArtist, SortByArtist, CSmartPlaylistRule::BROWSEABLE_FIELD, 557 },
{ "tracknumber", FieldTrackNumber, SortByTrackNumber, CSmartPlaylistRule::NUMERIC_FIELD, 554 },
{ "comment", FieldComment, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 569 },
{ "review", FieldReview, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 183 },
{ "themes", FieldThemes, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 21895 },
{ "moods", FieldMoods, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 175 },
{ "styles", FieldStyles, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 176 },
{ "type", FieldAlbumType, SortByAlbumType, CSmartPlaylistRule::TEXT_FIELD, 564 },
{ "label", FieldMusicLabel, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 21899 },
{ "title", FieldTitle, SortByTitle, CSmartPlaylistRule::TEXT_FIELD, 556 },
{ "sorttitle", FieldSortTitle, SortBySortTitle, CSmartPlaylistRule::TEXT_FIELD, 556 },
{ "year", FieldYear, SortByYear, CSmartPlaylistRule::BROWSEABLE_FIELD, 562 },
{ "time", FieldTime, SortByTime, CSmartPlaylistRule::SECONDS_FIELD, 180 },
{ "playcount", FieldPlaycount, SortByPlaycount, CSmartPlaylistRule::NUMERIC_FIELD, 567 },
{ "lastplayed", FieldLastPlayed, SortByLastPlayed, CSmartPlaylistRule::DATE_FIELD, 568 },
{ "inprogress", FieldInProgress, SortByNone, CSmartPlaylistRule::BOOLEAN_FIELD, 575 },
{ "rating", FieldRating, SortByRating, CSmartPlaylistRule::NUMERIC_FIELD, 563 },
{ "votes", FieldVotes, SortByVotes, CSmartPlaylistRule::TEXT_FIELD, 205 },
{ "top250", FieldTop250, SortByTop250, CSmartPlaylistRule::NUMERIC_FIELD, 13409 },
{ "mpaarating", FieldMPAA, SortByMPAA, CSmartPlaylistRule::TEXT_FIELD, 20074 },
{ "dateadded", FieldDateAdded, SortByDateAdded, CSmartPlaylistRule::DATE_FIELD, 570 },
{ "genre", FieldGenre, SortByGenre, CSmartPlaylistRule::BROWSEABLE_FIELD, 515 },
{ "plot", FieldPlot, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 207 },
{ "plotoutline", FieldPlotOutline, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 203 },
{ "tagline", FieldTagline, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 202 },
{ "set", FieldSet, SortByNone, CSmartPlaylistRule::BROWSEABLE_FIELD, 20457 },
{ "director", FieldDirector, SortByNone, CSmartPlaylistRule::BROWSEABLE_FIELD, 20339 },
{ "actor", FieldActor, SortByNone, CSmartPlaylistRule::BROWSEABLE_FIELD, 20337 },
{ "writers", FieldWriter, SortByNone, CSmartPlaylistRule::BROWSEABLE_FIELD, 20417 },
{ "airdate", FieldAirDate, SortByYear, CSmartPlaylistRule::DATE_FIELD, 20416 },
{ "hastrailer", FieldTrailer, SortByNone, CSmartPlaylistRule::BOOLEAN_FIELD, 20423 },
{ "studio", FieldStudio, SortByStudio, CSmartPlaylistRule::BROWSEABLE_FIELD, 572 },
{ "country", FieldCountry, SortByCountry, CSmartPlaylistRule::BROWSEABLE_FIELD, 574 },
{ "tvshow", FieldTvShowTitle, SortByTvShowTitle, CSmartPlaylistRule::BROWSEABLE_FIELD, 20364 },
{ "status", FieldTvShowStatus, SortByTvShowStatus, CSmartPlaylistRule::TEXT_FIELD, 126 },
{ "season", FieldSeason, SortBySeason, CSmartPlaylistRule::NUMERIC_FIELD, 20373 },
{ "episode", FieldEpisodeNumber, SortByEpisodeNumber, CSmartPlaylistRule::NUMERIC_FIELD, 20359 },
{ "numepisodes", FieldNumberOfEpisodes, SortByNumberOfEpisodes, CSmartPlaylistRule::NUMERIC_FIELD, 20360 },
{ "numwatched", FieldNumberOfWatchedEpisodes, SortByNumberOfWatchedEpisodes, CSmartPlaylistRule::NUMERIC_FIELD, 21441 },
{ "videoresolution", FieldVideoResolution, SortByVideoResolution, CSmartPlaylistRule::NUMERIC_FIELD, 21443 },
{ "videocodec", FieldVideoCodec, SortByVideoCodec, CSmartPlaylistRule::TEXTIN_FIELD, 21445 },
{ "videoaspect", FieldVideoAspectRatio, SortByVideoAspectRatio, CSmartPlaylistRule::NUMERIC_FIELD, 21374 },
{ "audiochannels", FieldAudioChannels, SortByAudioChannels, CSmartPlaylistRule::NUMERIC_FIELD, 21444 },
{ "audiocodec", FieldAudioCodec, SortByAudioCodec, CSmartPlaylistRule::TEXTIN_FIELD, 21446 },
{ "audiolanguage", FieldAudioLanguage, SortByAudioLanguage, CSmartPlaylistRule::TEXTIN_FIELD, 21447 },
{ "subtitlelanguage", FieldSubtitleLanguage, SortBySubtitleLanguage, CSmartPlaylistRule::TEXTIN_FIELD, 21448 },
{ "random", FieldRandom, SortByRandom, CSmartPlaylistRule::TEXT_FIELD, 590 },
{ "playlist", FieldPlaylist, SortByPlaylistOrder, CSmartPlaylistRule::PLAYLIST_FIELD, 559 },
{ "tag", FieldTag, SortByNone, CSmartPlaylistRule::BROWSEABLE_FIELD, 20459 },
{ "instruments", FieldInstruments, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 21892 },
{ "biography", FieldBiography, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 21887 },
{ "born", FieldBorn, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 21893 },
{ "bandformed", FieldBandFormed, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 21894 },
{ "disbanded", FieldDisbanded, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 21896 },
{ "died", FieldDied, SortByNone, CSmartPlaylistRule::TEXT_FIELD, 21897 }
};
#define NUM_FIELDS sizeof(fields) / sizeof(translateField)
typedef struct
{
char string[15];
CSmartPlaylistRule::SEARCH_OPERATOR op;
int localizedString;
} operatorField;
static const operatorField operators[] = { { "contains", CSmartPlaylistRule::OPERATOR_CONTAINS, 21400 },
{ "doesnotcontain", CSmartPlaylistRule::OPERATOR_DOES_NOT_CONTAIN, 21401 },
{ "is", CSmartPlaylistRule::OPERATOR_EQUALS, 21402 },
{ "isnot", CSmartPlaylistRule::OPERATOR_DOES_NOT_EQUAL, 21403 },
{ "startswith", CSmartPlaylistRule::OPERATOR_STARTS_WITH, 21404 },
{ "endswith", CSmartPlaylistRule::OPERATOR_ENDS_WITH, 21405 },
{ "greaterthan", CSmartPlaylistRule::OPERATOR_GREATER_THAN, 21406 },
{ "lessthan", CSmartPlaylistRule::OPERATOR_LESS_THAN, 21407 },
{ "after", CSmartPlaylistRule::OPERATOR_AFTER, 21408 },
{ "before", CSmartPlaylistRule::OPERATOR_BEFORE, 21409 },
{ "inthelast", CSmartPlaylistRule::OPERATOR_IN_THE_LAST, 21410 },
{ "notinthelast", CSmartPlaylistRule::OPERATOR_NOT_IN_THE_LAST, 21411 },
{ "true", CSmartPlaylistRule::OPERATOR_TRUE, 20122 },
{ "false", CSmartPlaylistRule::OPERATOR_FALSE, 20424 }
};
#define NUM_OPERATORS sizeof(operators) / sizeof(operatorField)
CSmartPlaylistRule::CSmartPlaylistRule()
{
m_field = FieldNone;
m_operator = OPERATOR_CONTAINS;
m_parameter.clear();
}
bool CSmartPlaylistRule::Load(TiXmlElement *element, const CStdString &encoding /* = "UTF-8" */)
{
if (element == NULL)
return false;
// format is:
// <rule field="Genre" operator="contains">parameter</rule>
// where parameter can either be a string or a list of
// <value> tags containing a string
const char *field = element->Attribute("field");
const char *oper = element->Attribute("operator");
if (field == NULL || oper == NULL)
return false;
m_field = TranslateField(field);
m_operator = TranslateOperator(oper);
if (m_operator == OPERATOR_TRUE || m_operator == OPERATOR_FALSE)
return true;
TiXmlNode *parameter = element->FirstChild();
if (parameter == NULL)
return false;
if (parameter->Type() == TiXmlNode::TINYXML_TEXT)
{
CStdString utf8Parameter;
if (encoding.IsEmpty()) // utf8
utf8Parameter = parameter->ValueStr();
else
g_charsetConverter.stringCharsetToUtf8(encoding, parameter->ValueStr(), utf8Parameter);
if (!utf8Parameter.empty())
m_parameter.push_back(utf8Parameter);
}
else if (parameter->Type() == TiXmlNode::TINYXML_ELEMENT)
{
TiXmlElement *valueElem = element->FirstChildElement("value");
while (valueElem != NULL)
{
TiXmlNode *value = valueElem->FirstChild();
if (value != NULL && value->Type() == TiXmlNode::TINYXML_TEXT)
{
CStdString utf8Parameter;
if (encoding.IsEmpty()) // utf8
utf8Parameter = value->ValueStr();
else
g_charsetConverter.stringCharsetToUtf8(encoding, value->ValueStr(), utf8Parameter);
if (!utf8Parameter.empty())
m_parameter.push_back(utf8Parameter);
}
valueElem = valueElem->NextSiblingElement("value");
}
}
else
return false;
return true;
}
bool CSmartPlaylistRule::Load(const CVariant &obj)
{
if (!obj.isObject() ||
!obj.isMember("field") || !obj["field"].isString() ||
!obj.isMember("operator") || !obj["operator"].isString())
return false;
m_field = TranslateField(obj["field"].asString().c_str());
m_operator = TranslateOperator(obj["operator"].asString().c_str());
if (m_operator == OPERATOR_TRUE || m_operator == OPERATOR_FALSE)
return true;
if (!obj.isMember("value") || (!obj["value"].isString() && !obj["value"].isArray()))
return false;
const CVariant &value = obj["value"];
if (value.isString() && !value.asString().empty())
m_parameter.push_back(value.asString());
else if (value.isArray())
{
for (CVariant::const_iterator_array val = value.begin_array(); val != value.end_array(); val++)
{
if (val->isString() && !val->asString().empty())
m_parameter.push_back(val->asString());
}
}
else
return false;
return true;
}
bool CSmartPlaylistRule::Save(TiXmlNode *parent) const
{
if (parent == NULL || (m_parameter.empty() && m_operator != OPERATOR_TRUE && m_operator != OPERATOR_FALSE))
return false;
TiXmlElement rule("rule");
rule.SetAttribute("field", TranslateField(m_field).c_str());
rule.SetAttribute("operator", TranslateOperator(m_operator).c_str());
for (vector<CStdString>::const_iterator it = m_parameter.begin(); it != m_parameter.end(); it++)
{
TiXmlElement value("value");
TiXmlText text(it->c_str());
value.InsertEndChild(text);
rule.InsertEndChild(value);
}
parent->InsertEndChild(rule);
return true;
}
bool CSmartPlaylistRule::Save(CVariant &obj) const
{
if (obj.isNull() || (m_parameter.empty() && m_operator != OPERATOR_TRUE && m_operator != OPERATOR_FALSE))
return false;
CVariant rule(CVariant::VariantTypeObject);
rule["field"] = TranslateField(m_field);
rule["operator"] = TranslateOperator(m_operator);
rule["value"] = CVariant(CVariant::VariantTypeArray);
for (vector<CStdString>::const_iterator it = m_parameter.begin(); it != m_parameter.end(); it++)
rule["value"].push_back(*it);
obj.push_back(rule);
return true;
}
Field CSmartPlaylistRule::TranslateField(const char *field)
{
for (unsigned int i = 0; i < NUM_FIELDS; i++)
if (strcmpi(field, fields[i].string) == 0) return fields[i].field;
return FieldNone;
}
CStdString CSmartPlaylistRule::TranslateField(Field field)
{
for (unsigned int i = 0; i < NUM_FIELDS; i++)
if (field == fields[i].field) return fields[i].string;
return "none";
}
SortBy CSmartPlaylistRule::TranslateOrder(const char *order)
{
for (unsigned int i = 0; i < NUM_FIELDS; i++)
if (strcmpi(order, fields[i].string) == 0) return fields[i].sort;
return SortByNone;
}
CStdString CSmartPlaylistRule::TranslateOrder(SortBy order)
{
for (unsigned int i = 0; i < NUM_FIELDS; i++)
if (order == fields[i].sort) return fields[i].string;
return "none";
}
CSmartPlaylistRule::SEARCH_OPERATOR CSmartPlaylistRule::TranslateOperator(const char *oper)
{
for (unsigned int i = 0; i < NUM_OPERATORS; i++)
if (strcmpi(oper, operators[i].string) == 0) return operators[i].op;
return OPERATOR_CONTAINS;
}
CStdString CSmartPlaylistRule::TranslateOperator(SEARCH_OPERATOR oper)
{
for (unsigned int i = 0; i < NUM_OPERATORS; i++)
if (oper == operators[i].op) return operators[i].string;
return "contains";
}
CStdString CSmartPlaylistRule::GetLocalizedField(Field field)
{
for (unsigned int i = 0; i < NUM_FIELDS; i++)
if (field == fields[i].field) return g_localizeStrings.Get(fields[i].localizedString);
return g_localizeStrings.Get(16018);
}
CStdString CSmartPlaylistRule::GetLocalizedOrder(SortBy order)
{
for (unsigned int i = 0; i < NUM_FIELDS; i++)
if (order == fields[i].sort) return g_localizeStrings.Get(fields[i].localizedString);
return g_localizeStrings.Get(16018);
}
CSmartPlaylistRule::FIELD_TYPE CSmartPlaylistRule::GetFieldType(Field field)
{
for (unsigned int i = 0; i < NUM_FIELDS; i++)
if (field == fields[i].field) return fields[i].type;
return TEXT_FIELD;
}
vector<Field> CSmartPlaylistRule::GetFields(const CStdString &type)
{
vector<Field> fields;
bool isVideo = false;
if (type == "songs")
{
fields.push_back(FieldGenre);
fields.push_back(FieldAlbum);
fields.push_back(FieldArtist);
fields.push_back(FieldAlbumArtist);
fields.push_back(FieldTitle);
fields.push_back(FieldYear);
fields.push_back(FieldTime);
fields.push_back(FieldTrackNumber);
fields.push_back(FieldFilename);
fields.push_back(FieldPath);
fields.push_back(FieldPlaycount);
fields.push_back(FieldLastPlayed);
fields.push_back(FieldRating);
fields.push_back(FieldComment);
fields.push_back(FieldDateAdded);
}
else if (type == "albums")
{
fields.push_back(FieldGenre);
fields.push_back(FieldAlbum);
fields.push_back(FieldArtist); // any artist
fields.push_back(FieldAlbumArtist); // album artist
fields.push_back(FieldYear);
fields.push_back(FieldReview);
fields.push_back(FieldThemes);
fields.push_back(FieldMoods);
fields.push_back(FieldStyles);
fields.push_back(FieldAlbumType);
fields.push_back(FieldMusicLabel);
fields.push_back(FieldRating);
}
else if (type == "artists")
{
fields.push_back(FieldArtist);
fields.push_back(FieldGenre);
fields.push_back(FieldMoods);
fields.push_back(FieldStyles);
fields.push_back(FieldInstruments);
fields.push_back(FieldBiography);
fields.push_back(FieldBorn);
fields.push_back(FieldBandFormed);
fields.push_back(FieldDisbanded);
fields.push_back(FieldDied);
}
else if (type == "tvshows")
{
fields.push_back(FieldTitle);
fields.push_back(FieldPlot);
fields.push_back(FieldTvShowStatus);
fields.push_back(FieldVotes);
fields.push_back(FieldRating);
fields.push_back(FieldYear);
fields.push_back(FieldGenre);
fields.push_back(FieldDirector);
fields.push_back(FieldActor);
fields.push_back(FieldNumberOfEpisodes);
fields.push_back(FieldNumberOfWatchedEpisodes);
fields.push_back(FieldPlaycount);
fields.push_back(FieldPath);
fields.push_back(FieldStudio);
fields.push_back(FieldMPAA);
fields.push_back(FieldDateAdded);
}
else if (type == "episodes")
{
fields.push_back(FieldTitle);
fields.push_back(FieldTvShowTitle);
fields.push_back(FieldPlot);
fields.push_back(FieldVotes);
fields.push_back(FieldRating);
fields.push_back(FieldTime);
fields.push_back(FieldWriter);
fields.push_back(FieldAirDate);
fields.push_back(FieldPlaycount);
fields.push_back(FieldLastPlayed);
fields.push_back(FieldInProgress);
fields.push_back(FieldGenre);
fields.push_back(FieldYear); // premiered
fields.push_back(FieldDirector);
fields.push_back(FieldActor);
fields.push_back(FieldEpisodeNumber);
fields.push_back(FieldSeason);
fields.push_back(FieldFilename);
fields.push_back(FieldPath);
fields.push_back(FieldStudio);
fields.push_back(FieldMPAA);
fields.push_back(FieldDateAdded);
isVideo = true;
}
else if (type == "movies")
{
fields.push_back(FieldTitle);
fields.push_back(FieldPlot);
fields.push_back(FieldPlotOutline);
fields.push_back(FieldTagline);
fields.push_back(FieldVotes);
fields.push_back(FieldRating);
fields.push_back(FieldTime);
fields.push_back(FieldWriter);
fields.push_back(FieldPlaycount);
fields.push_back(FieldLastPlayed);
fields.push_back(FieldInProgress);
fields.push_back(FieldGenre);
fields.push_back(FieldCountry);
fields.push_back(FieldYear); // premiered
fields.push_back(FieldDirector);
fields.push_back(FieldActor);
fields.push_back(FieldMPAA);
fields.push_back(FieldTop250);
fields.push_back(FieldStudio);
fields.push_back(FieldTrailer);
fields.push_back(FieldFilename);
fields.push_back(FieldPath);
fields.push_back(FieldSet);
fields.push_back(FieldTag);
fields.push_back(FieldDateAdded);
isVideo = true;
}
else if (type == "musicvideos")
{
fields.push_back(FieldTitle);
fields.push_back(FieldGenre);
fields.push_back(FieldAlbum);
fields.push_back(FieldYear);
fields.push_back(FieldArtist);
fields.push_back(FieldFilename);
fields.push_back(FieldPath);
fields.push_back(FieldPlaycount);
fields.push_back(FieldLastPlayed);
fields.push_back(FieldTime);
fields.push_back(FieldDirector);
fields.push_back(FieldStudio);
fields.push_back(FieldPlot);
fields.push_back(FieldDateAdded);
isVideo = true;
}
if (isVideo)
{
fields.push_back(FieldVideoResolution);
fields.push_back(FieldAudioChannels);
fields.push_back(FieldVideoCodec);
fields.push_back(FieldAudioCodec);
fields.push_back(FieldAudioLanguage);
fields.push_back(FieldSubtitleLanguage);
fields.push_back(FieldVideoAspectRatio);
}
fields.push_back(FieldPlaylist);
return fields;
}
std::vector<SortBy> CSmartPlaylistRule::GetOrders(const CStdString &type)
{
vector<SortBy> orders;
orders.push_back(SortByNone);
if (type == "songs")
{
orders.push_back(SortByGenre);
orders.push_back(SortByAlbum);
orders.push_back(SortByArtist);
orders.push_back(SortByTitle);
orders.push_back(SortByYear);
orders.push_back(SortByTime);
orders.push_back(SortByTrackNumber);
orders.push_back(SortByFile);
orders.push_back(SortByPath);
orders.push_back(SortByPlaycount);
orders.push_back(SortByLastPlayed);
orders.push_back(SortByRating);
}
else if (type == "albums")
{
orders.push_back(SortByGenre);
orders.push_back(SortByAlbum);
orders.push_back(SortByArtist); // any artist
orders.push_back(SortByYear);
//orders.push_back(SortByThemes);
//orders.push_back(SortByMoods);
//orders.push_back(SortByStyles);
orders.push_back(SortByAlbumType);
//orders.push_back(SortByMusicLabel);
orders.push_back(SortByRating);
}
else if (type == "artists")
{
orders.push_back(SortByArtist);
}
else if (type == "tvshows")
{
orders.push_back(SortBySortTitle);
orders.push_back(SortByTvShowStatus);
orders.push_back(SortByVotes);
orders.push_back(SortByRating);
orders.push_back(SortByYear);
orders.push_back(SortByGenre);
orders.push_back(SortByNumberOfEpisodes);
orders.push_back(SortByNumberOfWatchedEpisodes);
//orders.push_back(SortByPlaycount);
orders.push_back(SortByPath);
orders.push_back(SortByStudio);
orders.push_back(SortByMPAA);
orders.push_back(SortByDateAdded);
}
else if (type == "episodes")
{
orders.push_back(SortByTitle);
orders.push_back(SortByTvShowTitle);
orders.push_back(SortByVotes);
orders.push_back(SortByRating);
orders.push_back(SortByTime);
orders.push_back(SortByPlaycount);
orders.push_back(SortByLastPlayed);
orders.push_back(SortByYear); // premiered/dateaired
orders.push_back(SortByEpisodeNumber);
orders.push_back(SortBySeason);
orders.push_back(SortByFile);
orders.push_back(SortByPath);
orders.push_back(SortByStudio);
orders.push_back(SortByMPAA);
orders.push_back(SortByDateAdded);
}
else if (type == "movies")
{
orders.push_back(SortBySortTitle);
orders.push_back(SortByVotes);
orders.push_back(SortByRating);
orders.push_back(SortByTime);
orders.push_back(SortByPlaycount);
orders.push_back(SortByLastPlayed);
orders.push_back(SortByGenre);
orders.push_back(SortByCountry);
orders.push_back(SortByYear); // premiered
orders.push_back(SortByMPAA);
orders.push_back(SortByTop250);
orders.push_back(SortByStudio);
orders.push_back(SortByFile);
orders.push_back(SortByPath);
orders.push_back(SortByDateAdded);
}
else if (type == "musicvideos")
{
orders.push_back(SortByTitle);
orders.push_back(SortByGenre);
orders.push_back(SortByAlbum);
orders.push_back(SortByYear);
orders.push_back(SortByArtist);
orders.push_back(SortByFile);
orders.push_back(SortByPath);
orders.push_back(SortByPlaycount);
orders.push_back(SortByLastPlayed);
orders.push_back(SortByTime);
orders.push_back(SortByStudio);
orders.push_back(SortByDateAdded);
}
orders.push_back(SortByRandom);
return orders;
}
CStdString CSmartPlaylistRule::GetLocalizedOperator(SEARCH_OPERATOR oper)
{
for (unsigned int i = 0; i < NUM_OPERATORS; i++)
if (oper == operators[i].op) return g_localizeStrings.Get(operators[i].localizedString);
return g_localizeStrings.Get(16018);
}
CStdString CSmartPlaylistRule::GetLocalizedRule(const CStdString &type) const
{
CStdString rule;
rule.Format("%s %s %s", GetLocalizedField(m_field).c_str(), GetLocalizedOperator(m_operator).c_str(), GetLocalizedParameter(type).c_str());
return rule;
}
CStdString CSmartPlaylistRule::GetLocalizedParameter(const CStdString &type) const
{
return StringUtils::JoinString(m_parameter, " / ");
}
CStdString CSmartPlaylistRule::GetVideoResolutionQuery(const CStdString ¶meter) const
{
CStdString retVal(" in (select distinct idFile from streamdetails where iVideoWidth ");
int iRes = (int)strtol(parameter.c_str(), NULL, 10);
int min, max;
if (iRes >= 1080) { min = 1281; max = INT_MAX; }
else if (iRes >= 720) { min = 961; max = 1280; }
else if (iRes >= 540) { min = 721; max = 960; }
else { min = 0; max = 720; }
switch (m_operator)
{
case OPERATOR_EQUALS:
retVal.AppendFormat(">= %i and iVideoWidth <= %i)", min, max);
break;
case OPERATOR_DOES_NOT_EQUAL:
retVal.AppendFormat("< %i or iVideoWidth > %i)", min, max);
break;
case OPERATOR_LESS_THAN:
retVal.AppendFormat("< %i)", min);
break;
case OPERATOR_GREATER_THAN:
retVal.AppendFormat("> %i)", max);
break;
default:
retVal += ")";
break;
}
return retVal;
}
CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdString& strType) const
{
SEARCH_OPERATOR op = m_operator;
if ((strType == "tvshows" || strType == "episodes") && m_field == FieldYear)
{ // special case for premiered which is a date rather than a year
// TODO: SMARTPLAYLISTS do we really need this, or should we just make this field the premiered date and request a date?
if (op == OPERATOR_EQUALS)
op = OPERATOR_CONTAINS;
else if (op == OPERATOR_DOES_NOT_EQUAL)
op = OPERATOR_DOES_NOT_CONTAIN;
}
CStdString operatorString, negate;
if (GetFieldType(m_field) == TEXTIN_FIELD)
{
if (op == OPERATOR_DOES_NOT_EQUAL)
negate = " NOT";
}
else
{
// the comparison piece
switch (op)
{
case OPERATOR_CONTAINS:
operatorString = " LIKE '%%%s%%'"; break;
case OPERATOR_DOES_NOT_CONTAIN:
negate = " NOT"; operatorString = " LIKE '%%%s%%'"; break;
case OPERATOR_EQUALS:
operatorString = " LIKE '%s'"; break;
case OPERATOR_DOES_NOT_EQUAL:
negate = " NOT"; operatorString = " LIKE '%s'"; break;
case OPERATOR_STARTS_WITH:
operatorString = " LIKE '%s%%'"; break;
case OPERATOR_ENDS_WITH:
operatorString = " LIKE '%%%s'"; break;
case OPERATOR_AFTER:
case OPERATOR_GREATER_THAN:
case OPERATOR_IN_THE_LAST:
operatorString = " > '%s'"; break;
case OPERATOR_BEFORE:
case OPERATOR_LESS_THAN:
case OPERATOR_NOT_IN_THE_LAST:
operatorString = " < '%s'"; break;
case OPERATOR_TRUE:
operatorString = " = 1"; break;
case OPERATOR_FALSE:
negate = " NOT "; operatorString = " = 0"; break;
default:
break;
}
}
// boolean operators don't have any values in m_parameter, they work on the operator
if (m_operator == OPERATOR_FALSE || m_operator == OPERATOR_TRUE)
{
if (strType == "movies")
{
if (m_field == FieldInProgress)
return "movieview.idFile " + negate + " IN (select idFile from bookmark where type = 1)";
else if (m_field == FieldTrailer)
return negate + GetField(m_field, strType) + "!= ''";
}
else if (strType == "episodes")
{
if (m_field == FieldInProgress)
return "episodeview.idFile " + negate + " IN (select idFile from bookmark where type = 1)";
}
}
// now the query parameter
CStdString wholeQuery;
for (vector<CStdString>::const_iterator it = m_parameter.begin(); it != m_parameter.end(); /* it++ is done further down */)
{
CStdString parameter;
if (GetFieldType(m_field) == TEXTIN_FIELD)
{
CStdStringArray split;
StringUtils::SplitString(*it, ",", split);
for (CStdStringArray::iterator itIn = split.begin(); itIn != split.end(); ++itIn)
{
if (!parameter.IsEmpty())
parameter += ",";
parameter += db.PrepareSQL("'%s'", (*itIn).Trim().c_str());
}
parameter = " IN (" + parameter + ")";
}
else
parameter = db.PrepareSQL(operatorString.c_str(), it->c_str());
if (GetFieldType(m_field) == DATE_FIELD)
{
if (m_operator == OPERATOR_IN_THE_LAST || m_operator == OPERATOR_NOT_IN_THE_LAST)
{ // translate time period
CDateTime date=CDateTime::GetCurrentDateTime();
CDateTimeSpan span;
span.SetFromPeriod(*it);
date-=span;
parameter = db.PrepareSQL(operatorString.c_str(), date.GetAsDBDate().c_str());
}
}
else if (m_field == FieldTime)
{ // translate time to seconds
CStdString seconds; seconds.Format("%i", StringUtils::TimeStringToSeconds(*it));
parameter = db.PrepareSQL(operatorString.c_str(), seconds.c_str());
}
CStdString query;
CStdString table;
if (strType == "songs")
{
table = "songview";
if (m_field == FieldGenre)
query = GetField(FieldId, strType) + negate + " IN (SELECT idSong FROM song_genre, genre WHERE song_genre.idGenre = genre.idGenre AND genre.strGenre" + parameter + ")";
else if (m_field == FieldArtist)
query = GetField(FieldId, strType) + negate + " IN (SELECT idSong FROM song_artist, artist WHERE song_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
else if (m_field == FieldAlbumArtist)
query = table + ".idAlbum" + negate + " IN (SELECT idAlbum FROM album_artist, artist WHERE album_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
else if (m_field == FieldLastPlayed && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
query = GetField(m_field, strType) + " is NULL or " + GetField(m_field, strType) + parameter;
}
else if (strType == "albums")
{
table = "albumview";
if (m_field == FieldGenre)
query = GetField(FieldId, strType) + negate + " IN (SELECT song.idAlbum FROM song, song_genre, genre WHERE song.idSong = song_genre.idSong AND song_genre.idGenre = genre.idGenre AND genre.strGenre" + parameter + ")";
else if (m_field == FieldArtist)
query = GetField(FieldId, strType) + negate + " IN (SELECT song.idAlbum FROM song, song_artist, artist WHERE song.idSong = song_artist.idSong AND song_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
else if (m_field == FieldAlbumArtist)
query = GetField(FieldId, strType) + negate + " IN (SELECT album_artist.idAlbum FROM album_artist, artist WHERE album_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
}
else if (strType == "movies")
{
table = "movieview";
if (m_field == FieldGenre)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM genrelinkmovie JOIN genre ON genre.idGenre=genrelinkmovie.idGenre WHERE genre.strGenre" + parameter + ")";
else if (m_field == FieldDirector)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM directorlinkmovie JOIN actors ON actors.idActor=directorlinkmovie.idDirector WHERE actors.strActor" + parameter + ")";
else if (m_field == FieldActor)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM actorlinkmovie JOIN actors ON actors.idActor=actorlinkmovie.idActor WHERE actors.strActor" + parameter + ")";
else if (m_field == FieldWriter)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM writerlinkmovie JOIN actors ON actors.idActor=writerlinkmovie.idWriter WHERE actors.strActor" + parameter + ")";
else if (m_field == FieldStudio)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM studiolinkmovie JOIN studio ON studio.idStudio=studiolinkmovie.idStudio WHERE studio.strStudio" + parameter + ")";
else if (m_field == FieldCountry)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM countrylinkmovie JOIN country ON country.idCountry=countrylinkmovie.idCountry WHERE country.strCountry" + parameter + ")";
else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
else if (m_field == FieldInProgress)
query = table + ".idFile " + negate + " IN (SELECT idFile FROM bookmark WHERE type = 1)";
else if (m_field == FieldSet)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM setlinkmovie JOIN sets ON sets.idSet=setlinkmovie.idSet WHERE sets.strSet" + parameter + ")";
else if (m_field == FieldTag)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMedia FROM taglinks JOIN tag ON tag.idTag = taglinks.idTag WHERE tag.strTag" + parameter + " AND taglinks.media_type = 'movie')";
}
else if (strType == "musicvideos")
{
table = "musicvideoview";
if (m_field == FieldGenre)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM genrelinkmusicvideo JOIN genre ON genre.idGenre=genrelinkmusicvideo.idGenre WHERE genre.strGenre" + parameter + ")";
else if (m_field == FieldArtist)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM artistlinkmusicvideo JOIN actors ON actors.idActor=artistlinkmusicvideo.idArtist WHERE actors.strActor" + parameter + ")";
else if (m_field == FieldStudio)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM studiolinkmusicvideo JOIN studio ON studio.idStudio=studiolinkmusicvideo.idStudio WHERE studio.strStudio" + parameter + ")";
else if (m_field == FieldDirector)
query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM directorlinkmusicvideo JOIN actors ON actors.idActor=directorlinkmusicvideo.idDirector WHERE actors.strActor" + parameter + ")";
else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
}
else if (strType == "tvshows")
{
table = "tvshowview";
if (m_field == FieldGenre)
query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM genrelinktvshow JOIN genre ON genre.idGenre=genrelinktvshow.idGenre WHERE genre.strGenre" + parameter + ")";
else if (m_field == FieldDirector)
query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM directorlinktvshow JOIN actors ON actors.idActor=directorlinktvshow.idDirector WHERE actors.strActor" + parameter + ")";
else if (m_field == FieldActor)
query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM actorlinktvshow JOIN actors ON actors.idActor=actorlinktvshow.idActor WHERE actors.strActor" + parameter + ")";
else if (m_field == FieldStudio)
query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM tvshowview WHERE " + GetField(m_field, strType) + parameter + ")";
else if (m_field == FieldMPAA)
query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM tvshowview WHERE " + GetField(m_field, strType) + parameter + ")";
else if (m_field == FieldDateAdded && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
query = GetField(FieldDateAdded, strType) + " IS NULL OR " + GetField(FieldDateAdded, strType) + parameter;
}
else if (strType == "episodes")
{
table = "episodeview";
if (m_field == FieldGenre)
query = table + ".idShow" + negate + " IN (SELECT idShow FROM genrelinktvshow JOIN genre ON genre.idGenre=genrelinktvshow.idGenre WHERE genre.strGenre" + parameter + ")";
else if (m_field == FieldDirector)
query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM directorlinkepisode JOIN actors ON actors.idActor=directorlinkepisode.idDirector WHERE actors.strActor" + parameter + ")";
else if (m_field == FieldActor)
query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM actorlinkepisode JOIN actors ON actors.idActor=actorlinkepisode.idActor WHERE actors.strActor" + parameter + ")";
else if (m_field == FieldWriter)
query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM writerlinkepisode JOIN actors ON actors.idActor=writerlinkepisode.idWriter WHERE actors.strActor" + parameter + ")";
else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
else if (m_field == FieldInProgress)
query = table + ".idFile " + negate + " IN (SELECT idFile FROM bookmark WHERE type = 1)";
else if (m_field == FieldStudio)
query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM episodeview WHERE strStudio" + parameter + ")";
else if (m_field == FieldMPAA)
query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM episodeview WHERE mpaa" + parameter + ")";
}
if (m_field == FieldVideoResolution)
query = table + ".idFile" + negate + GetVideoResolutionQuery(*it);
else if (m_field == FieldAudioChannels)
query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE iAudioChannels " + parameter + ")";
else if (m_field == FieldVideoCodec)
query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE strVideoCodec " + parameter + ")";
else if (m_field == FieldAudioCodec)
query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE strAudioCodec " + parameter + ")";
else if (m_field == FieldAudioLanguage)
query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE strAudioLanguage " + parameter + ")";
else if (m_field == FieldSubtitleLanguage)
query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE strSubtitleLanguage " + parameter + ")";
else if (m_field == FieldVideoAspectRatio)
query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE fVideoAspect " + parameter + ")";
if (m_field == FieldPlaycount && strType != "songs" && strType != "albums")
{ // playcount IS stored as NULL OR number IN video db
if ((m_operator == OPERATOR_EQUALS && it->Equals("0")) ||
(m_operator == OPERATOR_DOES_NOT_EQUAL && !it->Equals("0")) ||
(m_operator == OPERATOR_LESS_THAN))
{
CStdString field = GetField(FieldPlaycount, strType);
query = field + " IS NULL OR " + field + parameter;
}
}
if (query.IsEmpty() && m_field != FieldNone)
query = GetField(m_field,strType) + negate + parameter;
it++;
if (query.Equals(negate + parameter))
query = "1";
query = "(" + query + ")";
if (it != m_parameter.end())
query += " OR ";
wholeQuery += query;
}
return wholeQuery;
}
CStdString CSmartPlaylistRule::GetField(Field field, const CStdString& type)
{
return DatabaseUtils::GetField(field, DatabaseUtils::MediaTypeFromString(type), DatabaseQueryPartWhere);
}
CSmartPlaylist::CSmartPlaylist()
{
m_matchAllRules = true;
m_limit = 0;
m_orderField = SortByNone;
m_orderAscending = true;
m_playlistType = "songs"; // sane default
}
TiXmlElement *CSmartPlaylist::OpenAndReadName(const CStdString &path)
{
CFileStream file;
if (!file.Open(path))
{
CLog::Log(LOGERROR, "Error loading Smart playlist %s (failed to read file)", path.c_str());
return NULL;
}
m_xmlDoc.Clear();
file >> m_xmlDoc;
TiXmlElement *root = readName();
if (m_playlistName.empty())
{
m_playlistName = CUtil::GetTitleFromPath(path);
if (URIUtils::GetExtension(m_playlistName) == ".xsp")
URIUtils::RemoveExtension(m_playlistName);
}
return root;
}
TiXmlElement* CSmartPlaylist::readName()
{
if (m_xmlDoc.Error())
{
CLog::Log(LOGERROR, "Error loading Smart playlist (failed to parse xml: %s)", m_xmlDoc.ErrorDesc());
return NULL;
}
TiXmlElement *root = m_xmlDoc.RootElement();
if (!root || strcmpi(root->Value(),"smartplaylist") != 0)
{
CLog::Log(LOGERROR, "Error loading Smart playlist");
return NULL;
}
// load the playlist type
const char* type = root->Attribute("type");
if (type)
m_playlistType = type;
// backward compatibility:
if (m_playlistType == "music")
m_playlistType = "songs";
if (m_playlistType == "video")
m_playlistType = "musicvideos";
// load the playlist name
TiXmlHandle name = ((TiXmlHandle)root->FirstChild("name")).FirstChild();
if (name.Node())
m_playlistName = name.Node()->Value();
return root;
}
TiXmlElement *CSmartPlaylist::readNameFromXml(const CStdString &xml)
{
if (xml.empty())
{
CLog::Log(LOGERROR, "Error loading empty Smart playlist");
return NULL;
}
m_xmlDoc.Clear();
if (!m_xmlDoc.Parse(xml))
{
CLog::Log(LOGERROR, "Error loading Smart playlist (failed to parse xml: %s)", m_xmlDoc.ErrorDesc());
return NULL;
}
return readName();
}
bool CSmartPlaylist::Load(const CStdString &path)
{