Extract Multiple Media URLs for Aria2
This is a Tampermonkey userscript that helps you quickly extract direct media URLs (.mp3
, .mp4
, etc.) from the current web page and format them for downloading with aria 2.
Features
Scans the page for
<audio>
,<video>
, and<source>
elementsExtracts their media
src
URLs (including lazy-loaded or partial sources)Removes query strings (like
?_=1
) from the URLGenerates formatted output compatible with aria 2:
https://example.com/09.mp3?_=1 out=09.mp3
Copies the formatted list to your clipboard
Triggered by pressing Ctrl+Q on any page
Usage
- Install Tampermonkey in your browser.
- Add this userscript.
- Visit any web page with embedded media elements.
- Press Ctrl+Q to trigger extraction.
- Paste the copied output into:
AriaNg (
Add > Input > Paste
)A text file (
aria2_input.txt
) for use with:aria2c -i aria2_input.txt
Limitations
- Only detects media loaded directly via
<audio>
,<video>
, or<source>
tags. - Will not detect videos loaded via
<iframe>
, streaming manifests (.m3u8
,.mpd
), or Media Source Extensions (MSE). - Duplicate URLs are automatically filtered out.
// ==UserScript==
// @name Extract Media URLs for Aria2
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Extract media URLs and format for aria2
// @author AAA
// @match *://*/*
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
function cleanFilename(url) {
const base = url.split('?')[0]; // strip query
return decodeURIComponent(base.split('/').pop()); // get last segment
}
function extractMediaLinks() {
const mediaTags = [...document.querySelectorAll('audio, video, source')];
const urls = mediaTags.map(tag => tag.src || tag.currentSrc).filter(Boolean);
const uniqueUrls = [...new Set(urls)];
const aria2Lines = uniqueUrls
.map(url => `${url}\n out=${cleanFilename(url)}`)
.join('\n');
console.log('Extracted URLs:\n' + aria2Lines);
GM_setClipboard(aria2Lines);
alert(`Copied ${uniqueUrls.length} unique URL(s) in aria2 format to clipboard.`);
}
// Run it automatically or attach to shortcut
window.addEventListener('keydown', function(e) {
if (e.ctrlKey && e.key === 'q') { // Ctrl+Q
extractMediaLinks();
}
});
})();