summaryrefslogtreecommitdiff
path: root/site/2023-11-15-scraping-images-from-open-tabs.md
blob: 3975356412a959a5547492b6ce27b1fd04019aa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Scraping images from open tabs

<div class="post-dates">
  <time id="post-upload-date">2023-11-15</time>
  <time id="post-modification-date">2023-11-15</time>
</div>

<!-- FIXME: shell highlighting doesn't work yet -->
<pre><code>
cat export.json \
  | jaq --raw-output '..["url"]? | strings' \
  | rg --fixed-strings "wallhaven.cc/w" \
  | gallery-dl --input-file -
</code></pre>

I exported my current session to json with tab session manager. This command
takes that json export (referred to as `export.json`), finds all the urls
that contain `wallhaven.cc/w` (i.e. all urls that are wallhaven images) and
passes them to gallery-dl. Gallery-dl then neatly downloads all of those images
in their original quality.

This workflow could be made better by creating a version of tab session manager
that exports in a simpler (or more configurable format), and I could also turn
this into a script that takes the wanted website formats as an argument.
Invocation of the script might look something like: 

<!-- FIXME: shell highlighting doesn't work yet -->
<pre><code>
tabsession-dl --format "wallhaven.cc/w" --format "reddit.com/r" \
  --input-file export.json
</code></pre>