Created
December 23, 2012 11:49
-
-
Save nfreear/4363061 to your computer and use it in GitHub Desktop.
Algorithm to create a unique URL for OU audio-visual (OU podcast tracks), version 1 / 24 November 2010.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Algorithm. | |
| */ | |
| ini_set('display_errors', 1); | |
| header('Content-Type: text/plain'); | |
| ?> | |
| /* | |
| Algorithm to create a unique URL for OU audio-visual (OU podcast tracks), version 1. | |
| (N.D.Freear, 24 nov 2010.) | |
| Aims: | |
| - To create a fairly short, friendly, unique URL for a HTML 'page' for each track or AV asset. | |
| - To NOT be affected by a new podcast track being added to the 'start' of the list. | |
| - To be agnostic to the container format/extension (ie. .M4V versus .OGV; .MP3 versus...) | |
| - To be agnostic to the particular 'view' of the asset (ie. video versus transcript). | |
| - To not be dependent on the actual location of the asset (eg. MP3 file). | |
| */ | |
| <?php | |
| $enclosure_url = | |
| 'http://podcast.open.ac.uk/feeds/l1314-spanish/l1314audio1.mp3'; | |
| $transcript_url= | |
| 'http://podcast.open.ac.uk/feeds/l1314-spanish/transcript/l1314audio1.pdf'; | |
| $album_permalink = 'http://podcast.open.ac.uk/pod/l1314-spanish'; #Check! | |
| $album_canonical = | |
| 'http://podcast.open.ac.uk/oulearn/languages/spanish/podcast-l1314-spanish'; | |
| $basename = basename($enclosure_url); | |
| $no_ext = preg_replace('/(.*)(\.\w+)/', '$1', $basename); | |
| $md5_noext = md5($no_ext); | |
| $md5_sub8 = substr($md5_noext, 0, 10); | |
| $unique_1 = "$album_permalink/$md5_sub8"; | |
| $unique_2 = "$album_permalink#!$md5_sub8"; | |
| $unique_3 = "$album_canonical/$md5_sub8"; | |
| $unique_4 = "$album_canonical#!$md5_sub8"; | |
| $output =<<<EOF | |
| # The location of the enclosure/ transcript may change. | |
| enclosure_url = $enclosure_url | |
| transcript_url = $transcript_url | |
| # This URL is unique for an album, and stable. | |
| album_permalink= $album_permalink | |
| # And this URL is where a user typically browses to - its unique and fairly stable! | |
| album_canonical= $album_canonical | |
| # 1. Get the filename. | |
| basename = $basename | |
| # 2. Remove the file extension. | |
| # (We don't care if the file is .M4V or .OGV; .MP3 or...) | |
| # (Note, this would be the same if we used the transcript_url.) | |
| noext = $no_ext | |
| # 3. Take the MD5 hash of noext. | |
| md5_noext = $md5_noext | |
| # 4. MD5 is too long - is it OK to take the first 10 characters? * | |
| md5_sub = $md5_sub8 | |
| # 5. Append the MD5 sub-string to the album permalink - should we support both '/' and '#!' ? ** | |
| unique_1 = $unique_1 | |
| unique_2 = $unique_2 | |
| # 6. Append the MD5 sub-string to the 'canonical' album URL - again '/' and '#!'. ** | |
| unique_3 = $unique_3 | |
| unique_4 = $unique_4 | |
| # 7. If later we wished to create YouTube-style deep-links, we could do this (that is, seek 1 minute 20 seconds into audio/video). | |
| deeplink = $unique_2/t=1m20s | |
| EOF; | |
| echo $output; | |
| ?> | |
| * The hashes used for Mercurial/hg changesets/revisions are 12 characters. | |
| ** For points 5/6, see Google's idea for AJAX and search engine friendly links. | |
| -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment