Skip to content

Instantly share code, notes, and snippets.

@hax4dazy
Last active May 25, 2025 18:53
Show Gist options
  • Save hax4dazy/e9a88c4e6b1df61688a49477cf32b11e to your computer and use it in GitHub Desktop.
Save hax4dazy/e9a88c4e6b1df61688a49477cf32b11e to your computer and use it in GitHub Desktop.
import json
favoritesStorage = []
def favoritesfunk(id, booruId, createdAt, updatedAt, thumbnailUrl, sampleUrl, originalUrl, sourceUrl, width, height, md5, tags, realSourceUrl, format):
favorite = {
"id": id,
"booruId": booruId,
"createdAt": createdAt,
"updatedAt": updatedAt,
"thumbnailUrl": thumbnailUrl,
"sampleUrl": sampleUrl,
"originalUrl": originalUrl,
"sourceUrl": sourceUrl,
"width": width,
"height": height,
"md5": md5,
"tags": tags,
"realSourceUrl": realSourceUrl,
"format": format
}
favoritesStorage.append(favorite)
with open('backup.abbj', 'r') as file:
backup = json.load(file)
banned_tags = backup.get('bannedTags', [])
with open('bannedTags.txt', 'w') as banned_tags_file:
for tag in banned_tags:
taag = tag.get('tagText', '')
split = taag.split('site')
banned_tags_file.write(f"{split[0]}\n")
print(f"Extracted {len(banned_tags)} banned tags to bannedTags.txt")
homePins = backup.get('homePins', [])
with open('homePins.txt', 'w') as home_pins_file:
for pin in homePins:
query = pin.get('query', {})
text = query.get('text', '')
if text:
home_pins_file.write(f"{text} ")
print(f"Extracted {len(homePins)} home pins to homePins.txt")
favorites = backup.get('favorites', [])
id = -1
for favorite in favorites:
id += 1
postURL = favorite.get('ppostUrl', '')
e = postURL.split('/')
host = e[2].split(".")
# There isn't really a good way to detect what booru software the server is using. I'm just hardcoding these two ID's for now since they're the easiest to "find".
if host[0] == 'e621':
booruId = 25
elif host[0] == 'rule34':
booruId = 23
createdAt = favorite.get('dateAdded', '')
updatedAt = favorite.get('dateAdded', '')
preview = favorite.get('preview', '')
thumbnailUrl = preview.get('url', '')
sampleUrl = preview.get('url', '')
file = favorite.get('file', {})
originalUrl = file.get('url', '')
sourceUrl = favorite.get('source', '')
width = file.get('width', 0)
height = file.get('height', 0)
md5 = favorite.get('md5', '')
tags = [tag.strip() for tag in favorite.get('tags', '').split() if tag.strip()]
realSourceUrl = favorite.get('source', '')
format = file.get('ext', '')
favoritesfunk(id, booruId, createdAt, updatedAt, thumbnailUrl, sampleUrl, originalUrl, sourceUrl, width, height, md5, tags, realSourceUrl, format)
print(f"Extracted {len(favorites)} favorites")
with open('favorites.json', 'w') as favorites_file:
json.dump(favoritesStorage, favorites_file, indent=4)
print("Favorites have been saved to favorites.json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment