2014-02-28 23:12:34 +00:00
|
|
|
# Copyright (C) 2010-2014 Bastian Kleineidam
|
2010-12-20 22:52:57 +00:00
|
|
|
#
|
|
|
|
|
# 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.
|
2020-07-25 15:35:48 +00:00
|
|
|
"""Parser for Firefox bookmark file."""
|
2020-05-28 18:44:53 +00:00
|
|
|
|
2010-12-20 23:02:12 +00:00
|
|
|
import re
|
2020-05-30 16:01:36 +00:00
|
|
|
|
2010-12-20 23:02:12 +00:00
|
|
|
try:
|
|
|
|
|
import sqlite3
|
2020-05-30 16:01:36 +00:00
|
|
|
|
2010-12-20 23:02:12 +00:00
|
|
|
has_sqlite = True
|
|
|
|
|
except ImportError:
|
|
|
|
|
has_sqlite = False
|
|
|
|
|
|
|
|
|
|
|
2019-04-26 18:25:59 +00:00
|
|
|
extension = re.compile(r'/places.sqlite$', re.IGNORECASE)
|
2010-12-20 23:02:12 +00:00
|
|
|
|
2010-12-20 22:52:57 +00:00
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
def parse_bookmark_file(filename):
|
2011-02-14 20:06:34 +00:00
|
|
|
"""Return iterator for bookmarks of the form (url, name).
|
|
|
|
|
Bookmarks are not sorted.
|
|
|
|
|
Returns None if sqlite3 module is not installed.
|
|
|
|
|
"""
|
2010-12-20 23:02:12 +00:00
|
|
|
if not has_sqlite:
|
|
|
|
|
return
|
|
|
|
|
conn = sqlite3.connect(filename, timeout=0.5)
|
|
|
|
|
try:
|
|
|
|
|
c = conn.cursor()
|
|
|
|
|
try:
|
|
|
|
|
sql = """SELECT mp.url, mb.title
|
|
|
|
|
FROM moz_places mp, moz_bookmarks mb
|
|
|
|
|
WHERE mp.hidden=0 AND mp.url NOT LIKE 'place:%' AND
|
|
|
|
|
mp.id=mb.fk"""
|
|
|
|
|
c.execute(sql)
|
|
|
|
|
for url, name in c:
|
|
|
|
|
if not name:
|
|
|
|
|
name = url
|
|
|
|
|
yield (url, name)
|
|
|
|
|
finally:
|
|
|
|
|
c.close()
|
|
|
|
|
finally:
|
|
|
|
|
conn.close()
|