Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Finishing URL Grabber V1 - Working On A Fix For Hugos YouTube Autoplay

*NOTE: TODO: This page needs updates to work with MDX*

`youtube: https://www.youtube.com/watch?v=sq5RUw8b_tI`

### [Start: 00:00:00] - Finishing Daily URL Grabber

Spent the first part of the stream finishing up the first version of my Daily URL Grabber. Two pieces of code that were helpful this snippet that sorts a dict by value:

Code

sort_items = sorted(self.object_data.items(), key=lambda x: x[1].lower())
for item in sort_items:
    print(item[1])

And this method I setup which writes to a file after making any needed directories in its path:

Code

import os
import os.path

def write_file_with_mkdir(*, path, content):
    directory = os.path.dirname(path)
    os.makedirs(directory, exist_ok=True)
    with open(path, "w") as output_file:
        output_file.write(content)

write_file_with_mkdir(
    path = "/Users/alans/Desktop/tmp/test/folder/file.txt",
    content = "the quick brown fox"
)

The last thing to do was to setup the trigger to capture the URLs from my tabs every 5 minutes. I used this launchd script for that:

Code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
<dict>

  <key>Label</key>
    <string>com.alanwsmith.url_archiver.plist</string>

  <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/python3</string>
        <string>/Users/alans/toolkit/url_archiver/archive_urls.py</string>
    </array>

  <key>StartInterval</key>
    <integer>300</integer>

</dict>
</plist>

For the setup, I decided to keep the source file in the same directory as the main script and then use a symbolic link for it in `~/Library/LaunchAgents`.

The `osascript` call inside the python file used a relative path. It took me a bit to figure out that since I was calling the python with launchd I needed to use full paths. Once they were in place, everything worked nicely.

I've got some more work that I'd like to do cleaning and filtering URLs and updating the output template but the first version is in production.

### [Time: ] - Setting Hugo YouTube Shortcode To Work With Muted Autoplay

The second

Code

<div class="youtube_video">
  <iframe 
  src="https://{{ $ytHost }}/embed/{{ $id }}{{ with .Get "autoplay" }}{{ if eq . "true" }}?autoplay=1&mute=1{{ end }}{{ end }}" 
  allowfullscreen title="YouTube Video"></iframe>
</div>

### Links From The Stream

- Allow or block media autoplay in Firefox - Auto-Play Policy Changes for macOS - Autoplay Policy Changes   - Cooperative asynchronous JavaScript: Timeouts and intervals - Learn web development - Customise YouTube controls, title and the whole iFrame - Stack Overflow - Darkwing Duck's Intro Interuppted by Launchpad - YouTube - David Guetta - Shot Me Down ft. Skylar Grey (Lyric Video) - YouTube - Design Patterns - Wikipedia - Design Patterns Book - DEV Community 👩‍💻👨‍💻 - Docendo discimus - Wikipedia - Example Domain - Exercism - Gang Of Four - GangOfFour - Glossary — Python 3.9.0 documentation - How does Jekyll date formatting work? - Stack Overflow - How to detect if Chrome/Safari/Firefox prevented autoplay for video? - Stack Overflow - How to Embed a YouTube Video with Sound Muted - Digital Inspiration - How to Execute Shell Commands with Python - Parametric Thoughts - How to Sort a Dictionary by Value in Python - Nikolai Janakiev (@njanakiev) / Twitter - Nikolai Janakiev - Parametric Thoughts - On Computable Numbers - Online Courses - Learn Anything, On Your Schedule - os — Miscellaneous operating system interfaces — Python 3.9.0 documentation - os.path — Common pathname manipulations — Python 3.9.0 documentation - Python - Sorting HOW TO — Python 3.9.0 documentation - Stack Overflow - Where Developers Learn, Share, & Build Careers - Turing Machine - What is the JavaScript version of sleep()? - Stack Overflow - WindowOrWorkerGlobalScope.setTimeout() - Web APIs - youtube doesnt autoplay on refreshing site or videos from bookmark : firefox - YouTube embed doesn't autoplay on initial load. Will autoplay on refresh - Stack Overflow - YouTube Embedded Players and Player Parameters - YouTube Player API Reference for iframe Embeds - YouTube: How to present embed video with sound muted - Stack Overflow