-
Notifications
You must be signed in to change notification settings - Fork 0
/
vivaldi.py
67 lines (54 loc) · 2.24 KB
/
vivaldi.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
# encoding: utf-8
__kupfer_name__ = _("Vivaldi Bookmarks")
__kupfer_sources__ = ("BookmarksSource", )
__kupfer_actions__ = ()
__description__ = _("Index of Vivaldi bookmarks")
__version__ = "2017.1"
__author__ = "thorko"
#from configparser import RawConfigParser
#from contextlib import closing
import os
import json
#from urllib.parse import quote, urlparse
from kupfer import plugin_support
from kupfer.obj import Source, Action, Leaf, OpenUrl
from kupfer.obj import UrlLeaf, TextLeaf, TextSource
from kupfer.obj.apps import AppLeafContentMixin
from kupfer.obj.helplib import FilesystemWatchMixin
from kupfer import launch
MAX_ITEMS = 10000
class BookmarksSource (AppLeafContentMixin, Source, FilesystemWatchMixin):
appleaf_content_id = ("vivaldi")
def __init__(self):
super().__init__(_("Vivaldi Bookmarks"))
self._version = 3
def initialize(self):
vivaldi_dir = os.path.expanduser("~/.config/vivaldi/Default")
self.monitor_token = self.monitor_directories(vivaldi_dir)
def monitor_include_file(self, gfile):
return gfile and gfile.get_basename() == 'lock'
def _get_vivaldi_bookmarks(self):
"""Query the vivaldi places bookmark database"""
bookmark = []
bookmarks_file = os.path.expanduser("~/.config/vivaldi/Default/Bookmarks")
data = json.loads(open(bookmarks_file, encoding='utf-8').read())
for c in data['roots']['bookmark_bar']['children']:
if 'children' in c:
for l in c['children']:
if 'children' in l:
for k in l['children']:
if 'url' in k:
bookmark.append({'title': k['name'], 'url': k['url']})
if 'url' in l:
bookmark.append({'title': l['name'], 'url': l['url']})
return[UrlLeaf(b['url'], b['title'].strip('/')) for b in bookmark]
def get_items(self):
return self._get_vivaldi_bookmarks()
def get_description(self):
return _("Index of Vivaldi bookmarks")
def get_gicon(self):
return self.get_leaf_repr() and self.get_leaf_repr().get_gicon()
def get_icon_name(self):
return "web-browser"
def provides(self):
yield UrlLeaf