Skip to content

Commit 24c8585

Browse files
authored
Merge pull request #11 from Jab2870/master
Adds the ability to transfer epubs
2 parents a7606df + ff8f9c9 commit 24c8585

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

pdf2remarkable.sh

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TARGET_DIR="${REMARKABLE_HOST}:${REMARKABLE_XOCHITL_DIR}"
6565

6666
# Check if we have something to do
6767
if [ $# -lt 1 ]; then
68-
echo "Transfer PDF document to a reMarkable tablet"
68+
echo "Transfer PDF or Epub document to a reMarkable tablet"
6969
echo "usage: $(basename $0) [ -r ] path-to-pdf-file [path-to-pdf-file]..."
7070
exit 1
7171
fi
@@ -87,14 +87,16 @@ tmpdir=$(mktemp -d)
8787

8888
# Loop over the command line arguments,
8989
# which we expect are paths to the PDF files to be transferred
90-
for pdfname in "$@" ; do
90+
for filename in "$@" ; do
9191

9292
# reMarkable documents appear to be identified by universally unique IDs (UUID),
9393
# so we generate one for the document at hand
9494
uuid=$(uuidgen)
9595

96-
# Copy the PDF file itself
97-
cp -- "$pdfname" ${tmpdir}/${uuid}.pdf
96+
extension="${filename##*.}"
97+
98+
# Copy the file itself
99+
cp -- "$filename" "${tmpdir}/${uuid}.${extension}"
98100

99101
# Add metadata
100102
# The lastModified item appears to contain the date in milliseconds since Epoch
@@ -109,12 +111,13 @@ for pdfname in "$@" ; do
109111
"synced": false,
110112
"type": "DocumentType",
111113
"version": 1,
112-
"visibleName": "$(basename -- "$pdfname" .pdf)"
114+
"visibleName": "$(basename -- "$filename" ".$extension")"
113115
}
114116
EOF
115117

116-
# Add content information
117-
cat <<EOF >${tmpdir}/${uuid}.content
118+
if [ "$extension" = "pdf" ]; then
119+
# Add content information
120+
cat <<EOF >${tmpdir}/${uuid}.content
118121
{
119122
"extraMetadata": {
120123
},
@@ -138,18 +141,31 @@ EOF
138141
}
139142
}
140143
EOF
144+
# Add cache directory
145+
mkdir ${tmpdir}/${uuid}.cache
146+
147+
# Add highlights directory
148+
mkdir ${tmpdir}/${uuid}.highlights
141149

142-
# Add cache directory
143-
mkdir ${tmpdir}/${uuid}.cache
150+
# Add thumbnails directory
151+
mkdir ${tmpdir}/${uuid}.thumbnails
144152

145-
# Add highlights directory
146-
mkdir ${tmpdir}/${uuid}.highlights
153+
elif [ "$extension" == "epub" ]; then
147154

148-
# Add thumbnails directory
149-
mkdir ${tmpdir}/${uuid}.thumbnails
155+
# Add content information
156+
cat <<EOF >${tmpdir}/${uuid}.content
157+
{
158+
"fileType": "epub"
159+
}
160+
EOF
161+
else
162+
echo "Unknown extension: $extension, skipping $filename"
163+
rm -rf ${tmpdir}/*
164+
continue
165+
fi
150166

151167
# Transfer files
152-
echo "Transferring $pdfname as $uuid"
168+
echo "Transferring $filename as $uuid"
153169
scp -r ${tmpdir}/* "${TARGET_DIR}"
154170
rm -rf ${tmpdir}/*
155171
done

0 commit comments

Comments
 (0)