Automatically link youtube videos

You could try with a php function the following:

<?php
function getYouTubeVideosByTag($tag, $maxResults = 6) {
    $apiKey = '[your youtube API key]';
    $channelId = '[your-youtube-channel-ID';

    // Forza formato hashtag
    $query = urlencode('#' . $tag);

    $url = "https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&order=date&maxResults=$maxResults&q=$query&channelId=$channelId&key=$apiKey";

    $response = file_get_contents($url);

    if ($response === FALSE) {
        return [];
    }

    $data = json_decode($response, true);

    $videos = [];

    if (!empty($data['items'])) {
        foreach ($data['items'] as $item) {
            if (!isset($item['id']['videoId'])) continue;

            $videos[] = [
                'title' => $item['snippet']['title'],
                'videoId' => $item['id']['videoId'],
                'description' => $item['snippet']['description'],
                // 'thumbnail' => $item['snippet']['thumbnails']['medium']['url']
            ];
        }
    }

    return $videos;
}
?>

Obviously you have to link this function in every web page you want links your videos, and in these pages you can call that function by a code like this:

<?php
if (!empty($youtubetag)) {

    if (is_array($youtubetag)) {
        $query = implode(' OR ', array_map(fn($t) => '#' . $t, $youtubetag));
        $videos = getYouTubeVideos($query, 5);
    } else {
        $videos = getYouTubeVideosByTag($youtubetag, 3);
    }

    if (!empty($videos)) {
        ?>

        <section class="youtube-videos">
        <h2>🎙️ Our podcast (YouTube)</h2>

            <ul>
                <?php foreach ($videos as $video): ?>
                    <li class="podcast">🎙️
                        <a href="https://www.youtube.com/watch?v=<?= $video['videoId'] ?>"><strong><?= htmlspecialchars($video['title']) ?></strong></a>:
                       <?= htmlspecialchars(substr($video['description'], 0, 120), ENT_QUOTES | ENT_HTML5, 'UTF-8', false) ?>
                    </li>
                <?php endforeach; ?>
            </ul>
        </section>

        <?php
    }
}
?>

Finally, you should define, possibly in the head of each php page, where you want to link youtube videos, the variable $youtubetag:

$youtubetag="my tag";
or 
$youtubetag="['mytag1', 'mytag2']";

Disable Caps Lock

It could happen that you inadvertently press and it turn out all the word you write are are UPPERCASE.
To avoid this, in Linux, you can

  • go to System Settings > Input Devices > Keyboard -> Key bindigs
  • in Key bindings -> Configure Keybord options -> Caps Lock behavior -> Caps Lock disabled.
  • and then, always in Configure Keybord options -> switching to another layout -> select both
    • Both Shifts together
    • Caps Lock.

In this way your Caps Lock will be usually disabled, but you can use it by pressing both the shift keys.

BUT…
If you have wayland and espanso the upper configuration can give problems.
So the simpler way is:

  • to disable (permanently) caps lock : Key bindings -> Configure Keybord options -> Caps Lock behavior -> Make Caps Lock an additional Ctrl

How to toggle the opened <details>

If you have two <details> tags, and you want to close one, when you open the other, you can use this short js:

<script>
const details = document.querySelectorAll("details");

details.forEach(d => {
  d.addEventListener("toggle", () => {
    if (d.open) {
      details.forEach(other => {
        if (other !== d) {
          other.removeAttribute("open");
        }
      });
    }
  });
});
</script>

WordPress in localhost: permalinks

There could be some problems to fix setting wp in localhost.

One is to get permalink working: there are at least two steps:

  • a working .htaccess (in the root of wp installation) with a code that wp itself will provide,
  • and a corrert apache configuration (in apache configuration file, such as apache2.conf or httpd.conf), that is you should set something like the following:
<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/html/your-path/to-local-wp>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
  • furthermore you should do this command: sudo a2enmod rewrite
  • and then sudo systemctl restart apache2

Get subtitles from a mkv

1) With Mkvtoolnix, if there is a subtitle in a mkv, you can easily extact it, deselecting all the other tracks and then giving the command “start multiplexing”: it will save that track as a mks file.

2a) If that track is a text one, you can easily convert it in a srt with this command (with a subtitle editor you could have to do another, easy conversion from an ass format to a real srt format):
mkvextract tracks "your-mks-file.mks" 0:a-name-you-want.srt.

2b) It the track is an image one (i.g. with one .sup file or two .sub e .idx files) you should use some online tool, such as subtitlestools.com so that from two files, sub e idx, you can one file srt. It could be a long process, waiting for your time aftr other users. But that webpage should keep working even you go offline and the day after you come back to download your srt file.

Sometimes however the easiest way is to find your srt files online, i.g. with OpenSubtitles.

Check android disk usage (and free space)

An useful open source android app to check how (by what apps or data) your device space is used, is Disky.

This “fast storage analyzer creates a pie chart of storage usage and lists folders by size”, very “intuitive and ad-free”.

I.g. yesterday, using this app I noticed that surprisingly an app (LinkToSport) was using 23 Gb.  Definitely too much 🙂.

difference between free and available

You could have an ext4 partition with almost 70 gb free (i.g. on KDE partition manager) but only a few more than 10 gb available in Dolphin.

Indeed free and available are not the same: free means the total space (available for root), available (in Dolphin) is the space for a single user.

If that partition is not a root one (=is not /) you could do something like:

sudo tune2fs -m 1 /dev/sdxx 
  • in the code above replace sdxx with the real name of your partition (you can know it, i.g. doing df -h), that is something like sdb8 or sdc6.
  • Be careful! Make sure that you have enough linux knowledge to do safely this kind of command. At your risk.

After your command, you should see that in that partition your user-available space is only 1gb less of the total space (that is 70 – 1). If your command would have been

sudo tune2fs -m 3 /dev/sdxx

Your user available space would be =70-3.

Kodi in openatv 7.6

Kodi working

Very painful to make it working. But something is being to become possible.

If Kodi, in you new OpenAtv installation (after restoring settings from another release) starts only from an external device (the device you used to restore settings and flash the new image) you can try to modify the kodi script in /usr/bin.

In this way:

you can reach your decoder from your PC via terminal, with something like

:~$ ssh root@sf8008.local 

if you have more than a partition on your decoder, you have to change your keys every time (each partition has its own keys), so you have to begin with:

:~$ ssh-keygen -R sf8008.local
# Host sf8008.local found: line 1
/home/[your-username]/.ssh/known_hosts updated.
Original contents retained as /home/[your-username]/.ssh/known_hosts.old
:~$ ssh root@sf8008.local
kf.notifications: Failed to play sound with canberra: File or data not found
Warning: Permanently added 'sf8008.local' (ED25519) to the list of known hosts.
root@sf8008:~# 

and then you can do
nano /usr/bin/kodi

find something like

[ -d /media/mmc ] && export HOME="/media/mmc"
[ -d /media/hdd ] && export HOME="/media/hdd"

and replace it with

ountpoint -q /media/hdd && export HOME="/media/hdd"
mountpoint -q /media/mmc && export HOME="/media/mmc"  


in my case, it did the trick.

Wrong zoom

To avoid a wrong zoom and a wrong position of the resized screen (with a black space on left and part of Kodi screen invisible, impossible to set/fix), avoid to start Kodi standalone (in Openatv – >plungis browser -> Kodi).

Fine tuning

However there were still big problems:

  • no way to reach a chapter and see that video normally (you can see a very slow video, almost still),
  • no way to resume a video from the last position,
  • no way to go forward or rewind (using the left right key).

Today I managed to resolve the first two ones:

  • settings – > player -> adjust display rate -> always
  • settings – > player -> sync playback -> on
  • settings – > player -> allow hardware acceleration – STB -> off

    as you can see in the screenshot below

Problems in OpenATV 7.6 can see found in their forum.

Kernel panic

You could have a kernel panic problem, booting your SO (.i.g Linux).

A possible cause could be Virtualbox (an old release of it).
In this case you can try the followings steps

sudo apt remove --purge virtualbox virtualbox-dkms
sudo dkms remove virtualbox/7.0.16 --all || true

and

sudo apt --fix-broken install
sudo dpkg --configure -a

and (you can change the number of kernels, of course, to adapt them to your situation)

sudo apt install --reinstall \
 linux-image-generic-hwe-24.04 \
 linux-headers-generic-hwe-24.04