Seven days into a new year and nary a SPLOT related blog post… what’s going on around here?
Thar be rabbit holing in the code warren. I’ve still got a big surprise to add to SPLOTbox, which now has maybe all the features of three SPLOTs in one. This little bit blogged here is just a bit of cleanup, refinement, and a bit of fun API discovery. And wandering down and back from a path of malfunction.
It was an idea from Daniel Villar-Onrubia maybe a year or more ago to enable the SPLOTbox to support adding video from the Internet Archive. I noticed on a site he crafted that it also supported audio content.
The thing was, the audio player is thin, but the way I had it displayed, it took up all the space allowed for the video player.
![Comparison of en emdedded video (left) and audio (right) from Internet Archive, with a large amount of wasted space because they are sized the same. It does not matter to you if you cannot see it, but...](https://cogdogblog.com/wp-content/uploads/2020/01/ia-audio-video-before-760x554.jpg)
So the thing to figure out is, from these kinds of URLs, how can you determine if it points to content that is video vs audio?
- https://archive.org/details/audreywattersdoooworkshop
- https://archive.org/details/Jolly_Fish_1932
I pondered it, and guessed that maybe there is an Internet Archive API I could call to find this info. The answer is yes, one can get metadata about any archive item.
You have to extract the item ID, which is the part of the URL after details/
. At first I did this by simple php locating this in the URL (str_pos
function) and then getting a substring to get all the characters after. Later I found this did not work with some video URLs that have extra start/end values in the URL.
Thus it is easier to take the URL as a string, use the PHP explode function to split it into arrays based on the “/” character, and the ID will always be the fourth item.
I did this by just testing a basic test script locally.
1 2 3 4 5 6 7 8 |
//url to test $url = 'https://archive.org/details/Jolly_Fish_1932'; // explode into array by the "/" $sp = explode('/', $url); //spit out the fourth item echo $sp[4]; |
And sure enough, the test returns Jolly_Fish_1932
.
I can then try out this call on either of my URLs by using this API to get just the metadata
- https://archive.org/metadata/audreywattersdoooworkshop/metadata
- https://archive.org/metadata/Jolly_Fish_1932/metadata
And this is thus available via the mediatype:
value (noting that Internet Archive video is sometimes mediatyped as “video” other times “movies” while I found results for audio as mediatyped “audio” or “etree”)
![JSON data for results of first link, showing media:audio as the data we seek](https://cogdogblog.com/wp-content/uploads/2020/01/mediatype-audio-760x236.jpg)
![API results for the second URL as mediatype:movies](https://cogdogblog.com/wp-content/uploads/2020/01/mediatyp-tj-1280x210.jpg)
Without going to the bottom of the coding hole, this is my function that makes an API call for a given Internet Archive URL, and returns the resulting media type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
function splotbox_fetch_iarchive_type ( $url ) { // use Internet Archive API to get the media type for a given URL // split url by "/" $url_array = explode('/', $url); // extract id as fourth element $iaid = $url_array[4]; // construct URL for Internet Archive metadata API URL // see http://blog.archive.org/2013/07/04/metadata-api/ $json_url = 'https://archive.org/metadata/' . $iaid . '/metadata'; // get some json, jason! $json = file_get_contents( $json_url ); if ( $json ) { $data = json_decode( $json, TRUE ); // return the results from one item result, media type return ($data['result']['mediatype']); } else { // error, error, Jason, maybe a bad URL, Earl return( false ); } } |
All of this leads to when it’s time to display the item, if it is an audio media type, it embeds via a shorter iframe size (the variable videoplayer
is a leftover from when all this did ws video, but who cares?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Internet Archive // use function to get media type via API $iamediatype = splotbox_get_iarchive_type ( $url ); // use a substitution to turn the public link to it's embed one $archiveorg_url = str_replace ( 'details' , 'embed' , $url ); if ( splotbox_is_ia_supported_audio( $iamediatype ) ) { // use smaller player for audio $videoplayer = '<iframe src="' . $archiveorg_url . '" width="100%" height="40" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" class="ia-audio" allowfullscreen></iframe>'; } elseif ( splotbox_is_ia_supported_video( $iamediatype ) ) { // regular player size for video $videoplayer = '<iframe src="' . $archiveorg_url . '" width="640" height="480" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen class="ia-video"></iframe>'; } else { $videoplayer = '<code>' . $iamediatype . '</code> is not a supported Internet Archive media type'; } |
Look at the difference!
![The same paired video and audio embeds, but now there is no blank space on the audio content.](https://cogdogblog.com/wp-content/uploads/2020/01/splotbox-after-760x598.jpg)
Once an item is published, the mediatype is stored as a custom post type, so we don’t have to make an API call on every load.
Okay, I then got carried a way. I noted there were equivalent embed codes for all content in the Internet Archive, and I imagined a SPLOTbox could handle text, software, all the goodies on the site. I even built out a prototype SPLOTbox as a premise that you could build a site where the only content it collected was from the Internet Archive.
OOPS. I discovered the embeds did not all display, many of them for books, texts, etc showed up blank. I did not wander farther down the road to sort out how these embeds were done, I decide to fold the tent back, and keep support limited to audio and video content, the stuff that embeds.
Wow.
I wonder if anyone would have ever noticed. But this did bother me enough to see if I could sort out this small issue. Better yet, I got better at running API calls behind the scene in WordPress (this is a huge door opener into WordPress, and as have already done, out of WordPress – which I still think is one of the biggest things I’ve code in a while. No one else seems to notice.) .
I’ve already rigged up a version of SPLOTbox that can be used to support group authored podcasts. Amazing? I thought that was insanely useful.
And this most recently updated version even has a nifty admin menu that opens the customizer to the view of the sharing form, where you can change all of the form section labels and instructions. How many themes can you do THAT on?
![](https://cogdogblog.com/wp-content/uploads/2020/01/share-form-customizer-760x463.jpg)
But Wait
There is something I have partly working as prototype as a new way to add media to SPLOTbox (and maybe a possible stand alone plugin) that should knock your socks off.
Until then, give the most current version of SPLOTbox a run at http://splot.ca/box or download and try it on your own domain from https://github.com/cogdog/splotbox. I am hoping soon we can get this added to Reclaim Hosting’s featured apps as a one click install.
Forget innovating in or out of boxes- build some media in your own SPLOTbox.
Feature Image: Modified a Wikimedia Commons image File:Geiger counter usage.jpg shared into the public domain as a work of a US Government agency. Changes included adding URLs and an Internet Archive logo to the cans being examined.
This is great! I feel I’ve been very remiss with my promises to test all the SPLOT goodness that you’ve been cranking out. Just as soon as I get my self settled (and get home internet!) I’ll get on it!
I’m new to blogging and coding and this is truly helpful and amazing. Thanks.