Пример автоматически-сгенерированного веб-плеера для сайта (вставить в html)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
<hr><center><p><h3>* TM MUSIC PLAYER *</h3></p> <audio id='TM' controls src='https://musify.club/track/dl/5497392/deep-purple-knocking-at-your-back-door.mp3' type='audio/mpeg'></audio></center><hr> <script language='javascript'> let links=[ 'https://musify.club/track/dl/5497392/deep-purple-knocking-at-your-back-door.mp3', 'https://musify.club/track/dl/5497393/deep-purple-under-the-gun.mp3', 'https://musify.club/track/dl/5497394/deep-purple-nobodys-home.mp3', 'https://musify.club/track/dl/5497395/deep-purple-mean-streak.mp3', 'https://musify.club/track/dl/5497396/deep-purple-perfect-strangers.mp3', 'https://musify.club/track/dl/5497397/deep-purple-a-gypsys-kiss.mp3', 'https://musify.club/track/dl/5497398/deep-purple-wasted-sunsets.mp3', 'https://musify.club/track/dl/5497399/deep-purple-hungry-daze.mp3', 'https://musify.club/track/dl/63846/deep-purple-bad-attitude.mp3', 'https://musify.club/track/dl/63847/deep-purple-the-unwritten-law.mp3', 'https://musify.club/track/dl/63848/deep-purple-call-of-the-wild.mp3', 'https://musify.club/track/dl/63850/deep-purple-black-and-white.mp3', 'https://musify.club/track/dl/63851/deep-purple-hard-lovin-woman.mp3', 'https://musify.club/track/dl/63852/deep-purple-the-spanish-archer.mp3', 'https://musify.club/track/dl/63853/deep-purple-strangeways.mp3', 'https://musify.club/track/dl/63854/deep-purple-mitzie-dupree.mp3', 'https://musify.club/track/dl/63855/deep-purple-dead-or-alive.mp3', 'https://musify.club/track/dl/5497552/deep-purple-the-battle-rages-on.mp3', 'https://musify.club/track/dl/5497553/deep-purple-lick-it-up.mp3', 'https://musify.club/track/dl/5497554/deep-purple-anya.mp3', 'https://musify.club/track/dl/5497555/deep-purple-talk-about-love.mp3', 'https://musify.club/track/dl/5497556/deep-purple-time-to-kill.mp3', 'https://musify.club/track/dl/5497557/deep-purple-ramshackle-man.mp3', 'https://musify.club/track/dl/5497558/deep-purple-a-twist-in-the-tale.mp3', 'https://musify.club/track/dl/5497559/deep-purple-nasty-piece-of-work.mp3', 'https://musify.club/track/dl/5497560/deep-purple-solitaire.mp3', 'https://musify.club/track/dl/5497561/deep-purple-one-mans-meat.mp3', 'https://musify.club/track/dl/5497400/deep-purple-king-of-dreams.mp3', 'https://musify.club/track/dl/5497401/deep-purple-the-cut-runs-deep.mp3', 'https://musify.club/track/dl/5497402/deep-purple-fire-in-the-basement.mp3', 'https://musify.club/track/dl/5497403/deep-purple-fortuneteller.mp3', 'https://musify.club/track/dl/5497404/deep-purple-truth-hurts.mp3', 'https://musify.club/track/dl/5497405/deep-purple-love-conquers-all.mp3', 'https://musify.club/track/dl/5497406/deep-purple-breakfast-in-bed.mp3', 'https://musify.club/track/dl/5497407/deep-purple-too-much-is-not-enough.mp3', 'https://musify.club/track/dl/5497408/deep-purple-wicked-ways.mp3', 'https://musify.club/track/dl/6201747/deep-purple-mitzi-dupree.mp3' ]; let TOTAL=37; let CURRENT=0; var au=document.getElementById('TM'); au.onerror=function() { var ua=document.getElementById('TM'); CURRENT++; if (CURRENT >= TOTAL) CURRENT=0; ua.src=links[CURRENT]; ua.play(); }; au.onended=function() { var ua=document.getElementById('TM'); CURRENT++; if (CURRENT >= TOTAL) CURRENT=0; ua.src=links[CURRENT]; ua.play(); }; </script> |
Исходный код генератора плееров (консольное приложение C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace LinksToAudio { class Program { static void Main(string[] args) { string Html = File.ReadAllText(args[0]); List<string> links = ExtractMp3Links(Html); Console.WriteLine("<hr><center><p><h3>* TM MUSIC PLAYER *</h3></p>"); Console.WriteLine("<audio id='TM' controls src='" + links[0] + "' type='audio/mpeg'></audio></center><hr>"); Console.WriteLine(); Console.WriteLine("<script language='javascript'>"); Console.WriteLine("let links=["); for (int i = 0; i < links.Count; i++) { Console.Write("'{0}'", links[i]); if (i < links.Count - 1) Console.Write(","); Console.WriteLine(); } Console.WriteLine("];"); Console.WriteLine(); Console.WriteLine("let TOTAL={0};", links.Count); Console.WriteLine("let CURRENT=0;"); Console.WriteLine(); Console.WriteLine("var au=document.getElementById('TM');"); Console.WriteLine(@" au.onerror=function() { var ua=document.getElementById('TM'); CURRENT++; if (CURRENT >= TOTAL) CURRENT=0; ua.src=links[CURRENT]; ua.play(); }; au.onended=function() { var ua=document.getElementById('TM'); CURRENT++; if (CURRENT >= TOTAL) CURRENT=0; ua.src=links[CURRENT]; ua.play(); }; "); Console.WriteLine("</script>"); } static List<string> ExtractMp3Links(string html) { List<string> result = new List<string>(); for (int pos = 0; pos < html.Length; pos++) { if (html.Length - pos < 10) break; string beg = html.Substring(pos, "https://".Length); if (beg.StartsWith("http://") || beg.StartsWith("https://")) { int end = pos + "http".Length; while ( (end < html.Length - 4) && ( Char.IsLetter(html[end]) || Char.IsDigit(html[end]) || html[end] == '-' || html[end] == '_' || html[end] == '/' || html[end] == ':' || html[end] == '\\' || html[end] == '.' || html[end] == '?' || html[end] == '&' || html[end] == '=' ) && !html.Substring(end, ".mp3".Length).Equals(".mp3") ) end++; if (html.Substring(end, ".mp3".Length).Equals(".mp3")) { string link = html.Substring(pos, end + "mp3".Length - pos + 1); bool found = false; foreach (string r in result) if (r.Equals(link)) { found = true; break; } if (!found) result.Add(link); pos = end + ".mp3".Length; } } } return result; } } } |
Программа выше генерирует код веб-плеера mp3 по текстовому файлу или html сайта для вставки в html страничку. Без флеша, без мутных аудиопотоков, своё радио - за вечер, даже на бесплатном хостинге типа https://2x2forum.ru или https://sites.google.com и даже без платы за файловое хранилище, если ссылки давать на чужой сервер - там за хостинг файлов уже заплачено!
Пример встраивания - низ этого форума. Лайфхак, Таломир Миротал.
@Talomir Кстати, не обязательно в футер форума вставлять, если делать своё радио с бесплатным хостингом. Можно встроить фрагмент плеера html блоком на гугл сайтах (бесплатный хостинг сайта https://sites.google.com), я оттуда ушёл так как дофига отслеживания и рекламного преследования в городе, от ГУГЛа. Но теоретически-можно, если преследование гуглом не беспокоит.... Или на любом другом бесплатном хостинге, где можно встроить фрагмент html в конструкторе сайтов или закачать свои html файлы...!
Генератор радиостанций для web-страниц. Длинной 2 экрана исходника на C#. Генерирует код радиостанции по тектовому файлу со ссылками на mp3 или по сохранённой html страничке с музыкой (в ней должны быть ссылки на .mp3, которые генератор извлекает для создаваемого кода плеера).
5 минут на создание радиостанции.
Глобальная достижимость, прослушивание во всех точках планеты где есть интернет.
Глобальная совместимость. Сгенерированное радио играет на MacOS, Windows, Linux, Android. iOS, на смартфонах, кнопочных, планшетах, ноутбуках и настольных компьютерах - везде, где есть современный интернет браузер.
Простота плеера ведущая к надёжности и простоте исправлений и отладки, дописывания и редизайна плеера.
Бесплатные исходник генератора и плеера.
900dh, wait me on ai articles projects... Talomir Mirotal (TM) :-)
Фотки сгенерированного плеера (который можно додизайнить под конкретную страниц\сайт\форум)
На форуме https://anti-psy.2x2forum.ru
На пустой странице:
Генерируйте, дизайните сгенерированный html фрагмент с плеером под себя. Скорее всего неделю потрачу на отказоустойчивость скрипта, сейчас он перестаёт играть при пропажах\помехах интернету в части браузеров. Если улучшу - выложу в этой теме вторую версию, и генератора плееров и сгенерированный пример!
Вроде проблема именно в перегруженной странице, сложного форума, на пустой странице играет нормально даже с плохим интернетом.
РАДИОСТАНЦИЯ DEEP
Сделал на этом движке плеера сайт радиостанции DEEP с омолаживающи эффектом. Крутит 350 раритетных композиций deep purple 50-ти летней давности, погружая слушателя в атмосферу юности или детства. Смета:
Больше суток не спал, теперь сутки спать, день отдыхать, опять спать и садиться за ИИ для написания статей для сайтов, превосходящий любого автора интернета в выбранной области :-)
Послушать станцию (и на телефоне) или даже добавить в закладки: https://talomir.wixsite.com/deep
@Talomir
ВТОРАЯ УЛУЧШЕННАЯ ВЕРСИЯ ГЕНЕРАТОРА MP3 ПЛЕЕРОВ ДЛЯ МУЗЫКАЛЬНЫХ САЙТОВ
Код генератора:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace LinksToAudio { class Program { static void Main(string[] args) { string Html = File.ReadAllText(args[0]); string SUF = GenerateSuffix; List<string> links = ExtractMp3Links(Html); Console.WriteLine("<hr><center><p><h3>* TM MUSIC PLAYER *</h3></p>"); Console.WriteLine("<audio id='TM{0}' controls src='" + links[0] + "' type='audio/mpeg'></audio>",SUF); Console.WriteLine(); Console.WriteLine("<p>Now playing: <a id='PLAYING" + SUF + "'>"+Name(links[0])+"</a></p></center><hr>"); Console.WriteLine(); Console.WriteLine("<script language='javascript'>"); Console.WriteLine("let names{0}=[", SUF); for (int i = 0; i < links.Count; i++) { Console.Write("'{0}'", Name(links[i])); if (i < links.Count - 1) Console.Write(","); Console.WriteLine(); } Console.WriteLine("];"); Console.WriteLine(); Console.WriteLine("let links{0}=[", SUF); for (int i = 0; i < links.Count; i++) { Console.Write("'{0}'", links[i]); if (i < links.Count - 1) Console.Write(","); Console.WriteLine(); } Console.WriteLine("];"); Console.WriteLine(); Console.WriteLine("let TOTAL{1}={0};", links.Count, SUF); Console.WriteLine("let CURRENT{0}=0;", SUF); Console.WriteLine(); Console.WriteLine("var au=document.getElementById('TM{0}');", SUF); Console.WriteLine(@" au.onerror=function() { var ua=document.getElementById('TM" + SUF + @"'); CURRENT" + SUF + @"++; if (CURRENT" + SUF + @" >= TOTAL" + SUF + @") CURRENT" + SUF + @"=0; ua.src=links" + SUF + @"[CURRENT" + SUF + @"]; ua.play(); var bb=document.getElementById('PLAYING" + SUF + @"'); bb.textContent=names" + SUF + @"[CURRENT" + SUF + @"]; }; au.onended=function() { var ua=document.getElementById('TM" + SUF + @"'); CURRENT" + SUF + @"++; if (CURRENT" + SUF + @" >= TOTAL" + SUF + @") CURRENT" + SUF + @"=0; ua.src=links" + SUF + @"[CURRENT" + SUF + @"]; ua.play(); var bb=document.getElementById('PLAYING" + SUF + @"'); bb.textContent=names" + SUF + @"[CURRENT" + SUF + @"]; }; "); Console.WriteLine("</script>"); } static Random rnd = new Random(); static string GenerateSuffix { get { string a = "" + DateTime.Now.Millisecond + rnd.Next(1000000, 99999999); return a; } } static string Name(string url) { int start = url.LastIndexOf('/'); if (start < 0) start = url.LastIndexOf('\\'); if (start < 0) return "noname"; int end = url.LastIndexOf('.'); if (end < 0) end = url.Length; if (end <= start) return "noname"; string res = url.Substring(start+1, end - start-1); return res; } static List<string> ExtractMp3Links(string html) { List<string> result = new List<string>(); for (int pos = 0; pos < html.Length; pos++) { if (html.Length - pos < 10) break; string beg = html.Substring(pos, "https://".Length); if (beg.StartsWith("http://") || beg.StartsWith("https://")) { int end = pos + "http".Length; while ( (end < html.Length - 4) && ( Char.IsLetter(html[end]) || Char.IsDigit(html[end]) || html[end] == '-' || html[end] == '_' || html[end] == '/' || html[end] == ':' || html[end] == '\\' || html[end] == '.' || html[end] == '?' || html[end] == '&' || html[end] == '=' ) && !html.Substring(end, ".mp3".Length).Equals(".mp3") ) end++; if (html.Substring(end, ".mp3".Length).Equals(".mp3")) { string link = html.Substring(pos, end + "mp3".Length - pos + 1); bool found = false; foreach (string r in result) if (r.Equals(link)) { found = true; break; } if (!found) result.Add(link); pos = end + ".mp3".Length; } } } return result; } } } |
Пример сгенерированного плеера:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
<hr><center><p><h3>* TM MUSIC PLAYER *</h3></p> <audio id='TM47968294315' controls src='https://musify.club/track/dl/10637015/chillout-cafe-relax-under-the-palms.mp3' type='audio/mpeg'></audio> <p>Now playing: <a id='PLAYING47968294315'>chillout-cafe-relax-under-the-palms</a></p></center><hr> <script language='javascript'> let names47968294315=[ 'chillout-cafe-relax-under-the-palms', 'chillout-cafe-holiday-party', 'chillout-cafe-malibu-starter-vibes', 'chillout-cafe-relaxing-music', 'chillout-cafe-party-electronic-music', 'chillout-cafe-tropical-chill-out', 'chillout-cafe-bahama-mama', 'chillout-cafe-lounge-summer', 'chillout-cafe-dance-hits', 'chillout-cafe-bar-special', 'chillout-cafe-ibiza-poolside', 'chillout-cafe-sophisticated-holiday-parties', 'chillout-cafe-electronic-breaks', 'chillout-cafe-stress-relief', 'chillout-cafe-friends-giving-fun', 'chillout-cafe-beach-chill', 'chillout-cafe-hotel-del-mar', 'chillout-cafe-summer-beats', 'chillout-cafe-deep-heat-essentials', 'chillout-cafe-chill-reflection', 'chillout-cafe-pure-chill', 'chillout-cafe-relaxation', 'chillout-cafe-deep-vibes', 'chillout-cafe-ibiza-chill-out', 'chillout-cafe-sounds-of-sea', 'chillout-cafe-holiday-ringtones', 'chillout-cafe-waves', 'chillout-cafe-summer-holiday', 'chillout-cafe-chill-out-2017', 'chillout-cafe-chilling', 'chillout-cafe-bar-music-cafe', 'chillout-cafe-beach-chill-out', 'chillout-cafe-house-hits-playlist', 'chillout-cafe-exotic-getaway', 'chillout-cafe-paradise', 'chillout-cafe-sunset-road', 'chillout-cafe-ambient-summer', 'chillout-cafe-deep-vibes', 'chillout-cafe-relax', 'chillout-cafe-summertime', 'chillout-cafe-ibiza-2017', 'chillout-cafe-afterhours-chill-out', 'chillout-cafe-soft-vibrations', 'chillout-cafe-drink-bar', 'chillout-cafe-cafe-chillout' ]; let links47968294315=[ 'https://musify.club/track/dl/10637015/chillout-cafe-relax-under-the-palms.mp3', 'https://musify.club/track/dl/10637016/chillout-cafe-holiday-party.mp3', 'https://musify.club/track/dl/10637017/chillout-cafe-malibu-starter-vibes.mp3', 'https://musify.club/track/dl/10637019/chillout-cafe-relaxing-music.mp3', 'https://musify.club/track/dl/10637018/chillout-cafe-party-electronic-music.mp3', 'https://musify.club/track/dl/10563335/chillout-cafe-tropical-chill-out.mp3', 'https://musify.club/track/dl/10566718/chillout-cafe-bahama-mama.mp3', 'https://musify.club/track/dl/10566717/chillout-cafe-lounge-summer.mp3', 'https://musify.club/track/dl/10637024/chillout-cafe-dance-hits.mp3', 'https://musify.club/track/dl/10637020/chillout-cafe-bar-special.mp3', 'https://musify.club/track/dl/10563336/chillout-cafe-ibiza-poolside.mp3', 'https://musify.club/track/dl/10637021/chillout-cafe-sophisticated-holiday-parties.mp3', 'https://musify.club/track/dl/10637026/chillout-cafe-electronic-breaks.mp3', 'https://musify.club/track/dl/10637023/chillout-cafe-stress-relief.mp3', 'https://musify.club/track/dl/10637022/chillout-cafe-friends-giving-fun.mp3', 'https://musify.club/track/dl/10563338/chillout-cafe-beach-chill.mp3', 'https://musify.club/track/dl/10566730/chillout-cafe-hotel-del-mar.mp3', 'https://musify.club/track/dl/10563337/chillout-cafe-summer-beats.mp3', 'https://musify.club/track/dl/10637025/chillout-cafe-deep-heat-essentials.mp3', 'https://musify.club/track/dl/10637029/chillout-cafe-chill-reflection.mp3', 'https://musify.club/track/dl/10566719/chillout-cafe-pure-chill.mp3', 'https://musify.club/track/dl/10566720/chillout-cafe-relaxation.mp3', 'https://musify.club/track/dl/10566721/chillout-cafe-deep-vibes.mp3', 'https://musify.club/track/dl/10566722/chillout-cafe-ibiza-chill-out.mp3', 'https://musify.club/track/dl/10566723/chillout-cafe-sounds-of-sea.mp3', 'https://musify.club/track/dl/10566724/chillout-cafe-holiday-ringtones.mp3', 'https://musify.club/track/dl/10566725/chillout-cafe-waves.mp3', 'https://musify.club/track/dl/10566726/chillout-cafe-summer-holiday.mp3', 'https://musify.club/track/dl/10566727/chillout-cafe-chill-out-2017.mp3', 'https://musify.club/track/dl/10566728/chillout-cafe-chilling.mp3', 'https://musify.club/track/dl/10566729/chillout-cafe-bar-music-cafe.mp3', 'https://musify.club/track/dl/10566731/chillout-cafe-beach-chill-out.mp3', 'https://musify.club/track/dl/10637027/chillout-cafe-house-hits-playlist.mp3', 'https://musify.club/track/dl/10637028/chillout-cafe-exotic-getaway.mp3', 'https://musify.club/track/dl/10563339/chillout-cafe-paradise.mp3', 'https://musify.club/track/dl/10563340/chillout-cafe-sunset-road.mp3', 'https://musify.club/track/dl/10563341/chillout-cafe-ambient-summer.mp3', 'https://musify.club/track/dl/10563342/chillout-cafe-deep-vibes.mp3', 'https://musify.club/track/dl/10563343/chillout-cafe-relax.mp3', 'https://musify.club/track/dl/10563344/chillout-cafe-summertime.mp3', 'https://musify.club/track/dl/10563345/chillout-cafe-ibiza-2017.mp3', 'https://musify.club/track/dl/10563346/chillout-cafe-afterhours-chill-out.mp3', 'https://musify.club/track/dl/10563347/chillout-cafe-soft-vibrations.mp3', 'https://musify.club/track/dl/10563348/chillout-cafe-drink-bar.mp3', 'https://musify.club/track/dl/10563349/chillout-cafe-cafe-chillout.mp3' ]; let TOTAL47968294315=45; let CURRENT47968294315=0; var au=document.getElementById('TM47968294315'); au.onerror=function() { var ua=document.getElementById('TM47968294315'); CURRENT47968294315++; if (CURRENT47968294315 >= TOTAL47968294315) CURRENT47968294315=0; ua.src=links47968294315[CURRENT47968294315]; ua.play(); var bb=document.getElementById('PLAYING47968294315'); bb.textContent=names47968294315[CURRENT47968294315]; }; au.onended=function() { var ua=document.getElementById('TM47968294315'); CURRENT47968294315++; if (CURRENT47968294315 >= TOTAL47968294315) CURRENT47968294315=0; ua.src=links47968294315[CURRENT47968294315]; ua.play(); var bb=document.getElementById('PLAYING47968294315'); bb.textContent=names47968294315[CURRENT47968294315]; }; </script> |
Вид плеера на страничке радиостанци
КОД УТИЛИТЫ ДЛЯ ИЗВЛЕЧЕНИЯ MP3 ССЫЛОК ИЗ ТЕКСТА ДЛЯ ПЕРЕДАЧИ ФАЙЛА ГЕНЕРАТОРУ ПЛЕЕРОВ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace modulo_mp3links { class Program { static void Main(string[] args) { try { string html = File.ReadAllText(args[0]); List<string> links = ExtractMp3Links(html); foreach (string l in links) File.AppendAllText("MP3LINKS.txt", l + "\r\n"); } catch { } } static List<string> ExtractMp3Links(string html) { List<string> result = new List<string>(); for (int pos = 0; pos < html.Length; pos++) { if (html.Length - pos < 10) break; string beg = html.Substring(pos, "https://".Length); if (beg.StartsWith("http://") || beg.StartsWith("https://")) { int end = pos + "http".Length; while ( (end < html.Length - 4) && ( Char.IsLetter(html[end]) || Char.IsDigit(html[end]) || html[end] == '-' || html[end] == '_' || html[end] == '/' || html[end] == ':' || html[end] == '\\' || html[end] == '.' || html[end] == '?' || html[end] == '&' || html[end] == '=' ) && !html.Substring(end, ".mp3".Length).Equals(".mp3") ) end++; if (html.Substring(end, ".mp3".Length).Equals(".mp3")) { string link = html.Substring(pos, end + "mp3".Length - pos + 1); bool found = false; foreach (string r in result) if (r.Equals(link)) { found = true; break; } if (!found) result.Add(link); pos = end + ".mp3".Length; } } } return result; } } } |
ПРИМЕР СЕССИИ КОМАНДНОЙ СТРОКИ ДЛЯ ГЕНЕРАЦИИ ПРЕЕРА ПО СОХРАНЁННОЙ HTML СТРАНИЧКЕ С МУЗЫКОЙ
1 2 |
c:\folder\> modulo_mp3links.exe saved_page.html c:\filder\> PlayerGenerator.exe MP3LINKS.txt >player.html |
ПРИМЕР САЙТА С ТРЕМЯ ВСТРОЕННЫМИ СГЕНЕРИРОВАННЫМИ ПЛЕЕРАМИ
Сайт радиостанции Deep Purple:
ТРЕТЬЯ ВЕРСИЯ ГЕНЕРАТОРА HTML ПЛЕЕРОВ
В этой версии вместо линецного проигрывания композиций сверху-вниз по списку сделано псевдослучайное проигрывание. Фиксирована только нулевая композиция, с которой пользователь начинает на страничке. Все остальные композиции - в случайном порядке.
Код на C# генератора плееров на javascript-е:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace LinksToAudio { class Program { static void Main(string[] args) { string Html = File.ReadAllText(args[0]); string SUF = GenerateSuffix; List<string> links = ExtractMp3Links(Html); Console.WriteLine("<hr><center><p><h3>* TM MUSIC PLAYER *</h3></p>"); Console.WriteLine("<audio id='TM{0}' controls src='" + links[0] + "' type='audio/mpeg'></audio>",SUF); Console.WriteLine(); Console.WriteLine("<p>Now playing: <a id='PLAYING" + SUF + "'>"+Name(links[0])+"</a></p></center><hr>"); Console.WriteLine(); Console.WriteLine("<script language='javascript'>"); Console.WriteLine("let names{0}=[", SUF); for (int i = 0; i < links.Count; i++) { Console.Write("'{0}'", Name(links[i])); if (i < links.Count - 1) Console.Write(","); Console.WriteLine(); } Console.WriteLine("];"); Console.WriteLine(); Console.WriteLine("let links{0}=[", SUF); for (int i = 0; i < links.Count; i++) { Console.Write("'{0}'", links[i]); if (i < links.Count - 1) Console.Write(","); Console.WriteLine(); } Console.WriteLine("];"); Console.WriteLine(); Console.WriteLine("let TOTAL{1}={0};", links.Count, SUF); Console.WriteLine(); Console.WriteLine("var au=document.getElementById('TM{0}');", SUF); Console.WriteLine(@" au.onerror=function() { var ua=document.getElementById('TM" + SUF + @"'); var idx = Math.floor(Math.random() * (TOTAL" + SUF + @" + 1)); ua.src=links" + SUF + @"[idx]; ua.play(); var bb=document.getElementById('PLAYING" + SUF + @"'); bb.textContent=names" + SUF + @"[idx]; }; au.onended=function() { var ua=document.getElementById('TM" + SUF + @"'); var idx = Math.floor(Math.random() * (TOTAL" + SUF + @" + 1)); ua.src=links" + SUF + @"[idx]; ua.play(); var bb=document.getElementById('PLAYING" + SUF + @"'); bb.textContent=names" + SUF + @"[idx]; }; "); Console.WriteLine("</script>"); } static Random rnd = new Random(); static string GenerateSuffix { get { string a = "" + DateTime.Now.Millisecond + rnd.Next(1000000, 99999999); return a; } } static string Name(string url) { int start = url.LastIndexOf('/'); if (start < 0) start = url.LastIndexOf('\\'); if (start < 0) return "noname"; int end = url.LastIndexOf('.'); if (end < 0) end = url.Length; if (end <= start) return "noname"; string res = url.Substring(start+1, end - start-1); return res; } static List<string> ExtractMp3Links(string html) { List<string> result = new List<string>(); for (int pos = 0; pos < html.Length; pos++) { if (html.Length - pos < 10) break; string beg = html.Substring(pos, "https://".Length); if (beg.StartsWith("http://") || beg.StartsWith("https://")) { int end = pos + "http".Length; while ( (end < html.Length - 4) && ( Char.IsLetter(html[end]) || Char.IsDigit(html[end]) || html[end] == '-' || html[end] == '_' || html[end] == '/' || html[end] == ':' || html[end] == '\\' || html[end] == '.' || html[end] == '?' || html[end] == '&' || html[end] == '=' ) && !html.Substring(end, ".mp3".Length).Equals(".mp3") ) end++; if (html.Substring(end, ".mp3".Length).Equals(".mp3")) { string link = html.Substring(pos, end + "mp3".Length - pos + 1); bool found = false; foreach (string r in result) if (r.Equals(link)) { found = true; break; } if (!found) result.Add(link); pos = end + ".mp3".Length; } } } return result; } } } |
Пример сгенерированого плеера: https://talomir.wixsite.com/deep