Last active
August 29, 2015 14:20
-
-
Save keiya/5c3f28dcf9e26cd82aaf to your computer and use it in GitHub Desktop.
Chrome Extension / Generate a M3U or XSPF playlist from HTML <a> links. Useful for playing audios/movies on a HTTP server.
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
| $(document).ready(function(){ | |
| var exts = ["aif","avi","flac","m4a","mkv","mov","mp3","mp4","ogg","ogv","opus","wav"]; | |
| var m3u = ""; | |
| for (var i = 0; i < $('a').size(); ++i) { | |
| var $uri = $('a').eq(i); | |
| var absuri = $uri.attr('href'); | |
| var available_format = false; | |
| exts.forEach(function(ext) { | |
| if (absuri.lastIndexOf("."+ext) != -1) { | |
| available_format = true; | |
| } | |
| }); | |
| if (!available_format) continue; | |
| if (absuri.indexOf('/') == 0) { | |
| var uri = document.location.protocol + "//" | |
| + document.location.host | |
| + absuri; | |
| } | |
| else { | |
| var uri = document.location.protocol + "//" | |
| + document.location.host | |
| + document.location.pathname | |
| + absuri; | |
| } | |
| m3u += uri + "\n"; | |
| } | |
| var data = new Blob([m3u]); | |
| $("<a/>", { | |
| 'href': URL.createObjectURL(data), | |
| 'type':'audio/x-mpegurl', | |
| 'download':document.title+'.m3u', | |
| 'text':'download m3u', | |
| }).appendTo('body'); | |
| }); |
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
| function eschtml(body) { | |
| return jQuery('<div>').text(body).html(); | |
| } | |
| $(document).ready(function(){ | |
| var exts = ["aif","avi","flac","m4a","mkv","mov","mp3","mp4","ogg","ogv","opus","wav"]; | |
| var xspf = '<?xml version="1.0" encoding="UTF-8"?><playlist version="1" xmlns="http://xspf.org/ns/0/">\n<trackList>\n'; | |
| for (var i = 0; i < $('a').size(); ++i) { | |
| var $uri = $('a').eq(i); | |
| var absuri = $uri.attr('href'); | |
| var title = $uri.text(); | |
| var available_format = false; | |
| exts.forEach(function(ext) { | |
| if (absuri.lastIndexOf("."+ext) != -1) { | |
| available_format = true; | |
| } | |
| }); | |
| if (!available_format) continue; | |
| if (absuri.indexOf('/') == 0) { | |
| var uri = document.location.protocol + "//" | |
| + document.location.host | |
| + absuri; | |
| } | |
| else { | |
| var uri = document.location.protocol + "//" | |
| + document.location.host | |
| + document.location.pathname | |
| + absuri; | |
| } | |
| xspf += "<track><album>" + eschtml(document.title) + "</album><title>" + eschtml(title) + "</title><location>" + uri + "</location></track>\n"; | |
| } | |
| xspf += "</trackList></playlist>\n"; | |
| var data = new Blob([xspf]); | |
| $("<a/>", { | |
| 'href': URL.createObjectURL(data), | |
| 'type':'audio/x-mpegurl', | |
| 'download':document.title+'.xspf', | |
| 'text':'download xspf', | |
| }).appendTo('body'); | |
| }); |
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
| { | |
| "name": "PLS converter", | |
| "description": "", | |
| "version": "1.0", | |
| "content_scripts": [ | |
| { "matches": ["http://your_media_server/*"], "js": ["jquery-2.1.3.min.js","content_script_xspf.js"] } | |
| ], | |
| "permissions": [ | |
| "http://your_media_server/*", | |
| "notifications" | |
| ], | |
| "manifest_version": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment