-1

I have a M3U playlist file and I want to output the whole file as text using javascript. I found an example but it doesnt seem to work and im not sure its right for what I want to do, heres what im using. The m3u playlist is this http://siptv.app/lists/example.m3u

    <div id="text"></div>

    var playlist = 'http://siptv.app/lists/example.m3u';

    function convertInto2KOM(m3u) {
        return m3u
            .replace('#EXTM3U', '')
            .split('#EXTINF:0,')
            .slice(1)
            .map(function(str, index) {
                var channel = str.split('\n').slice(0,-1);

                return {
                    "id": index + 1,
                    "number": index + 1,
                    "caption": channel[0],
                    "icon_url": "",
                    "tv_categories": [2],
                    "streaming_url": channel[1],
                    "announce": "",
                    "volume_shift": 0
                };
            });
    }


    var parseM3U = convertInto2KOM(playlist);
    console.log(parseM3U);
    $('#text').append(parseM3U);
lanjes
  • 81
  • 1
  • 8
  • Showing your sample M3U file would help. – Peter B Aug 10 '18 at 12:21
  • this is what i trying to get http://siptv.app/lists/example.m3u – lanjes Aug 10 '18 at 12:22
  • 1
    I don't actually see you read the file content anywhere, is that all of your code? You need to read the file content, right now it looks like you try to split up the string containing only the URL. – user3154108 Aug 10 '18 at 13:23
  • could you please give me an example on how to get this to work? I wasnt sure what to do so just used this code without knowing if it would work and it didnt – lanjes Aug 10 '18 at 13:24

1 Answers1

0

You can try

var playlist = '';
$.get('http://siptv.app/lists/example.m3u', function(data) {
   playlist = data;
}, 'text');

to read the file content into your playlist variable.

user3154108
  • 1,264
  • 13
  • 23
  • its still giving me no data – lanjes Aug 10 '18 at 13:31
  • Your cross-origin request for the m3u file is probably being blocked. You can tell when you open the console. That is a whole another cup of tea. – user3154108 Aug 10 '18 at 13:40
  • Tried it, but I run into CORS issues: `No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.` This might work, but definitely not from inside a browser context (because modern browsers will always send CORS headers and then expect a compatible CORS response, which you'll never get). – Peter B Aug 10 '18 at 13:41
  • im using it in phonegap so this shouldnt apply, do you have any other way it could work, different to the one i supplied? i found this solution that works http://jsfiddle.net/d2ntn6x2/70/ but what is the codesniff.com part about? does it rely on this to work? – lanjes Aug 10 '18 at 13:49