Advanced Mobile VR Station Download Generator 3.1

In development download link generator

HTML

<div id="box">

  <h2>
  Advanced Download Generator for Mobile VR Station 3.1
  </h2>

  <p>
    <label for="url">Content Url (UTF-8 Encoded):</label> (Required)
    <br/>
    <input type="text" name="url" id="url" value="http://urltomedia" />
  </p>

  <ul>
    <li>Make sure the content url points to a video or zip file</li>
    <li>It must point to an actual zip file, not a redirecting website</li>
  </ul>

  <p>
    <label for="url">Title:</label> (Required)
    <br/>
    <input type="text" name="title" id="title">
  </p>
  
  <ul>
    <li>The title will be displayed while content is downloading</li>
  </ul>
  
  <p>
    <label for="url">Filename:</label> (Required)
    <br/>
    <input type="text" name="filename" id="filename">
  </p>

  <ul>
    <li>You must include the final file name of the link</li>
    <li>Include the extension, for example amovie<span style="font-weight:bold;">.mp4</span> or archive<span style="font-weight:bold;">.zip</span></li>
    <li>This is useful, incase you want to rename the file to include playback tags</li>
    <ul>
      <li>_LR : 3D Left-Right</li>
      <li>_RL : 3D Right-Left</li>
      <li>_TB : 3D Top-Bottom</li>
      
      <li>_360 : 2D 360</li>
      <li>_360_TB : 3D 360 Top-Bottom</li>
      <li>_360_LR : 3D 360 Left-Right</li>
      
      <li>_180 : 2D 180</li>
      <li>_180_LR : 3D 180 Left-Right</li>
      
      <li>_FFD : 2D Front Full Dome</li>
      <li>_FFD_LR : 3D Front Full Dome Left-Right</li>
      
    </ul>
  </ul>

  <p>
    <label for="url">Type:</label> (Required)
    <br/>
    <select name="contentType" id="contentType">
      <option value="dl">Download Only</option>
      <option value="dle">Download &amp; Extract</option>
    </select>
  </p>

  <p>
    <label for="autoplay">Auto-Play:</label> (Optional) (The filename to automatically display once the transfer is finished)
    <br/>
    <input type="text" name="autoplay" id="autoplay">
  </p>

  <ul>
    <li>For <b>Download</b> type...

CSS

#box {
  background: white;
  margin: 1em;
  padding: 1em;
}

.presetRequired {
  margin: 1em;
}

select,
input[type=text] {
  width: 80%;
}

JavaScript

$(function() {

  function replaceAll(str, find, replace) {
    return str.replace(new RegExp(find, 'g'), replace);
  }

  window.MVRS = {};

  $('#gen').click(function() {
    $('#result').val('');
    var media = $('#url').val(),
    		title = $.trim($('#title').val()),
        filename = $.trim($('#filename').val()),
        secure = $('#secure').prop('checked'),
        autoplay = $.trim($('#autoplay').val()),
      	type, i, link, js;
        
    if (filename.indexOf('/') >= 0 || filename.indexOf('\\') >= 0) {
    	alert('Filename contains an invalid character');
      return;
    } else if (!media) {
      alert('Please enter a content url');
      return;
    } else if (!title) {
      alert('Please enter a title');
      return;
    } else if (!filename) {
      alert('Please enter a filename');
      return;
    }
    type = $('#contentType').val() || '';

		

    js = {
    	v: 2,
      url: media,
      title: title,
      filename: filename,
      type: type
    }
    
    if (secure) {
    	js.se = true;
    }

		if (autoplay.length > 0) {
    	js.ap = autoplay;
    }
    
    if (js.autoplay && js.type == 'dl' && js.autoplay != js.filename) {
    	alert('Error: The autoplay file name does not match the actual filename.');
      return;
    }
    
    if (js.secure && !js.autoplay) {
    	alert('Error: Secure requests, require auto-play.');
      return;
    }

    var json =

      link = 'https://webvr.mobilevrstation.com/dl/' + replaceAll(window.btoa(JSON.stringify(js)), '=', '');

    $('#result').val(link).focus().select();
  });
  $("#result").focus(function() {
    $(this).select();
  });
});