Selaa lähdekoodia

- recoll.py:

    * add mount_prefix parameter, set this to location where _local_
      filesystem covered by index is mounted, used to create
      download path, see explanation in settings.yml
    * add preview support for audio, video and image types
 - settings.yml:
    * add mount_prefix plus explanation on how to use it
 - templates/.../files.html
    * add generic media preview support
frankdelange 6 vuotta sitten
vanhempi
commit
930e0d09a0
3 muutettua tiedostoa jossa 61 lisäystä ja 21 poistoa
  1. 25
    4
      searx/engines/recoll.py
  2. 32
    16
      searx/settings.yml
  3. 4
    1
      searx/templates/oscar/result_templates/files.html

+ 25
- 4
searx/engines/recoll.py Näytä tiedosto

@@ -4,12 +4,12 @@
4 4
  @using-api   yes
5 5
  @results     JSON
6 6
  @stable      yes
7
- @parse       url, content, size, abstract, author, mtype, time, \
8
-              filename, label
7
+ @parse       url, content, size, abstract, author, mtype, subtype, time, \
8
+              filename, label, type, embedded
9 9
 """
10 10
 
11 11
 from json import loads
12
-from searx.url_utils import urlencode
12
+from searx.url_utils import urlencode, quote
13 13
 from datetime import date, timedelta
14 14
 
15 15
 # engine dependent config
@@ -19,9 +19,15 @@ time_range_support = True
19 19
 # parameters from settings.yml
20 20
 base_url = None
21 21
 search_dir = ''
22
+mount_prefix = None
22 23
 dl_prefix = None
23 24
 
25
+# embedded
26
+embedded_url = '<{type} controls height="166px" ' +\
27
+    'src="{url}" type="{mtype}"></{type}>'
24 28
 
29
+
30
+# helper functions
25 31
 def get_time_range(time_range):
26 32
     sw = {
27 33
         'day': 1,
@@ -61,7 +67,7 @@ def response(resp):
61 67
 
62 68
     for result in response_json.get('results', []):
63 69
         title = result['label']
64
-        url = result['url'].replace('file:///export', dl_prefix)
70
+        url = result['url'].replace('file://' + mount_prefix, dl_prefix)
65 71
         content = u'{}'.format(result['snippet'])
66 72
 
67 73
         # append result
@@ -77,6 +83,21 @@ def response(resp):
77 83
             if result[parameter]:
78 84
                 item[parameter] = result[parameter]
79 85
 
86
+        # facilitate preview support for known mime types
87
+        if 'mtype' in result:
88
+            (mtype, subtype) = result['mtype'].split('/')
89
+            item['type'] = mtype
90
+            item['subtype'] = subtype
91
+
92
+            if mtype in ['audio', 'video']:
93
+                item['embedded'] = embedded_url.format(
94
+                    type=type,
95
+                    url=quote(url.encode('utf8'), '/:'),
96
+                    mtype=result['mtype'])
97
+
98
+            if mtype in ['image'] and subtype in ['bmp', 'gif', 'jpeg', 'png']:
99
+                item['img_src'] = url
100
+
80 101
         results.append(item)
81 102
 
82 103
     if 'nres' in response_json:

+ 32
- 16
searx/settings.yml Näytä tiedosto

@@ -533,31 +533,47 @@ engines:
533 533
     # This engine uses a custom 'files' result template
534 534
     #
535 535
     # set base_url to the location where recoll-webui can be reached
536
+    # set mount_prefix to the location where the file hierarchy is mounted on your _local_ filesystem
536 537
     # set dl_prefix to a location where the file hierarchy as indexed by recoll can be reached
538
+    # 
539
+    # For example:
540
+    #
541
+    #     Recoll indexes a local filesystem mounted in /export/documents/reference
542
+    #     The Recoll search inteface can be reached at https://recoll.example.org/
543
+    #     The contents of this filesystem can be reached though https://download.example.org/reference
544
+    #
545
+    #        set base_url to https://recoll.example.org/
546
+    #        set mount_prefix to /export/documents
547
+    #        set dl_prefix to https://example.org
548
+    #
549
+    #     the resulting url will be https://download.example.org/reference
550
+    # 
537 551
     # set search_dir to the part of the indexed file hierarchy to be searched, use an empty string
538 552
     #     to search the entire search domain
539 553
 
540 554
     # this entry (with search_dir set to an empty string) covers the entire recoll search domain
541
-  - name : library
542
-    engine : recoll
543
-    shortcut : lib
555
+  - name: library
556
+    engine: recoll
557
+    shortcut: lib
544 558
     base_url: 'https://recoll.example.org/'
545
-    search_dir : ''
546
-    dl_prefix : 'https://download.example.org'
547
-    timeout : 30.0
548
-    categories : files
549
-    disabled : True
559
+    search_dir: ''
560
+    mount_prefix: /export
561
+    dl_prefix: 'https://download.example.org'
562
+    timeout: 30.0
563
+    categories: files
564
+    disabled: True
550 565
 
551 566
     # this entry only searches the 'reference' directory
552
-  - name : library reference
553
-    engine : recoll
567
+  - name: library reference
568
+    engine: recoll
554 569
     base_url: 'https://recoll.example.org/'
555
-    search_dir : reference
556
-    dl_prefix : 'https://download.example.org'
557
-    shortcut : libr
558
-    timeout : 30.0
559
-    categories : files
560
-    disabled : True
570
+    search_dir: reference
571
+    mount_prefix: /export
572
+    dl_prefix: 'https://download.example.org'
573
+    shortcut: libr
574
+    timeout: 30.0
575
+    categories: files
576
+    disabled: True
561 577
 
562 578
   - name : reddit
563 579
     engine : reddit

+ 4
- 1
searx/templates/oscar/result_templates/files.html Näytä tiedosto

@@ -4,7 +4,10 @@
4 4
 {{ result_sub_header(result) }}
5 5
 
6 6
 {% if result.embedded %}
7
-    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">{{ icon('music') }} {{ _('show media') }}</a></small>
7
+    <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">
8
+    {% if result.mtype == 'audio' %}{{ icon('music') }}
9
+    {% elif result.mtype == 'video' %} {{ icon('film') }}
10
+    {% endif %} {{ _('show media') }}</a></small>
8 11
 {% endif %}
9 12
 
10 13
 {% if result.embedded %}