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

October - 2020

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:

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:

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:

<?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

 <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