Created
November 21, 2020 19:10
-
-
Save dynax60/4bf7af4a853d07351492d0a0cf110a5e to your computer and use it in GitHub Desktop.
lg-android-shortcuts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import re | |
import sqlite3 | |
from urllib.parse import unquote | |
def process(filename): | |
connection = sqlite3.connect(f'{filename}') | |
cursor = connection.cursor() | |
directories = cursor.execute('SELECT _id, title FROM favorites WHERE itemType=2').fetchall() | |
output_dir = './output' | |
url_pattern = re.compile(r'(http.+?)#Intent;|webapp_url=(.*?);end') | |
if not os.path.isdir(output_dir): | |
os.mkdir(output_dir, mode=0o755) | |
os.chdir(output_dir) | |
for subdir in directories: | |
if not os.path.isdir(subdir[1]): | |
os.mkdir(subdir[1], mode=0o755) | |
os.chdir(subdir[1]) | |
shortcuts = cursor.execute('SELECT title, Intent FROM favorites WHERE itemType=1 AND IconPackage is null AND container = ?', | |
(int(subdir[0]),)).fetchall() | |
for shortcut in shortcuts: | |
name = shortcut[0] | |
name = name.replace('/', '-') | |
name = name[:200] | |
filename = name + '.url' | |
contents = shortcut[1] | |
url = re.findall(url_pattern, contents)[0] | |
with open(filename, 'w') as fname: | |
fname.write("[InternetShortcut]\nURL="+unquote(url[0] if url[0] else url[1])+"\n") | |
fname.close() | |
os.chdir('..') | |
if __name__ == '__main__': | |
process('workspace.db') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment