snippets commit

This commit is contained in:
keystroke 2026-02-06 22:41:51 +11:00
parent 1cd8ca425d
commit bff3302b73
6 changed files with 120 additions and 2 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

79
E621Bridge.php Normal file
View file

@ -0,0 +1,79 @@
<?php
class e621Bridge extends BridgeAbstract
{
const MAINTAINER = 'keystroke';
const NAME = 'e621';
const URI = 'https://e621.net/';
const DESCRIPTION = 'Returns images from given page';
const PARAMETERS = [
'global' => [
'p' => [
'name' => 'page',
'defaultValue' => 1,
'type' => 'number'
],
't' => [
'name' => 'tags',
'exampleValue' => 'solo',
'title' => 'Tags to search for'
],
'l' => [
'name' => 'limit',
'exampleValue' => 100,
'title' => 'How many posts to retrieve (hard limit of 1000)'
]
],
0 => []
];
protected function getFullURI()
{
return $this->getURI()
. 'posts.json?page=' . $this->getInput('p')
. '&limit=' . $this->getInput('l')
. '&tags=' . urlencode($this->getInput('t'));
}
protected function getItemFromElement($element)
{
$item = [];
$item['uri'] = $this->getURI() . 'posts/'
. $element->id;
$item['postid'] = $element->id;
$item['author'] = implode(' ', $element->tags->artist); // to fix?
$item['timestamp'] = date('d F Y H:i:s', strtotime($element->created_at));
$item['tags'] = implode(' ', $element->tags->general);
$item['title'] = $this->getName() . ' | ' . $item['postid'];
$thumbnailUri = $element->preview->url;
$item['content'] = '<a href="' . $item['uri'] . '"><img src="'
. $thumbnailUri . '" /></a><br><br><b>Dimensions:</b> '
. strval($element->file->width) . ' x ' . strval($element->file->height) . '<br><br><b>Tags:</b> '
. $item['tags'];
if (isset($element->sources[0])) {
$item['content'] .= '<br><br><b>Source: </b><a href="' . $element->sources[0] . '">' . $element->sources[0] . '</a>'; // to fix?
}
return $item;
}
public function collectData()
{
$content = getContents($this->getFullURI());
// $content is empty string
$posts = json_decode($content);
$posts = $posts->posts;
if (is_null($posts)) {
returnServerError('No posts found.');
}
foreach ($posts as $post) {
$this->items[] = $this->getItemFromElement($post);
}
}
}

View file

@ -1,3 +1,6 @@
# snippets
# Snippets
Small snippets of code not cool or complex enough to get their own repo
- backup.sh: Backup script that syncs from a file containing directories/files to an offsite remote using rclone.
- monitor-toggle.sh: Turn off a display to stop my monitor from switching to the "active" server input with my computer off.
- remove-metadata.sh: Removes name and comment metadata from mp4 and mkv files from a directory recursively.
- E621Bridge.php: An e621 bridge for [rss-bridge](https://github.com/RSS-Bridge/rss-bridge).

12
backup.sh Normal file
View file

@ -0,0 +1,12 @@
#!/bin/bash
if [ $# -eq 0 ]; then
>&2 echo 'No backup file provided'
exit 1
fi
grep -ve '^$\|^#' "$1" | \
while read location; do
echo "Backing up $location"
rclone sync "$location" mega:backup-"$(hostname)${location%/*}" -vlM --create-empty-src-dirs --exclude '**cache**' --ignore-case
done

11
monitor-toggle.sh Normal file
View file

@ -0,0 +1,11 @@
#!/bin/bash
export DISPLAY=:0.0
status=$(xset -q|sed -ne 's/^[ ]*Monitor is //p')
if [ $status = "On" ]; then
echo -e "Turning monitor off..."
xset dpms force off
elif [ $status = "Off" ]; then
echo -e "Turning monitor on..."
xset dpms force on
fi

11
remove-metadata.sh Normal file
View file

@ -0,0 +1,11 @@
#!/bin/bash
if [[ $# -eq 0 ]] ; then
echo "Usage: remove-metadata DIRECTORY
Removes name and comment metadata from mp4 and mkv files from a directory recursively."
exit 0
fi
dir=$1
exiftool -r -overwrite_original -ext mp4 -Title= -Comment= -Description= "$dir"
find "$dir" -name *.mkv -exec mkvpropedit -d title {} \;