Permalink
Browse files

Added underlying content type. Patched tests

  • Loading branch information...
1 parent 141edc7 commit d8cd4b997a124316af9dabddbc74d2067baacbb4 amix committed Apr 22, 2014
Showing with 75 additions and 74 deletions.
  1. +20 −10 lib/media-parser.js
  2. +1 −1 package.json
  3. +16 −10 src/media_services.coffee
  4. +4 −1 src/media_types.coffee
  5. +17 −29 tests/test_core.coffee
  6. +17 −23 tests/test_core.js
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3,7 +3,7 @@
"description": "Simple JavaScript library to ease integration with media and oEmbed.",
"keywords": ["oembed", "media", "thumbnails", "preview"],
"author": "amix",
- "version": "1.4.2",
+ "version": "1.4.3",
"dependencies": {},
"repository": "https://github.com/Doist/media-parser",
"licenses": [{
View
@@ -50,6 +50,7 @@ MediaServices = {
match = cnt.match(MediaServices.providers.Imgly)
if match
MediaTypes.imageEntity(callback, {
+ 'underlying_type': 'image'
'sizes': {
'thumb': 50,
'mini': 75,
@@ -67,6 +68,7 @@ MediaServices = {
match = cnt.match(MediaServices.providers.Instagram)
if match
MediaTypes.imageEntity(callback, {
+ 'underlying_type': 'image'
'sizes': {
't': 150,
'm': 306,
@@ -82,6 +84,7 @@ MediaServices = {
match = cnt.match(MediaServices.providers.Twitpic)
if match
MediaTypes.imageEntity(callback, {
+ 'underlying_type': 'image'
'sizes': {
'mini': 75,
'thumb': 50,
@@ -97,6 +100,7 @@ MediaServices = {
match = cnt.match(MediaServices.providers.Yfrog)
if match
MediaTypes.imageEntity(callback, {
+ 'underlying_type': 'image'
'sizes': {
'small': 100,
'medium': 640
@@ -111,6 +115,7 @@ MediaServices = {
match = cnt.match(MediaServices.providers.Flickr)
if match
MediaTypes.oembedImageEntitiy(callback, {
+ 'underlying_type': 'image'
'timeout': timeout
'sizes': {
't': 75,
@@ -130,62 +135,63 @@ MediaServices = {
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.DevaiantArt,
'https://backend.deviantart.com/oembed?url={0}&format=json',
- timeout)
+ timeout, 'image')
# --- Hulu
parseHulu: (cnt, callback, timeout) ->
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.Hulu,
'http://www.hulu.com/api/oembed?url={0}&format=json',
- timeout)
+ timeout, 'video')
# --- Justin
parseJustin: (cnt, callback, timeout) ->
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.JustinTv,
'http://api.justin.tv/api/embed/from_url.json?url={0}',
- timeout)
+ timeout, 'video')
# --- Screenr
parseScreenr: (cnt, callback, timeout) ->
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.Screenr,
"http://www.screenr.com/api/oembed.json?url={0}",
- timeout)
+ timeout, 'video')
# --- Rdio
parseRdio: (cnt, callback, timeout) ->
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.Rdio,
"http://www.rdio.com/api/oembed/?url={0}&format=json",
- timeout)
+ timeout, 'audio')
# --- Soundcloud
parseSoundCloud: (cnt, callback, timeout) ->
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.Soundcloud,
"https://soundcloud.com/oembed?url={0}&format=json",
- timeout)
+ timeout, 'audio')
# --- Spotify
parseSpotify: (cnt, callback, timeout) ->
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.Spotify,
"https://embed.spotify.com/oembed/?url={0}&format=json",
- timeout)
+ timeout, 'audio')
# --- Ted
parseTed: (cnt, callback, timeout) ->
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.Ted,
"http://www.ted.com/talks/oembed.json?url={0}",
- timeout)
+ timeout, 'video')
# --- Vimeo
parseVimeo: (cnt, callback, timeout) ->
match = cnt.match(MediaServices.providers.Vimeo)
if match
MediaTypes.oembedImageEntitiy(callback, {
+ 'underlying_type': 'video'
'timeout': timeout
'sizes': {
'100': 100,
@@ -204,6 +210,7 @@ MediaServices = {
match = cnt.match(MediaServices.providers.Slideshare)
if match
MediaTypes.oembedImageEntitiy(callback, {
+ 'underlying_type': 'page'
'timeout': timeout
'sizes': {
'3': 240,
@@ -225,7 +232,6 @@ MediaServices = {
return MediaTypes.genericOemebed(cnt, callback,
MediaServices.providers.Youtube,
"http://www.youtube.com/oembed?url={0}&format=json",
- timeout)
-
+ timeout, 'video')
}
View
@@ -2,6 +2,7 @@ MediaTypes = {
imageEntity: (callback, opts) ->
return callback({
+ 'underlying_type': opts.underlying_type
'sizes': opts.sizes
'content_url': opts.match[0]
'get_thumbnail_url': (size) ->
@@ -12,11 +13,12 @@ MediaTypes = {
return [url, width, width]
})
- genericOemebed: (cnt, callback, reg_exp, oembed_template, timeout) ->
+ genericOemebed: (cnt, callback, reg_exp, oembed_template, timeout, underlying_type) ->
match = cnt.match(reg_exp)
if match
MediaTypes.oembedImageEntitiy(callback, {
+ 'underlying_type': underlying_type
'timeout': timeout
'match': match
'oembed_template': oembed_template
@@ -56,6 +58,7 @@ MediaTypes = {
result.title = json.title or ''
result.raw = json
+ result.underlying_type = opts.underlying_type
# Resolve content type
if result.content_url
Oops, something went wrong.

0 comments on commit d8cd4b9

Please sign in to comment.