Skip to content

Commit

Permalink
support for exports with local file urls
Browse files Browse the repository at this point in the history
  • Loading branch information
slatinsky committed Oct 14, 2022
1 parent 95a7e50 commit ed2f88f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ Using prebuilt binaries is the easiest way to use this tool. Builds are Windows
4. Run `START_VIEWER.bat` - DiscordChatExporter-jsonViewer will open in your default browser


## Building release from source
### Requirements
# Building release from source
## Requirements
- Node.js 16
- Python 3.9+
- pyinstaller (installled globally)
```
py -m pip install pyinstaller
```

### Steps
## Steps
1. Clone this repository
```bash
git clone URL
Expand Down Expand Up @@ -66,7 +66,7 @@ v16.14.2
BUILD_RELEASE.bat
```

### Tested on
## Tested on

```
>winver
Expand Down Expand Up @@ -94,8 +94,11 @@ AMD Ryzen™ 7 5800H

But should work on any Windows 10 / Windows 11 x64 computer

## Development
### Preprocessor
# Development
This tool consists of two parts:
- Frontend - Sveltekit app
- Backend - Python3 script to preprocess JSON exports for frontend
## Preprocessor
For development make sure you have nodemon installed globally (used for hot reloading)
```
npm install -g nodemon
Expand All @@ -115,7 +118,7 @@ preprocess script will:

After running preprocess script, don't remove `/static/input/` folder - it's needed to serve media files.

### Frontend
## Frontend
Run dev webserver:
```
npm run dev -- --open
Expand All @@ -126,18 +129,32 @@ npm run dev -- --open



# Which JSON exports are supported?
Supported are JSON exports exported with media
```
DiscordChatExporter.Cli export --token DISCORD_TOKEN --media True --reuse-media True --output OUTPUT_FOLDER_PATH --format Json --channel CHANNEL_OR_THREAD_ID
```

Or exported without media, but coupled with another html export with media
```
DiscordChatExporter.Cli export --token DISCORD_TOKEN --output OUTPUT_FOLDER_PATH --format Json --channel CHANNEL_OR_THREAD_ID
DiscordChatExporter.Cli export --token DISCORD_TOKEN --output OUTPUT_FOLDER_PATH --media True --reuse-media True --format HtmlDark --channel CHANNEL_OR_THREAD_ID
```

The main requirement now is that media files (`--media True --reuse-media True`) are exported.

Tested with DiscordChatExporter v2.36.1 exports

## How to view threads
- This viewer supports viewing threads, but they need to be exported by Tyrrrz/DiscordChatExporter. Export them the same way you export channels, but instead of channel_ID, use thread_ID.
- This viewer supports viewing threads, but they need to be exported by Tyrrrz/DiscordChatExporter. Export them the same way you export channels (`--channel`), but instead of CHANNEL_ID, use THREAD_ID. Because threads are channels.

## Roadmap:
- Support JSON exports with local media urls
- Better handle edge cases (if something is missing in the backup)
- Better handling of edge cases (if something is missing in the backup)
- Support Direct messages
- Screenshots in documentation
- Message markdown rendering support
- Better GUI
- Better search
- Better search (by author, by date)
- Guild-wide search
- Improve code readability
- Discord forums support
Expand Down
29 changes: 20 additions & 9 deletions preprocess/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,20 @@ def _calculate_filename(self, url):
"""calculate the filename based on the data"""
if url is None:
return ""
filename = url.split('/')[-1]
# remove get parameters
# hashed filename must contain get parameters
hash_sha256 = sha256(url.encode('utf-8')).hexdigest()[:5].upper()

filename = filename.split('?')[0]
base, extension = os.path.splitext(filename)
filename = base + "-" + hash_sha256 + extension
is_url = re.match(r'^https?://', url)

filename = url.replace('\\', '/').split('/')[-1]

if is_url: # calculate filename for url
# remove get parameters
# hashed filename must contain get parameters
hash_sha256 = sha256(url.encode('utf-8')).hexdigest()[:5].upper()

filename = filename.split('?')[0]
base, extension = os.path.splitext(filename)
filename = base + "-" + hash_sha256 + extension
else: # filename already contains hash
pass
return filename

def _find_filepath(self, filename, ignore_not_found=False):
Expand All @@ -119,7 +125,11 @@ def _find_filepath(self, filename, ignore_not_found=False):
if not ignore_not_found:
print("File not found: " + filename)
return None
return None

def calculateGuildFilename(self, guild):
guild['localFileName'] = self._calculate_filename(guild['iconUrl'])
guild['localFilePath'] = self._find_filepath(guild['localFileName'])
return guild

def calculate_local_filenames(self, messages, authors, emojis):
for message in messages.values():
Expand Down Expand Up @@ -393,6 +403,7 @@ def process(self):
for guild_id, json_filepaths in json_paths_by_guild.items():
gp = GuildPreprocess(guild_id, self.input_directory,
json_filepaths, media_filepaths)
guilds[guild_id] = gp.calculateGuildFilename(guilds[guild_id])
gp.process()

# write guilds to json file
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{#if data.guildId === guild.id}
<div class="guild-selected"></div>
{/if}
<img src="{guild.iconUrl}" alt="{guild.name}">
<img src="{guild.localFilePath}" alt="{guild.name}">
</div>
</a>

Expand Down

0 comments on commit ed2f88f

Please sign in to comment.