Ampache auto skip

Auto-Skip TamperMonkey/GreaseMonkey script for corrupt MP3s

My Ampache web player gets stuck one second before the end of some MP3 tracks because the file headers say that it is one second longer than the stream actually is.

This script runs in the browser and checks to see if there is still one second to go and also that the play button is visible.

This is the case when an MP3 is corrupt for me and so this script just presses the skip button so I can still enjoy my albums without having to look at the player.

Please feel free to make it better and post back the changes so I can improve my own experience, thanks :)

// ==UserScript==
// @name       Ampache Autoskip
// @namespace  http://tom-gould.co.uk/blog/ampache-auto-skip
// @version    0.1
// @description  Skips the track if Ampache fails to
// @match      http://yourserver.com/*
// @copyright  2012+, Tom Gould
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
var skipAmpache = function () {
    var currentTime = jQuery('div.jp-current-time').html();
    var duration = jQuery('div.jp-duration').html();
    if (undefined == currentTime || undefined == duration) {
      setTimeout(skipAmpache, 3000);
      return;
    }
    var cur = parseFloat(currentTime.replace(':', ''));
    var dur = parseFloat(duration.replace(':', ''));
    var diff = dur - cur;
    if (diff <= 1 && jQuery('.jp-play').css('display') == 'block') {
        console.log('Skipping: ' + jQuery('.playing_title a').html());
        jplaylist.next();
        setTimeout(skipAmpache, 10000);
        return;
    }
 
    setTimeout(skipAmpache, 1000);
};
 
skipAmpache();

Comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.