[vim/vim] Add syntax highlighting for HLS playlists (PR #11204)

42 views
Skip to first unread message

Benoît Ryder

unread,
Sep 23, 2022, 8:50:56 AM9/23/22
to vim/vim, Subscribed

This PR adds syntax highlighting for HTTP Live Streaming playlists (.m3u8):
https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-11

Feedbacks are welcome, especially regarding good practices for syntax plugins.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/11204

Commit Summary

  • de34382 Add syntax highlighting for HLS playlists

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204@github.com>

Bram Moolenaar

unread,
Sep 23, 2022, 11:17:02 AM9/23/22
to vim/vim, Subscribed


> This PR adds syntax highlighting for HTTP Live Streaming playlists (.m3u8):

Can we use a nicer name for this filetype? Perhaps hlsplaylist?

Please also add an entry in the test src/testdir/test_filetype.vim


--
hundred-and-one symptoms of being an internet addict:
141. You'd rather go to http://www.weather.com/ than look out your window.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256349075@github.com>

Benoît Ryder

unread,
Sep 23, 2022, 1:11:58 PM9/23/22
to vim/vim, Push

@benoitryder pushed 1 commit.

  • fa92d98 Rename 'm3u8' filetype to 'hlsplaylist' and add test


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/push/11118275754@github.com>

Benoît Ryder

unread,
Sep 23, 2022, 1:16:01 PM9/23/22
to vim/vim, Subscribed

Can we use a nicer name for this filetype? Perhaps hlsplaylist?

hlsplaylist is good. I changed the name, and added the test as requested.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256460630@github.com>

Bram Moolenaar

unread,
Sep 23, 2022, 3:34:21 PM9/23/22
to vim/vim, Subscribed

Closed #11204 via 35fdd9a.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/issue_event/7449876720@github.com>

Bram Moolenaar

unread,
Sep 23, 2022, 3:45:44 PM9/23/22
to vim/vim, Subscribed

The syntax file is using line continuation. the 'cpo' option needs to be set and restored. Se other syntax files for an example.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256608906@github.com>

Benoît Ryder

unread,
Sep 23, 2022, 4:17:38 PM9/23/22
to vim/vim, Subscribed

Thanks for noticing. I fixed it on my branch but since the the PR was already closed, the diff does not include it.
Updated file available here.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256634034@github.com>

ObserverOfTime

unread,
Sep 23, 2022, 5:52:56 PM9/23/22
to vim/vim, Subscribed

The .m3u extension is also valid. Also, I think mpegurl would be a better name.

https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-17.html#section-4

Each Playlist file MUST be identifiable by either the path component
of its URI or by HTTP Content-Type. In the first case, the path MUST
end with either .m3u8 or .m3u. In the second, the HTTP Content-type
MUST be "application/vnd.apple.mpegurl" or "audio/mpegurl".


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256711728@github.com>

Benoît Ryder

unread,
Sep 24, 2022, 8:36:09 AM9/24/22
to vim/vim, Subscribed

HLS playlists are based on the old M3U format, but they define their own format. It is not a superset of the M3U format with its common extensions, and it has not the same purpose. The HLS playlist mime-type is mpegurl most likely for historical reasons. But this name is never used when working with HLS. Using it has filetype can be confusing for users.

I've never seen the .m3u extension being used for HLS playlists. IMHO it's fine to not support it (and maybe reserve it for the old M3U format if support is added in the future), but adding it would not hurt.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256958998@github.com>

Bram Moolenaar

unread,
Sep 24, 2022, 9:09:35 AM9/24/22
to vim/vim, Subscribed


> HLS playlists are based on the old M3U format, but they define their
> own format. It is not a superset of the M3U format with its common
> extensions, and it has not the same purpose. The HLS playlist
> mime-type is `mpegurl` most likely for historical reasons. But this
> name is never used when working with HLS. Using it has filetype can be
> confusing for users.
>
> I've never seen the `.m3u` extension being used for HLS playlists.
> IMHO it's fine to not support it (and maybe reserve it for the old M3U
> format if support is added in the future), but adding it would not
> hurt.

Are the .m3u8 and .m3u files different enough to justify a different
filetype? Would they need different settings, indenting and syntax?

--
Send $25.00 for handy leaflet on how to make money by selling leaflets


/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256965086@github.com>

ObserverOfTime

unread,
Sep 24, 2022, 10:17:41 AM9/24/22
to vim/vim, Subscribed

M3U8 is just M3U with UTF-8 character encoding.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256978926@github.com>

Bram Moolenaar

unread,
Sep 24, 2022, 10:56:40 AM9/24/22
to vim/vim, Subscribed


> M3U8 is just M3U with UTF-8 character encoding.

Information about the files is a bit confusing and sometimes misleading.

Calling them HLS playlists also doesn't seem right, the files can be
used by many players.

"M3U files that are UTF-8 encoded are instead saved in the M3U8 file
format."

The name comes from "MP3 URL", but now other files are also supported,
thus "mp3" isn't quite right.

Something like "URL playlist" would be more accurate, but would users
recognize that name?

What if we just call it "playlist", would that have a problem?



--
hundred-and-one symptoms of being an internet addict:
165. You have a web page burned into your glasses


/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256988711@github.com>

Benoît Ryder

unread,
Sep 24, 2022, 11:14:12 AM9/24/22
to vim/vim, Subscribed

Are the .m3u8 and .m3u files different enough to justify a different filetype? Would they need different settings, indenting and syntax?

Syntax is compatible. But HLS playlists define elements specific to them, and don't use elements specific to M3U playlists. So both formats are compatible, but neither strict superset nor subset of each other.
Technically, the extension alone is not enough identify a .m3u8/.m3u as an M3U playlist or an HLS playlist. Hence some confusion in previous comments.

The proposed syntax file does not provide highlighting to tags not supported by HLS playlists but used by M3U playlists (but it could). It does not highlight wrong/erroneous constructs as errors; if it did, errors to report would not be the same for both cases.

What if we just call it "playlist", would that have a problem?

There are other playlist formats that use a completely different syntax (e.g. .pls). m3uplaylist would be a better compromise, recognizable by users.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1256991800@github.com>

Bram Moolenaar

unread,
Sep 24, 2022, 12:25:23 PM9/24/22
to vim/vim, Subscribed


> > Are the .m3u8 and .m3u files different enough to justify a different
> > filetype? Would they need different settings, indenting and syntax?
>
> Syntax is compatible. But HLS playlists define elements specific to
> them, and don't use elements specific to M3U playlists. So both
> formats are compatible, but neither strict superset nor subset of each
> other.
> Technically, the extension alone is not enough identify a .m3u8/.m3u
> as an M3U playlist or an HLS playlist. Hence some confusion in
> previous comments.

Thus an .m3u or .m3u8 file could also be another type, not a HLS
playlist. If we would have separate file types, we would have to
inspect the contents to see what it is? Assuming some HLS elements are
found there.


> The proposed syntax file does not provide highlighting to tags not
> supported by HLS playlists but used by M3U playlists (but it could).
> It does not highlight wrong/erroneous constructs as errors; if it did,
> errors to report would not be the same for both cases.
>
> > What if we just call it "playlist", would that have a problem?
>
> There are other playlist formats that use a completely different
> syntax (e.g. `.pls`). `m3uplaylist` would be a better compromise,
> recognizable by users.

OK, so we should not use just "playlist".


--
hundred-and-one symptoms of being an internet addict:
167. You have more than 200 websites bookmarked.


/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1257006521@github.com>

Benoît Ryder

unread,
Sep 24, 2022, 12:45:05 PM9/24/22
to vim/vim, Subscribed

If we would have separate file types, we would have to inspect the contents to see what it is?

Yes. We could check for a line starting with #EXT-X- among the first lines; and if there is one, consider it's an HLS playlist.
Note that some content providers add comments or empty lines at the beginning, so a good heuristic would be need to be smarter (e.g. defaulting to "HLS playlist" if extension is .m3u8 and M3U if extension is .m3u).


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1257011052@github.com>

Bram Moolenaar

unread,
Sep 24, 2022, 2:22:42 PM9/24/22
to vim/vim, Subscribed


> > If we would have separate file types, we would have to inspect the
> > contents to see what it is?
>
> Yes. We could check for a line starting with `#EXT-X-` among the first
> lines; and if there is one, consider it's an HLS playlist.
> Note that some content providers add comments or empty lines at the
> beginning, so a good heuristic would be need to be smarter (e.g.
> defaulting to "HLS playlist" if extension is `.m3u8` and M3U if
> extension is `.m3u`).

Well, we can add that check when it is needed. For now calling all
those files hlsplaylist would be OK.

So we should also recognize *.m3u, or are only *.m3u8 files used for
hlsplaylist?

--
"Hit any key to continue" does _not_ mean you can hit the on/off button!


/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1257036594@github.com>

Benoît Ryder

unread,
Sep 24, 2022, 3:08:10 PM9/24/22
to vim/vim, Subscribed

So we should also recognize *.m3u, or are only *.m3u8 files used for hlsplaylist?

Both are technically valid for HLS playlists, so we can recognize both.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1257046698@github.com>

Sandra Rivera

unread,
Sep 25, 2022, 4:38:45 AM9/25/22
to vim...@googlegroups.com, reply+ACY5DGB7HS3XYUCJ7K...@reply.github.com, Sandra Rivera (Sandy), vim/vim, Subscribed
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/vim/vim/pull/11204/c1256349075%40github.com.

Bram Moolenaar

unread,
Oct 11, 2022, 4:22:11 AM10/11/22
to vim/vim, Subscribed


> Thanks for noticing. I fixed it on my branch but since the the PR was already closed, the diff does not include it.
> Updated file available [here](https://raw.githubusercontent.com/benoitryder/vim/master/runtime/syntax/hlsplaylist.vim).

I'll merge it in.

--
Although the scythe isn't pre-eminent among the weapons of war, anyone who
has been on the wrong end of, say, a peasants' revolt will know that in
skilled hands it is fearsome.
-- (Terry Pratchett, Mort)


/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11204/c1274291484@github.com>

Reply all
Reply to author
Forward
0 new messages