-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcldataformat.py
3083 lines (2441 loc) · 140 KB
/
cldataformat.py
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#***************************************************************************
#* nepoogle - data format library. *
#* *
#* Copyright (C) 2011-2012 Ignacio Serantes <kde@aynoa.net> *
#* *
#* 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 of the License, 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 this program; if not, write to the *
#* Free Software Foundation, Inc., *
#* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
#***************************************************************************
import __builtin__
import datetime, fractions, os, re
from PyKDE4.kdeui import KIconLoader
from PyKDE4.nepomuk2 import Nepomuk2
from PyKDE4.soprano import Soprano
from clsparql import *
from lfunctions import *
from lglobals import *
_ = gettext.gettext
#BEGIN cldataformat.py
_CONST_ICON_DOLPHIN = 1
_CONST_ICON_KONQUEROR = 2
_CONST_ICON_PROPERTIES = 4
_CONST_ICON_REMOVE = 8
_CONST_ICON_SYSTEM_RUN = 16
# Order is relevant, is display order.
_CONST_ICONS_LIST = (_CONST_ICON_PROPERTIES, _CONST_ICON_REMOVE, \
_CONST_ICON_DOLPHIN, _CONST_ICON_KONQUEROR, \
_CONST_ICON_SYSTEM_RUN)
class cDataFormat():
cfgId = "Display"
columnsCount = 3
coverFileNames = ['cover.png', 'Cover.png', 'cover.jpg', 'Cover.jpg']
data = []
enableImageViewer = True
hiddenOntologiesInResults = ["kao", "rdfs:Resource"] # This hidden ontologies are for results view.
#hiddenOntologies = ["kext:unixFileGroup", "kext:unixFileMode", "kext:unixFileOwner", "nao:userVisible", "nao:annotation", "rdfs:comment", "nie:relatedTo"]
hiddenOntologies = ["kext:unixFileGroup", "kext:unixFileMode", "kext:unixFileOwner", "nao:hasSubResource", "nao:userVisible"]
#hiddenOntologiesInverse = ["nao:hasSubResource", "dces:contributor", "nco:contributor"]
hiddenOntologiesInverse = ["nao:hasSubResource"]
hiddenResults = 0
ignoredRowMark = "[#]"
maxPageNumber = 20
model = None
navegable = False
ontologyMusicAlbumCover = ONTOLOGY_MUSIC_ALBUM_COVER
outFormat = 1 # 1- Text, 2- Html
playlistShowWithOneElement = True
playlistDescendingOrderByAlbumYear = True
queryString = ""
readOnlyOntologies = ["kext:indexingLevel", "nie:url", "rdf:type"]
renderSize = 25
renderedDataRows = 0
renderedDataText = ""
renderedLines = []
showCopyHtmlLink = False
skippedOntologiesInResourceIsA = ["nao:hasSubResource"]
structure = []
uri = None
videojsEnabled = False
parent = None
# Sizes
screenWidth = 800
viewerColumnsWidth = (screenWidth - 100) / 2
playlistHeight = 200
playlistScrollHeight = 50
playlistWidth = viewerColumnsWidth
videoWidth = viewerColumnsWidth
videoHeight = int(0.5625*viewerColumnsWidth)
supportedAudioFormats = ("flac", "mp3", "ogg", "wav")
supportedImageFormats = QImageReader.supportedImageFormats() + ["nef"]
supportedVideoFormats = ("avi", "divx", "flv", "mkv", "mp4", "mpeg", "mpg", "tp", "ts", "vob", "webm", "wmv")
iconDelete = toUnicode(KIconLoader().iconPath('edit-delete', KIconLoader.Small))
iconDocumentInfo = toUnicode(KIconLoader().iconPath('documentinfo', KIconLoader.Small))
iconDocumentProp = toUnicode(KIconLoader().iconPath('document-properties', KIconLoader.Small))
iconEmblemLink = toUnicode(KIconLoader().iconPath('emblem-link', KIconLoader.Small))
iconFileManager = toUnicode(KIconLoader().iconPath('system-file-manager', KIconLoader.Small))
iconKIO = toUnicode(KIconLoader().iconPath('kde', KIconLoader.Small))
iconKonqueror = toUnicode(KIconLoader().iconPath('konqueror', KIconLoader.Small))
iconListAdd = toUnicode(KIconLoader().iconPath('list-add', KIconLoader.Small))
iconListRemove = toUnicode(KIconLoader().iconPath('list-remove', KIconLoader.Small))
iconNavigateFirst = toUnicode(KIconLoader().iconPath('go-first', KIconLoader.Toolbar))
iconNavigateLast = toUnicode(KIconLoader().iconPath('go-last', KIconLoader.Toolbar))
iconNavigateNext = toUnicode(KIconLoader().iconPath('go-next', KIconLoader.Toolbar))
iconNavigatePrevious = toUnicode(KIconLoader().iconPath('go-previous', KIconLoader.Toolbar))
iconNoCover = toUnicode(KIconLoader().iconPath('no_cover', KIconLoader.Desktop))
iconNoPhoto = toUnicode(KIconLoader().iconPath('no_photo', KIconLoader.Desktop))
iconNoSymbol = toUnicode(KIconLoader().iconPath('no_symbol', KIconLoader.Desktop))
iconNoVideoThumbnail = toUnicode(KIconLoader().iconPath('no_video_thumbnail', KIconLoader.Desktop))
iconPlaylistFirst = toUnicode(KIconLoader().iconPath('go-first-view', KIconLoader.Small))
iconPlaylistPrevious = toUnicode(KIconLoader().iconPath('go-previous-view', KIconLoader.Small))
iconPlaylistNext = toUnicode(KIconLoader().iconPath('go-next-view', KIconLoader.Small))
iconPlaylistLast = toUnicode(KIconLoader().iconPath('go-last-view', KIconLoader.Small))
iconProcessIdle = toUnicode(KIconLoader().iconPath('process-idle', KIconLoader.Small))
iconRatingEmpty = toUnicode(KIconLoader().iconPath('rating_empty', KIconLoader.Small))
iconRatingFull = toUnicode(KIconLoader().iconPath('rating_full', KIconLoader.Small))
iconRatingHalf = toUnicode(KIconLoader().iconPath('rating_half', KIconLoader.Small))
iconReindex = toUnicode(KIconLoader().iconPath('nepomuk', KIconLoader.Small))
iconSystemRun = toUnicode(KIconLoader().iconPath('system-run', KIconLoader.Small))
iconSystemSearch = toUnicode(KIconLoader().iconPath('system-search', KIconLoader.Small))
iconSystemSearchWeb = toUnicode(KIconLoader().iconPath('edit-web-search', KIconLoader.Small))
iconUnknown = toUnicode(KIconLoader().iconPath('unknown', KIconLoader.Small))
htmlHeader = "<html>\n" \
"<head>\n" \
"<title>%(title)s</title>\n" \
"<style type=\"text/css\">" \
" body {%(body_style)s}\n" \
" tr {%(tr_style)s}\n" \
" p {%(p_style)s}\n" \
"</style>\n" \
"<meta charset=\"UTF-8\" />" \
"%(scripts)s\n" \
"</head>\n" \
"<body>\n" \
% {"title": "%s", \
"scripts": "%s", \
"body_style": "font-size:small;", \
"p_style": "font-size:small;", \
"tr_style": "font-size:small;" \
}
htmlFooter = "</body>\n" \
"</html>"
htmlProgramInfo = PROGRAM_HTML_POWERED
htmlTableHeader = "<table style=\"text-align:left; width: 100%;\" " \
"border=\"1\" cellpadding=\"1\" cellspacing=\"0\">" \
"<tbody>\n"
htmlTableFooter = "</tbody></table>\n"
#TODO: This must be automatic.
# This is not automatically generated and is linked to self.columnsCount.
# To add a column self.columnsCount must be changed and this properties too.
# Search for columnsformat for more changes.
htmlTableColumn1 = "<td>%s</td>"
htmlTableColumn2 = "<td width=\"50px\">%s</td>"
htmlTableColumn3 = "<td width=\"65px\">%s</td>"
htmlTableRow = "<tr>" + htmlTableColumn1 + htmlTableColumn2 + htmlTableColumn3 + "</tr>"
htmlViewerTableHeader = "<table style=\"text-align:left; width: 100%%;\" " \
"border=\"0\" cellpadding=\"3\" cellspacing=\"0\">" \
"<tbody>\n"
htmlViewerTableFooter = "</tbody></table>\n"
htmlStyleIcon = "align=\"center\" border=\"0\" hspace=\"0\" vspace=\"0\" style=\"width: 14px; height: 14px;\""
#htmlStyleNavigate = "align=\"center\" border=\"0\" hspace=\"0\" vspace=\"0\" style=\"width: 20px; height: 20px;\""
htmlStyleNavigate = "align=\"center\" border=0 hspace=0 vspace=0"
htmlStyleNavigateDisabled = "align=\"center\" border=0 hspace=0 vspace=0 style=\"-webkit-filter: grayscale(100%);\""
htmlStadistics = "%(records)s records found in %(seconds).4f seconds." \
" HTML visualization built in %(sechtml).2f seconds." \
htmlLinkDelete = "<a title=\"Delete\" href=\"delete:/%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconDelete) \
+ "</a>"
htmlLinkDolphin = "<a title=\"Open with Dolphin\" href=\"dolp:/%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconFileManager) \
+ "</a>"
htmlLinkInfo = "<a title=\"%(uri)s\" href=\"%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconDocumentInfo) \
+ "</a>"
htmlLinkKonqueror = "<a title=\"Open with Konqueror\" href=\"konq:/%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconKonqueror) \
+ "</a>"
htmlLinkNavigateFirst = "<a title=\"Go %(to)s (%(hotkey)s)\" href=\"navigate:/%(to)s/navbutton\"><img %(style)s title=\"Go %(to)s (%(hotkey)s)\" src=\"file://%(icon)s\"></a>" \
% {"to": "first", "hotkey": "Ctrl+PgUp", "style": htmlStyleNavigate, "icon": iconNavigateFirst}
htmlLinkNavigateFirstDisabled = "<img %(style)s src=\"file://%(icon)s\">" % {"style": htmlStyleNavigateDisabled, "icon": iconNavigateFirst}
htmlLinkNavigateLast = "<a title=\"Go %(to)s (%(hotkey)s)\" href=\"navigate:/%(to)s/navbutton\"><img %(style)s title=\"Go %(to)s (%(hotkey)s)\" src=\"file://%(icon)s\"></a>" \
% {"to": "last", "hotkey": "Ctrl+PgDown", "style": htmlStyleNavigate, "icon": iconNavigateLast}
htmlLinkNavigateLastDisabled = "<img %(style)s src=\"file://%(icon)s\">" % {"style": htmlStyleNavigateDisabled, "icon": iconNavigateLast}
htmlLinkNavigatePrevious = "<a title=\"Go %(to)s (%(hotkey)s)\" href=\"navigate:/%(to)s/navbutton\"><img %(style)s title=\"Go %(to)s (%(hotkey)s)\" src=\"file://%(icon)s\"></a>" \
% {"to": "previous", "hotkey": "Ctrl+Left", "style": htmlStyleNavigate, "icon": iconNavigatePrevious}
htmlLinkNavigatePreviousDisabled = "<img %(style)s src=\"file://%(icon)s\">" % {"style": htmlStyleNavigateDisabled, "icon": iconNavigatePrevious}
htmlLinkNavigateNext = "<a title=\"Go %(to)s (%(hotkey)s)\" href=\"navigate:/%(to)s/navbutton\"><img %(style)s title=\"Go %(to)s (%(hotkey)s)\" src=\"file://%(icon)s\"></a>" \
% {"to": "next", "hotkey": "Ctrl+Right", "style": htmlStyleNavigate, "icon": iconNavigateNext}
htmlLinkNavigateNextDisabled = "<img %(style)s src=\"file://%(icon)s\">" % {"style": htmlStyleNavigateDisabled, "icon": iconNavigateNext}
htmlLinkOpenKIO = "<a title=\"Open location %(uri)s\" href=\"%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconKIO) \
+ "</a>"
htmlLinkOpenLocation = "<a title=\"Open location %(uri)s\" href=\"%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconFileManager) \
+ "</a>"
htmlLinkProperties = "<a title=\"Properties\" href=\"prop:/%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconDocumentInfo) \
+ "</a>"
htmlLinkRemove = "<a title=\"Remove resource%(hotkey)s\" href=\"remove:/%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconDelete) \
+ "</a>"
htmlLinkRemoveAll = "<a title=\"Remove all listed resources\" href=\"remove:/all\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconListRemove) \
+ "</a>"
htmlLinkRemoveOntology = "<a title=\"Remove ontology\" href=\"%s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconListRemove) \
+ "</a>"
htmlLinkSearch = "<a title=\"%(uri)s\" href=\"query:/%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconSystemSearch) \
+ "</a>"
htmlLinkSearchRender = "<img align=\"bottom\" border=\"0\" hspace=\"0\" vspace=\"0\" " \
"style=\"width: 14px; height: 14px;\" " \
" src=\"file://%s\">" % (iconSystemSearch)
htmlLinkSearchWebRender = "<img align=\"bottom\" border=\"0\" hspace=\"0\" vspace=\"0\" " \
"style=\"width: 14px; height: 14px;\" " \
" src=\"file://%s\">" % (iconSystemSearchWeb)
htmlLinkSystemRun = "<a title=\"Open file %(uri)s\" href=\"run:/%(uri)s\">" \
+ "<img %s src=\"file://%s\">" % (htmlStyleIcon, iconSystemRun) \
+ "</a>"
#TODO: columnsformat. This is linked to self.columnsCount.
ontologyFormat = [ \
[None, \
"{uri|l|of}%[<br /><b>Full name</b>: {nco:fullname}%]%[<br /><b>Label</b>: {nao:prefLabel}%]%[<br /><b>Title</b>: {nie:title}%]" \
"%[<br /><b>Url</b>: {nie:url|of|ol}%]" \
"%[<br /><b>Rating</b>: {nao:numericRating|x:rating}%]" \
"%[<br /><b>Description</b>: {nie:description}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["pimo:Topic", \
"{pimo:tagLabel|l}%[<br />Alternative labels: {nao:altLabel}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nao:Agent", \
"{uri|l|of}%[<br /><b>Identifier</b>: {nao:identifier}%] %[<b>Label</b>: {nao:prefLabel}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nao:Tag", \
"%[<img width=48 style='float:left; vertical-align:text-bottom;' src=\"{nao:hasSymbol->nie:url|1}\"'>%]" \
"{nao:prefLabel|l|of|ol|s:hasTag}%[<br />Alternative labels: {nao:altLabel}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nco:Contact", \
"%[<img width=48 style='float:left; vertical-align:text-bottom;' src=\"{nco:photo->nie:url|1}\"'>%]" \
"{nco:fullname|l|s:contact}%[<br />Preferred label: {nao:prefLabel}%]%[<br />Alternative labels: {nao:altLabel}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nco:EmailAddress", \
"{nco:emailAddress|l}", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nco:IMAccount", \
"%[<img width=48 style='float:left; vertical-align:text-bottom;' src=\"{nco:photo->nie:url|1}\"'>%]" \
"{nco:imNickname|l}%[ ({nco:imID})%]%[<br />Type: {nco:imAccountType}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nco:PersonContact", \
"%[<img width=48 style='float:left; vertical-align:text-bottom;' src=\"{nco:photo->nie:url|1}\"'>%]" \
#"{nco:fullname|l|s:contact}%[<br />Preferred label: {nao:prefLabel}%]%[<br />Alternative labels: {nao:altLabel}%]" \
"{nco:hasIMAccount->nco:imNickname|l}%[ ({nco:hasIMAccount->nco:imID})%]%[<br />Account type: {nco:hasIMAccount->nco:imAccountType}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nexif:Photo", \
"{nfo:fileName|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:Audio", \
"{nfo:fileName|l|of|ol}%[<br />Title: {nie:title}%]%[<br />url: {nie:url}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:Archive", \
"{nie:url|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:ArchiveItem", \
"{nie:url|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:FileDataObject", \
"{nie:url|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:FileHash", \
"<b>File hash</b>: {nie:url|l|of|ol}" \
"<br /><b>Associated files</b>:<br />{SPARQL}SELECT DISTINCT ?uri ?value WHERE { ?uri nfo:hasHash <%(uri)s> . optional { ?uri nie:url ?value } . } ORDER BY ?value|lfld|n{/SPARQL}", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:Folder", \
"{nie:url|l|of|ol}%[<br />Filename: {nfo:fileName}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nfo:Image", \
"{nie:url|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:PaginatedTextDocument", \
"{nfo:fileName|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:RemoteDataObject", \
"{nie:url|l|of}%[<br /><b>Title</b>: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_SYSTEM_RUN], \
["nfo:RasterImage", \
"{nfo:fileName|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:Spreadsheet", \
"{nfo:fileName|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:TextDocument", \
"{nfo:fileName|l|of|ol}%[<br />Title: {nie:title}%]" \
"%[<br /><b>Lines</b>: {nfo:lineCount} <b>Words</b>: {nfo:wordCount} <b>Characters</b>: {nfo:characterCount}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nfo:Video", \
"{nfo:fileName|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_SYSTEM_RUN], \
["nfo:Website", \
"{nie:url|l|of}%[<br /><b>Title</b>: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_SYSTEM_RUN], \
["nfo:WebDataObject", \
"{nie:url|l|of}%[<br /><b>Title</b>: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_SYSTEM_RUN], \
["nie:InformationElement", \
"{nfo:fileName|l|of|ol}%[<br />Alternative labels: {nao:altLabel}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nmm:Movie", \
"%[<img width=48 style='float:left; vertical-align:text-bottom;' src=\"{nfo:depiction->nie:url|1}\"'>%]" \
"<b>Title</b>: {nie:title|l|of|ol}" \
"%[<br /><b>Alternative titles</b>: {nao:altLabel}%]" \
"%[<br /><b>Rating</b>: {nao:numericRating|x:rating}%]" \
"<br /><b>Actors</b>: {SPARQL}SELECT DISTINCT ?uri ?value WHERE { <%(uri)s> nmm:actor ?uri . ?uri nco:fullname ?value . } ORDER BY ?value|l|s:actor{/SPARQL}" \
"%[<br /><b>Description</b>: {nie:description}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nmm:MusicAlbum", \
"%[<img width=48 style='float:left; vertical-align:text-bottom;' src=\"{nmm:artwork->nie:url|1}\"'>%]" \
"{nie:title|l|s:album}" \
"%[ <b>by</b> {SPARQL}SELECT DISTINCT ?uri ?value WHERE { <%(uri)s> nmm:albumArtist ?uri . ?uri nco:fullname ?value . } ORDER BY ?value|l|s:albumartist{/SPARQL}%]" \
"%[<br /><b>Rating</b>: {nao:numericRating|x:rating}%]" \
"<br /><b>Performers</b>: {SPARQL}SELECT DISTINCT ?uri ?value WHERE { ?r nmm:musicAlbum <%(uri)s> . ?r nmm:performer ?uri . ?uri nco:fullname ?value . } ORDER BY ?value|l|s:performer{/SPARQL}", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nmm:MusicPiece", \
"{nfo:fileName|l|of|ol}<br />" \
"<b>Title</b>: <em>%[{nmm:setNumber}x%]{nmm:trackNumber|f%02d} - {nie:title}</em><br />" \
"<b>Album</b>: {nmm:musicAlbum->nie:title|l|s:album}<br \>" \
"%[<b>Performers</b>: {SPARQL}SELECT DISTINCT ?uri ?value WHERE { <%(uri)s> nmm:performer ?uri . ?uri nco:fullname ?value . } ORDER BY ?value|l|s:performer{/SPARQL}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nmm:TVSeason", \
"<b>Title</b>: {nao:prefLabel}<br /><b>Season</b>: {nmm:seasonNumber|l} of {nmm:seasonOf->nie:title|l} ", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["nmm:TVSeries", \
"{SPARQL}SELECT ?banner AS ?uri ?url AS ?value WHERE { <%(uri)s> nfo:depiction ?banner . ?banner nfo:height 140 . ?banner nie:url ?url . } LIMIT 1|i{/SPARQL}" \
"{nie:title|l|s:tvserie|ok:tvshow}" \
"%[<br /><b>Rating</b>: {nao:numericRating|x:rating}%]" \
"%[<br /><b>Last watched episode</b>: S{SPARQL}SELECT DISTINCT ?uri ?season AS ?value WHERE { ?x1 nmm:series <%(uri)s> ; nmm:episodeNumber ?episode ; nmm:season ?season ; nuao:usageCount ?v2 . FILTER(?v2 > 0) . } ORDER BY DESC(1000*?season + ?episode) LIMIT 1|f%02d{/SPARQL}" \
"E{SPARQL}SELECT DISTINCT ?uri ?episode AS ?value ?season WHERE { ?x1 nmm:series <%(uri)s> ; nmm:episodeNumber ?episode ; nmm:season ?season ; nuao:usageCount ?v2 . FILTER(?v2 > 0) . } ORDER BY DESC(1000*?season + ?episode) LIMIT 1|f%02d{/SPARQL}" \
" - {SPARQL}SELECT DISTINCT ?x1 AS ?uri ?value WHERE { ?x1 nmm:series <%(uri)s> . ?x1 nmm:episodeNumber ?episode ; nmm:season ?season ; nie:title ?value ; nuao:usageCount ?v2 . FILTER(?v2 > 0) . } ORDER BY DESC(1000*?season + ?episode) LIMIT 1|l|s:tvshows{/SPARQL}%]"
"%[<br /><b>Last available episode</b>: S{SPARQL}SELECT DISTINCT ?uri ?season AS ?value WHERE { ?x1 nmm:series <%(uri)s> ; nmm:episodeNumber ?episode ; nmm:season ?season . } ORDER BY DESC(1000*?season + ?episode) LIMIT 1|f%02d{/SPARQL}" \
"E{SPARQL}SELECT DISTINCT ?uri ?episode AS ?value ?season WHERE { ?x1 nmm:series <%(uri)s> ; nmm:episodeNumber ?episode ; nmm:season ?season . } ORDER BY DESC(1000*?season + ?episode) LIMIT 1|f%02d{/SPARQL}" \
" - {SPARQL}SELECT DISTINCT ?x1 AS ?uri ?value WHERE { ?x1 nmm:series <%(uri)s> . ?x1 nmm:episodeNumber ?episode ; nmm:season ?season ; nie:title ?value . } ORDER BY DESC(1000*?season + ?episode) LIMIT 1|l|s:tvshows{/SPARQL}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nmm:TVShow", \
"{SPARQL}SELECT ?banner AS ?uri ?url AS ?value WHERE { <%(uri)s> nmm:series ?series . ?series nfo:depiction ?banner . ?banner nfo:height 140 . ?banner nie:url ?url . } LIMIT 1|i{/SPARQL}" \
"%[<b>Episode:</b> S{nmm:season|f%02d}E{nmm:episodeNumber|f%02d} - %]{nie:title|l|of|ol}" \
"%[<br \><b>Series</b>: {nmm:series->nie:title|l|ol|ok:tvshow}%]"\
"%[ <b>Watched</b>: {nuao:usageCount} times%]" \
"%[<br /><b>Rating</b>: {nao:numericRating|x:rating}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE + _CONST_ICON_DOLPHIN + _CONST_ICON_KONQUEROR], \
["nmo:Email", \
"<b>From</b>: {nmo:from->nco:fullname|l|s:contact} %[<b>To</b>: {nmo:to->nco:fullname|l|s:contact}%]" \
"%[<br /><b>Date</b>: {nmo:sentDate}%]" \
"%[<br /><b>Subject</b>: {nmo:messageSubject}%]" \
"%[<br /><b>Url</b>: {nie:url|of}%]" \
"%[<br /><b>Rating</b>: {nao:numericRating|x:rating}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE], \
["rdfs:Resource", \
"{nie:url|l|of|ol}%[<br />Title: {nie:title}%]", \
"{type}", \
_CONST_ICON_PROPERTIES + _CONST_ICON_REMOVE] \
]
def __init__(self, searchString = "", model = None, screenWidth = 1024, renderedDataText = None, parent = None, cfgManager = None):
if (cfgManager and cfgManager.cfg[self.cfgId]):
for key in cfgManager.cfg[self.cfgId]:
value = cfgManager.cfg[self.cfgId][key][0]
self.__dict__[key] = value
#print("%s: value = %s, readed = %s" % (key, self.__dict__[key], value))
self.searchString = searchString
if model == None:
if DO_NOT_USE_NEPOMUK:
self.model = Soprano.Client.DBusModel('org.kde.NepomukStorage', '/org/soprano/Server/models/main')
else:
self.model = Nepomuk2.ResourceManager.instance().mainModel()
else:
self.model = model
self.screenWidth = screenWidth
self.viewerColumnsWidth = (self.screenWidth - 100) / 2
self.playlistWidth = self.viewerColumnsWidth
self.videoWidth = self.viewerColumnsWidth
self.videoHeight = int(0.5625*self.viewerColumnsWidth)
if (renderedDataText != None):
self.renderedDataText = renderedDataText
self.parent = parent
def getCoverUrl(self, res = None, url = "", useHtmlEncoding = True):
if res in (None, ""):
return ""
if vartype(res) in ("str", "unicode", "QString", "QVariant"):
if INTERNAL_RESOURCE:
res = cResource(res)
else:
res = Nepomuk2.Resource(res)
# Setting default cover.
coverUrl = self.iconNoCover
# First try to extract this information from the resource.
ontologyMusicAlbumCover = NOC(self.ontologyMusicAlbumCover, True)
if res.hasProperty(ontologyMusicAlbumCover):
if INTERNAL_RESOURCE:
resUris = res.property(ontologyMusicAlbumCover)
if vartype(resUris) != "list":
resUris = [resUris]
else:
resUris = res.property(ontologyMusicAlbumCover).toStringList()
for uri in resUris:
if INTERNAL_RESOURCE:
resTmp = cResource(uri)
else:
resTmp = Nepomuk2.Resource(uri)
tmpCoverUrl = self.readProperty(resTmp, 'nie:url', 'str')
if tmpCoverUrl[:7] == "file://":
tmpCoverUrl = tmpCoverUrl[7:]
if ((tmpCoverUrl != "") and fileExists(tmpCoverUrl)):
if useHtmlEncoding:
coverUrl = urlHtmlEncode(tmpCoverUrl)
else:
coverUrl = tmpCoverUrl
break
# If there is no property then let's try to locate using tracks location.
if coverUrl == self.iconNoCover:
if url == "":
# We must obtain the url from one of the album tracks.
#query = "select ?uri\n" \
# " where {\n" \
# " ?uri nao:hasSubResource <%s> ; nao:userVisible 1 .\n" \
# "}\n" % toUnicode(res.uri())
query = "select ?uri\n" \
" where {\n" \
" ?uri nie:isLogicalPartOf <%s> .\n" \
"}\n" % toUnicode(res.uri())
data = self.model.executeQuery(query, Soprano.Query.QueryLanguageSparql)
if data.isValid():
while data.next():
resUri = toUnicode(data["uri"].toString())
if INTERNAL_RESOURCE:
resTrack = cResource(resUri)
resType = NOCR(resTrack.type())
else:
resTrack = Nepomuk2.Resource(resUri)
if USE_INTERNAL_RESOURCE_FOR_MAIN_TYPE:
resType = NOCR(cResource(resUri).type())
else:
resType = NOCR(resTrack.type())
if (resType == "nmm:MusicPiece"):
url = toUnicode(self.readProperty(resTrack, 'nie:url', 'str'))
break
if (url != ""):
if url[:7] == "file://":
url = url[7:]
url = os.path.dirname(url)
for coverName in ('cover.png', 'Cover.png', 'cover.jpg', 'Cover.jpg'):
tmpCoverUrl = url + '/' + coverName
if fileExists(tmpCoverUrl):
if useHtmlEncoding:
coverUrl = urlHtmlEncode(tmpCoverUrl)
else:
coverUrl = tmpCoverUrl
break
return "file://" + coverUrl
def getOrientationHtml(self, orientation = 1, size = 48):
if (vartype(orientation) == "Resource"):
orientation = orientation.property(NOC("nexif:orientation", True))
if not (vartype(orientation) in ("int", "long")):
try:
orientation = int(orientation)
except:
orientation = 1
if ((orientation < 1) or (orientation > 8)):
orientation = 1
propertyName = 'iconOrientation%s' % orientation
if hasattr(self, propertyName):
icon = getattr(self, propertyName)
else:
icon = toUnicode(KIconLoader().iconPath('orientation_%s' % orientation, KIconLoader.Small))
setattr(self, propertyName, icon)
html = ""
html += "<div class=\"orientation\">"
html += "<img style=\"width:%spx\" src=\"file://%s\">" % (size, icon)
html += "</div>"
return html
def getRatingHtml(self, rating = None, size = 32, listMode = False):
#if (self.iconRatingEmpty == self.iconUnknown) \
# or (self.iconRatingFull == self.iconUnknown) \
# or (self.iconRatingHalf == self.iconUnknown):
# if (vartype(rating) == "Resource"):
# rating = rating.rating()
# return "<div class=\"rating\">%s%s</div>" % (rating, _(" (can't locate rating icons)"))
#
num_stars = 5
full_count = half_count = 0
empty_count = num_stars
if (vartype(rating) == "Resource"):
rating = rating.rating()
if (vartype(rating) in ("int", "long")):
full_count = min(rating/2, 5)
half_count = min(rating - full_count*2, num_stars - full_count)
empty_count = max(empty_count - full_count - half_count, 0)
#starHtml = "<a href=\"setrating:/%s\"><img style=\"-webkit-filter: blur(2px) grayscale(1);\" src=\"file://%s\"></a>"
html = ""
if listMode:
starHtml = "<img style=\"width:%spx\" src=\"file://%%(icon)s\">" % size
else:
starHtml = "<a href=\"setrating:/%%(rating)s\"><img style=\"width:%spx\" src=\"file://%%(icon)s\"></a>" % size
html += "<div class=\"rating\">"
i = 1
for j in range(0, full_count):
html += starHtml % {"rating": i*2-1, "icon": self.iconRatingFull}
i += 1
for j in range(0, half_count):
html += starHtml % {"rating": i*2-2, "icon": self.iconRatingHalf}
i += 1
for j in range(0, empty_count):
html += starHtml % {"rating": i*2, "icon": self.iconRatingEmpty}
i += 1
if not listMode:
html += "</div>"
return html
def resourceIsA(self, uri = None):
if (vartype(uri) != "str"):
uri = toUnicode(uri.uri())
result = []
if (uri == None) or (uri == ""):
return ", ".join(result)
query = "SELECT DISTINCT ?p\n" \
"WHERE {\n" \
" [] ?p <%s> .\n" \
"}\n" % uri
ontologies = []
queryResultSet = self.model.executeQuery(query, SOPRANO_QUERY_LANGUAGE)
if queryResultSet.isValid():
while queryResultSet.next():
ontologies += [toUnicode(queryResultSet["p"].toString())]
for ontology in ontologies:
if NOCR(ontology) in self.skippedOntologiesInResourceIsA:
continue
result += [self.ontologyInfo(ontology)[1]]
# list -> to set (duplicates are removed) -> to list again.
result = list(set(result))
result.sort()
return ", ".join(result)
def buildPlaylist(self, data = [], listType = "audio", playlistMode = True, mustSortPlaylist = True):
if playlistMode:
enableButtons = True
else:
enableButtons = False
listType = listType.lower()
#TODO: Añadir soporte para imágenes..., algún tipo de slideshow.
#TODO: Mantener volumen entre preproducciones.
#TODO: from PyKDE4.kio import *
#TODO: oKPJ = KIO.PreviewJob()
if not listType in ('audio', 'video'):
return ""
if len(data) < 1:
return ""
if mustSortPlaylist:
data = sorted(data, key=lambda item: item[0])
i = 0
playList = []
output = ""
oldTitle = ["", "", 0]
oldPerformers = []
albumYear = None
trackInfo = ""
trackCover = ""
trackAlbumArtists = ""
for item in data:
sortColumn = ""
songSearch = ""
url = item[0]
if url[:7] != "file://":
url = "file://" + url
if INTERNAL_RESOURCE_IN_PLAYLIST:
res = cResource(item[1])
else:
res = Nepomuk2.Resource(item[1])
if listType == 'audio':
trackNumber = self.readProperty(res, 'nmm:trackNumber', 'int')
discNumber = self.readProperty(res, 'nmm:setNumber', 'int')
trackName = self.readProperty(res, 'nie:title', 'str')
if trackName == "":
trackName = os.path.basename(url)
else:
songSearch = ""%s"" % urlHtmlEncode(trackName)
trackInfo = "<b>%s</b>" % urlHtmlEncode(trackName)
trackName = "<a title='%(uri)s' href='%(uri)s'>%(title)s</a>" \
% {"uri": item[1], "title": trackName}
if trackNumber != None:
trackName = "%02d - " % trackNumber + trackName
if discNumber != None:
trackName = "%02d/" % discNumber + trackName
# This property is deprecated.
albumYear = self.readProperty(res, 'nie:contentCreated', 'year')
if not albumYear:
albumYear = self.readProperty(res, 'nmm:releaseDate', 'year')
if not albumYear:
albumYear = 0
sortColumn = trackName
coverUrl = None
# Performers.
performers = []
if res.hasProperty(NOC('nmm:performer', True)):
if INTERNAL_RESOURCE_IN_PLAYLIST:
resUris = res.property(NOC('nmm:performer', True))
if vartype(resUris) != "list":
resUris = [resUris]
else:
resUris = res.property(NOC('nmm:performer', True)).toStringList()
for itemUri in resUris:
if INTERNAL_RESOURCE_IN_PLAYLIST:
resTmp = cResource(itemUri)
else:
resTmp = Nepomuk2.Resource(itemUri)
fullname = self.readProperty(resTmp, 'nco:fullname', 'str')
if fullname != None:
performers += [[itemUri, fullname]]
songSearch += " "%s"" % urlHtmlEncode(fullname)
if (len(performers) > 0):
performers = sorted(performers, key=lambda item: toUtf8(item[1]))
else:
performers = [[None, _("No performers")]]
trackInfo += "<br/> by <b>" + ", ".join([urlHtmlEncode(item[1]) for item in performers]) + "</b>"
if performers == oldPerformers:
performers = []
else:
oldPerformers = list(performers)
# Album title.
albumTitle = [None, "", 0, ""]
if res.hasProperty(NOC('nmm:musicAlbum', True)):
if INTERNAL_RESOURCE_IN_PLAYLIST:
resUri = res.property(NOC('nmm:musicAlbum', True))
resTmp = cResource(resUri)
else:
resUri = res.property(NOC('nmm:musicAlbum', True)).toStringList()[0]
resTmp = Nepomuk2.Resource(resUri)
albumTitle = self.readProperty(resTmp, 'nie:title', 'str')
if albumTitle:
trackInfo += "<br /><br />on <b>%s</b>" % urlHtmlEncode(albumTitle)
else:
trackInfo += "<br /><br />on <b>%s</b>" % _("Unknown album")
if albumTitle == None:
oldTitle = [None, "", 0, ""]
elif not (oldTitle[1] == albumTitle):
# Obtain album artists.
albumArtists = []
if resTmp.hasProperty(NOC('nmm:albumArtist', True)):
if INTERNAL_RESOURCE_IN_PLAYLIST:
resUris = resTmp.property(NOC('nmm:albumArtist', True))
if vartype(resUris) != "list":
resUris = [resUris]
else:
resUris = resTmp.property(NOC('nmm:albumArtist', True)).toStringList()
for itemUri in resUris:
if INTERNAL_RESOURCE_IN_PLAYLIST:
resTmp2 = cResource(itemUri)
else:
resTmp2 = Nepomuk2.Resource(itemUri)
fullname = self.readProperty(resTmp2, 'nco:fullname', 'str')
if fullname != None:
albumArtists += [[itemUri, fullname]]
albumArtists = sorted(albumArtists, key=lambda item: toUtf8(item[1]))
if albumArtists:
trackAlbumArtists = "<br/> by <b>" + ", ".join([urlHtmlEncode(item[1]) for item in albumArtists]) + "</b>"
linkAlbumArtists = ""
for artist in albumArtists:
if linkAlbumArtists != "":
linkAlbumArtists += ", "
linkAlbumArtists += "<a title='%(uri)s' href='%(uri)s'>%(title)s</a>" \
% {"uri": artist[0], "title": artist[1]}
oldTitle = [resUri, albumTitle, albumYear, linkAlbumArtists]
albumTitle = [resUri, albumTitle, albumYear, linkAlbumArtists]
performers = list(oldPerformers)
else:
albumTitle = ["", "", 0, ""]
# Final track name building.
if albumTitle[1] != "":
if (albumTitle[2] > 0):
linkTitle = "<a title='%(uri)s' href='%(uri)s'>%(title)s (%(year)s)</a>" \
% {"uri": albumTitle[0], "title": albumTitle[1], "year": albumTitle[2]}
else:
linkTitle = "<a title='%(uri)s' href='%(uri)s'>%(title)s</a>" \
% {"uri": albumTitle[0], "title": albumTitle[1]}
if albumTitle[3] != "":
linkTitle += " by " + albumTitle[3]
linkPerformers = ""
for performer in performers:
if linkPerformers != "":
linkPerformers += ", "
if (performer[0] == None):
linkPerformers += "%(title)s" % {"title": performer[1]}
else:
linkPerformers += "<a title='%(uri)s' href='%(uri)s'>%(title)s</a>" \
% {"uri": performer[0], "title": performer[1]}
trackName = "<em>%s</em><br /><em>%s</em><br />%s" \
% (linkTitle, linkPerformers, trackName)
# Cover.
coverUrl = self.getCoverUrl(albumTitle[0], toUnicode(self.readProperty(res, 'nie:url', 'str')), False)
trackCover = coverUrl
coverUrl = urlHtmlEncode(trackCover)
trackName = "<img width=48 style='float:left; " \
"vertical-align:text-bottom; margin:2px' " \
"src='%s'>" % (coverUrl) \
+ trackName
elif performers != []:
linkPerformers = ""
for performer in performers:
if linkPerformers != "":
linkPerformers += ", "
if (performer[0] == None):
linkPerformers += "%(title)s" % {"title": performer[1]}
else:
linkPerformers += "<a title='%(uri)s' href='%(uri)s'>%(title)s</a>" \
% {"uri": performer[0], "title": performer[1]}
trackName = "<em>%s</em><br />%s" % (linkPerformers, trackName)
if (coverUrl == None):
# Probably a video or a music file without tags. Use a thumbnail is exists.
if (os.path.splitext(url)[1][1:].lower() in self.supportedVideoFormats):
if coverUrl == None:
tmpCoverUrl = getThumbnailUrl(url)
if tmpCoverUrl != None:
coverUrl = tmpCoverUrl
# If there is no thumbnail then default image is displayed.
if coverUrl == None:
coverUrl = "file://" + self.iconNoCover
trackCover = coverUrl
trackName = "<img width=48 style='float:left; " \
"vertical-align:text-bottom; margin:2px' " \
"src='%s'>" % (coverUrl) \
+ trackName
trackName = trackName.replace('"', '"')
if self.playlistDescendingOrderByAlbumYear:
sortAdjustment = 9999
else:
sortAdjustment = 0
sortColumn = "%s_%s_%s" % (oldTitle[2] - sortAdjustment, oldTitle[1], sortColumn)
trackInfo += trackAlbumArtists
elif listType == 'video':
# Thumbnail.
thumbnailUrl = None
if res.hasProperty(NOC('nie:url', True)):
thumbnailUrl = getThumbnailUrl(toUnicode(self.readProperty(res, 'nie:url', 'str')))
if thumbnailUrl == None:
thumbnailUrl = "file://" + self.iconNoVideoThumbnail
# Title.
trackName = self.readProperty(res, 'nie:title', 'str')
if ((trackName == None) or (trackName == "")):
dummyVal = os.path.basename(url)
trackInfo = "<b>%s</b>" % dummyVal
sortColumn = dummyVal
trackName = "<a title='%(uri)s' href='%(uri)s'>%(title)s</a>" \
% {"uri": toUnicode(res.uri()), "title": dummyVal}
else:
trackInfo = "<b>%s</b>" % trackName
sortColumn = trackName
trackName = "<a title='%(uri)s' href='%(uri)s'>%(title)s</a>" \
% {"uri": toUnicode(res.uri()), "title": trackName}
# Episode number.
episodeNumber = self.readProperty(res, 'nmm:episodeNumber', 'int')
seasonNumber = self.readProperty(res, 'nmm:season', 'int')
if episodeNumber != None:
dummyVal = "E%02d - " % episodeNumber
sortColumn = dummyVal + sortColumn
trackName = dummyVal + trackName
# Season.
if seasonNumber != None:
dummyVal = "S%02d" % seasonNumber
sortColumn = dummyVal + sortColumn
trackName = dummyVal + trackName
# Series title.
if res.hasProperty(NOC('nmm:series', True)):
if INTERNAL_RESOURCE:
resUri = res.property(NOC('nmm:series', True))
resTmp = cResource(resUri)
else:
resUri = res.property(NOC('nmm:series', True)).toStringList()[0]
resTmp = Nepomuk2.Resource(resUri)
if resTmp.hasProperty(NOC('nie:title', True)):
dummyVal = resTmp.property(NOC('nie:title', True)).toString()
sortColumn = dummyVal + sortColumn
trackName = "<em><a title='%(uri)s' href='%(uri)s'>%(title)s</a></em>: %(trackName)s" \
% {"uri": toUnicode(resTmp.uri()), "title": dummyVal, "trackName": trackName}
# Watched?.
if (res.hasProperty(NOC('nuao:usageCount', True)) and (res.property(NOC('nuao:usageCount', True)).toString() == '1')):
trackName += " <b><input type='checkbox' disabled='disabled' onclick='window.open(\"%s\");' name='watched' checked=true><em>watched</em></b>" % item[1]
else:
trackName += " <b><input type='checkbox' disabled='disabled' onclick='window.open(\"%s\");' name='watched' checked=false><em>not watched</em></b>" % item[1]
# Maybe it's a music video with Performers.
performers = []
if res.hasProperty(NOC('nmm:performer', True)):
if INTERNAL_RESOURCE_IN_PLAYLIST:
resUris = res.property(NOC('nmm:performer', True))
if vartype(resUris) != "list":
resUris = [resUris]
else:
resUris = res.property(NOC('nmm:performer', True)).toStringList()
for itemUri in resUris:
if INTERNAL_RESOURCE_IN_PLAYLIST:
resTmp = cResource(itemUri)
else:
resTmp = Nepomuk2.Resource(itemUri)
fullname = self.readProperty(resTmp, 'nco:fullname', 'str')
if fullname != None:
performers += [[itemUri, fullname]]
songSearch += " "%s"" % urlHtmlEncode(fullname)
if (len(performers) > 0):
performers = sorted(performers, key=lambda item: toUtf8(item[1]))
linkPerformers = ""
for performer in performers:
if linkPerformers:
linkPerformers += ", "
linkPerformers += "<a title='%(uri)s' href='%(uri)s'>%(title)s</a>" \