Last active
January 25, 2022 21:40
-
-
Save aldrinmartoq/de08c2b94731facdab4972f7e719043b to your computer and use it in GitHub Desktop.
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
# Busca archivos JPG desde el cache de Google Chrome en Mac | |
# lo copie de https://www.matbra.com/2018/08/20/find-images-on-chrome-cache-files-and-any-other.html | |
import os | |
import glob | |
import sys | |
import errno | |
OUTPUT_FOLDER = os.getenv('HOME') + '/Desktop/salvado_cache' | |
def mkdir_p(path): | |
try: | |
os.makedirs(path) | |
except OSError as exc: | |
if exc.errno == errno.EEXIST and os.path.isdir(path): | |
pass | |
else: | |
# possibly handle other errno cases here, otherwise finally: | |
raise | |
def save_file(data, path, filename, count, eoi, soi): | |
file = open('{}/{}-{}.jpg'.format(OUTPUT_FOLDER, filename, count), 'wb') | |
m1 = soi[0] | |
m2 = soi[-1] if soi[-1] > eoi[-1] else eoi[-1] | |
file.write(data[m1:m2]) | |
file.close() | |
def extract(filepath): | |
count = 0 | |
f = open(filepath, 'rb') | |
data = f.read() | |
if 'JFIF' not in data and 'Exif' not in data: | |
return | |
path, filename = os.path.split(filepath) | |
old_soi = [] | |
old_eoi = [] | |
prev = None | |
soi = [] | |
eoi = [] | |
eoi_found = False | |
pos = 0 | |
for b in data: | |
if prev is None: | |
prev = b | |
pos = pos + 1 | |
continue | |
if prev == chr(0xFF): | |
if b == chr(0xD8): | |
if eoi_found: | |
save_file(data, path, filename, count, eoi, soi) | |
old_soi = old_soi + soi | |
old_eoi = old_eoi + eoi | |
soi = [] | |
eoi = [] | |
count = count + 1 | |
eoi_found = False | |
soi.append(pos-1) | |
elif b == chr(0xD9): | |
eoi.append(pos-1) | |
eoi_found = True | |
prev = b | |
pos = pos + 1 | |
print(filename, "SOI", soi, len(old_soi)) | |
print(filename, "EOI", eoi, len(old_eoi)) | |
if eoi_found: save_file(data, path, filename, count, eoi, soi) | |
def procesar(carpeta): | |
print("procesando " + carpeta) | |
for root, dirs, files in os.walk(carpeta): | |
for filename in files: | |
filename = os.path.join(root, filename) | |
if os.path.isfile(filename): | |
print("item " + filename) | |
extract(filename) | |
def seleccionar_perfil(): | |
print("Escoge un perfil:") | |
base = os.getenv('HOME') + '/Library/Caches/Google/Chrome/' | |
lista = filter(lambda x: os.path.isdir(base + x), os.listdir(base)) | |
lista.sort() | |
while(True): | |
for index, item in enumerate(lista): | |
print index, item | |
opcion = int(input('Seleccione: ')) | |
if 0 <= opcion < len(lista): | |
mkdir_p(OUTPUT_FOLDER) | |
procesar(base + lista[opcion] + '/Cache/Cache_Data/') | |
os.system('open ' + OUTPUT_FOLDER) | |
exit() | |
def main(): | |
print("Hola, voy a extrar fotos que encuentre desde tu cache") | |
seleccionar_perfil() | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment