August 4, 201511 yr Hi guys! I was playing with VLC Media Player's options and I created playlists in HTML based on my songs and an idea came into my mind. What if I'd implement a search function to search one or more keywords trough the html pages (to find a song)? I googled for it and all I got were some programs that work only in PHP and with servers, but I don't have such things. I'm hosting my test site (where I 'play', to say so) at a website that doesn't provide access to the necessary stuff to implement the function in any way I have seen while searching on google. My test site where I'd like to implement the function is this: http://alextests.pancakeapps.com/. You'll see that I managed to sort songs in a few categories. Then, another idea: what if I want to search a song in a particular category? Could I sort them alphabetically or some other way (ex. lenght) when the results are displayed? I'm sure there's a way to do this using Lucene, Solr, Sphider, etc, but (acording to what I understood) all these require server access and PHP support, while I can't even host PHP files (they just don't display themselves, it just pops up the .php file for download). Is there a way to do this with the things I can use? I mean, could this be done (even if not so complex) using my html pages and some scripts or something? By the way, this is just something I want to do for myself (searching a song) and yes, I know I can use Windows's search bar, but that's not the point. I'm curious if this could be done and how exactly. I'm sorry if this sounds stupid (I'm aware that this might not be possible), but I'm no 'web wizard' to know everything, and I figured out that (hopefully) here I might get some help form more people. If linking my website bothers any of the Mods or if I posted in the wrong section, they can delete/move this thread. Edited August 4, 201511 yr by alex_oiste
August 5, 201511 yr Try 000 webhost for free, PHP ad free hosting - that's where I started. Only use it for testing though as it's unreliable and slow lol. As for your question I think the only way, without a load of Javascript would be PHP. Edited August 5, 201511 yr by Ash Scott
August 5, 201511 yr Can you post an example of the HTML generated by VLC, from that ill be able to help you make a search bar without the need for PHP Edited August 5, 201511 yr by D4Y0
August 6, 201511 yr Author Try 000 webhost for free, PHP ad free hosting - that's where I started. Only use it for testing though as it's unreliable and slow lol. As for your question I think the only way, without a load of Javascript would be PHP. I'm trying it right now! Thanks for the tip! I'll try using PHP to do what I need now that I can work with it. Can you post an example of the HTML generated by VLC, from that ill be able to help you make a search bar without the need for PHP You can click on my website link in the main post and then just click on one category shown there (eg. All Songs ) and there you go, that's what VLC generates me. You can do it without PHP?
August 7, 201511 yr You can add this to your page and target with CSS, but the search results will be on Google, not on your site, unless you iframe the output: <form method="get" action="http://www.google.com/search"> <input type="text" name="q" size="31" maxlength="255" value=""> <input type="submit" value="Google Search"> </form> This will take whatever you type into the text input, and at the end of google.com/search will add ?q=XXXX, where XXXX is the term you typed into the input I that doesn't make sense let me know and I'll explain it better. Good luck!
August 7, 201511 yr Author You can add this to your page and target with CSS, but the search results will be on Google, not on your site, unless you iframe the output: <form method="get" action="http://www.google.com/search"> <input type="text" name="q" size="31" maxlength="255" value=""> <input type="submit" value="Google Search"> </form> This will take whatever you type into the text input, and at the end of google.com/search will add ?q=XXXX, where XXXX is the term you typed into the input I that doesn't make sense let me know and I'll explain it better. Good luck! Thank you, I was aware of that method and I've already tryed it. It's effective, yet it's not what I had in mind because I wanted the search results to be generated/displayed on my site directly without iframes. But I don't know if it's possible
August 7, 201511 yr Thank you, I was aware of that method and I've already tryed it. It's effective, yet it's not what I had in mind because I wanted the search results to be generated/displayed on my site directly without iframes. But I don't know if it's possible I see - it looks like a PHP system is your only option then :/ Have you considered putting your site on a CMS with a built in search function?
August 7, 201511 yr Author I see - it looks like a PHP system is your only option then :/ Have you considered putting your site on a CMS with a built in search function? I don't really know what a CMS is/does... I just googled it and I don't think I understood it in it's depth.
August 7, 201511 yr This is possible with javascript without the need for php. What this does is goes throgh every li element (the songs) and stores them in an array i then filter this array with the search string provided by teh input box and show/hide songs as the user types (more user friendly then having to click a button) It could be much better but it works <input type="text" name="search" placeholder="Search query ..."> <script> var elements = document.getElementsByTagName("li"); var data = []; for (var obj in elements) { if (typeof elements[obj].innerHTML === "string") { data[data.length] = elements[obj].innerHTML; } } document.querySelector("input[name=search]").addEventListener("keyup", function() { var html = ''; var searchQuery = this.value; var results = data.filter(function(o) { return (o.indexOf(searchQuery) !== -1); }); for (var obj in results) { html += "<li>" + results[obj] + "</li>"; } document.querySelector("ol").innerHTML = html; }); </script> Edited August 7, 201511 yr by D4Y0
August 7, 201511 yr Author This is possible with javascript without the need for php. What this does is goes throgh every li element (the songs) and stores them in an array i then filter this array with the search string provided by teh input box and show/hide songs as the user types (more user friendly then having to click a button) It could be much better but it works <input type="text" name="search" placeholder="Search query ..."> <script> var elements = document.getElementsByTagName("li"); var data = []; for (var obj in elements) { if (typeof elements[obj].innerHTML === "string") { data[data.length] = elements[obj].innerHTML; } } document.querySelector("input[name=search]").addEventListener("keyup", function() { var html = ''; var searchQuery = this.value; var results = data.filter(function(o) { return (o.indexOf(searchQuery) !== -1); }); for (var obj in results) { html += "<li>" + results[obj] + "</li>"; } document.querySelector("ol").innerHTML = html; }); </script> Hm, I think I did something wrong? I put the code on the page where I have all my songs indexed (this one) right after the <style></style> tags (which are right after the <body> tag), and you can see the result on the page I linked above. I type my search and the results don't appear, but the song list disappears. What did I do wrong?
August 7, 201511 yr Hm, I think I did something wrong? I put the code on the page where I have all my songs indexed (this one) right after the <style></style> tags (which are right after the <body> tag), and you can see the result on the page I linked above. I type my search and the results don't appear, but the song list disappears. What did I do wrong? It is my faulr as i was doing this in the console and forgot to wait for page load try this <input type="text" name="search" placeholder="Search query ..."> <script> document.addEventListener("DOMContentLoaded", function() { var elements = document.getElementsByTagName("li"); var data = []; for (var obj in elements) { if (typeof elements[obj].innerHTML === "string") { data[data.length] = elements[obj].innerHTML; } } document.querySelector("input[name=search]").addEventListener("keyup", function() { var html = ''; var searchQuery = this.value; var results = data.filter(function(o) { return (o.indexOf(searchQuery) !== -1); }); for (var obj in results) { html += "<li>" + results[obj] + "</li>"; } document.querySelector("ol").innerHTML = html; }); }); </script>
August 7, 201511 yr Author It is my faulr as i was doing this in the console and forgot to wait for page load try this <input type="text" name="search" placeholder="Search query ..."> <script> document.addEventListener("DOMContentLoaded", function() { var elements = document.getElementsByTagName("li"); var data = []; for (var obj in elements) { if (typeof elements[obj].innerHTML === "string") { data[data.length] = elements[obj].innerHTML; } } document.querySelector("input[name=search]").addEventListener("keyup", function() { var html = ''; var searchQuery = this.value; var results = data.filter(function(o) { return (o.indexOf(searchQuery) !== -1); }); for (var obj in results) { html += "<li>" + results[obj] + "</li>"; } document.querySelector("ol").innerHTML = html; }); }); </script> THIS is so awesome!! Thank you so much! It works! What if I want to add a filter to this? Is it possible?
August 7, 201511 yr THIS is so awesome!! Thank you so much! It works! What if I want to add a filter to this? Is it possible? There's a script I've used (http://www.listjs.com/examples) that works really well, especially when you have 1000's of rows.
August 7, 201511 yr Author what do you mean filter? I mean what if I want to search only through songs that have a length > 3 mins and start with letter E only in the Rock section? Is that possible? What about a particular sorting? By name, length? There's a script I've used (http://www.listjs.com/examples) that works really well, especially when you have 1000's of rows. Seems to work there on the website, but I'm not able to click the HTML CSS JS boxes to see the code used. I refreshed the page, even the cookies, what's the problem?
August 7, 201511 yr I mean what if I want to search only through songs that have a length > 3 mins and start with letter E only in the Rock section? Is that possible? What about a particular sorting? By name, length? Seems to work there on the website, but I'm not able to click the HTML CSS JS boxes to see the code used. I refreshed the page, even the cookies, what's the problem? Yeh I saw that. You need to click on the CodePen icon. The source is pretty lightweight for what it offers, and it has been well tested performance wise.
August 7, 201511 yr Is there any other format that VLC will out put the data as i.e. JSON or XML? with the HTML code you provided it is not possible as there isn't the data there to say if it is in a particular genre. Infact it is possible if you do it from the main page where you have the different menus it would be possible to load all of the files via ajax and filter like that. But that would be an inefficient way.
August 7, 201511 yr Author Is there any other format that VLC will out put the data as i.e. JSON or XML? with the HTML code you provided it is not possible as there isn't the data there to say if it is in a particular genre. Infact it is possible if you do it from the main page where you have the different menus it would be possible to load all of the files via ajax and filter like that. But that would be an inefficient way. The raw HTML VLC generates me is this: http://pastebin.com/JXg3eQF7. Does the first line make my HTML an XML document or something? I can generate only in HTML, XSPF, M3U and M3U8. I'll do some research to see if I can generate in other formats my playlists. Yeh I saw that. You need to click on the CodePen icon. The source is pretty lightweight for what it offers, and it has been well tested performance wise. Thank you! It works now! I'll have it as a back-up just in case (and also save it for further use).
August 10, 201511 yr Author I was expecting a reply, but ,anyway, I found out that I can generate my playlists in XSPF (XML Shareable Playlist Format). So, you asked for XML, right? Would this work? http://pastebin.com/GrAuWaYz
Create an account or sign in to comment