Use .cast ext and application/x-asciicast media type

Closes #224
This commit is contained in:
Marcin Kulik
2017-12-01 22:48:24 +01:00
parent 4286e8f480
commit fe75b4e06c
3 changed files with 10 additions and 5 deletions

View File

@@ -206,7 +206,7 @@ Playing from HTTP(S) URL:
asciinema play http://example.com/demo.cast asciinema play http://example.com/demo.cast
Playing from asciicast page URL (requires `<link rel="alternate" Playing from asciicast page URL (requires `<link rel="alternate"
type="application/asciicast+json" href="....json">` in page's HTML): type="application/x-asciicast" href="/my/ascii.cast">` in page's HTML):
asciinema play https://asciinema.org/a/22124 asciinema play https://asciinema.org/a/22124
asciinema play http://example.com/blog/post.html asciinema play http://example.com/blog/post.html

View File

@@ -19,14 +19,16 @@ class Parser(html.parser.HTMLParser):
self.url = None self.url = None
def handle_starttag(self, tag, attrs_list): def handle_starttag(self, tag, attrs_list):
# look for <link rel="alternate" type="application/asciicast+json" href="https://...json"> # look for <link rel="alternate" type="application/x-asciicast" href="https://...cast">
if tag == 'link': if tag == 'link':
attrs = {} attrs = {}
for k, v in attrs_list: for k, v in attrs_list:
attrs[k] = v attrs[k] = v
if attrs.get('rel') == 'alternate' and attrs.get('type') == 'application/asciicast+json': if attrs.get('rel') == 'alternate':
self.url = attrs.get('href') type = attrs.get('type')
if type == 'application/asciicast+json' or type == 'application/x-asciicast':
self.url = attrs.get('href')
def open_url(url): def open_url(url):
@@ -57,7 +59,7 @@ def open_url(url):
url = parser.url url = parser.url
if not url: if not url:
raise LoadError("""<link rel="alternate" type="application/asciicast+json" href="..."> not found in fetched HTML document""") raise LoadError("""<link rel="alternate" type="application/x-asciicast" href="..."> not found in fetched HTML document""")
return open_url(url) return open_url(url)

View File

@@ -17,6 +17,9 @@ Example file:
[6.541828, "o", "Bye!"] [6.541828, "o", "Bye!"]
``` ```
Suggested file extension is `.cast`, suggested media type is
`application/x-asciicast`.
## Header ## Header
asciicast header is JSON-encoded object containing recording meta-data. asciicast header is JSON-encoded object containing recording meta-data.