Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My comments usage uppon method Comments example
# This module generate methods to generate video's fluxes
# before signing it and request it.
module DMCloud
class Streaming
# Get media url for direct link to the file on DailyMotion Cloud
# Params :
# media_id: this is the id of the media (eg: 4c922386dede830447000009)
# asset_name: the name of the asset you want to stream (eg: mp4_h264_aac)
# asset_extension: the extension of the asset, most of the time it is the first part of the asset name (eg: mp4)
# Result :
# return a string which contain the signed url like
# http://cdn.dmcloud.net/route/<user_id>/<media_id>/<asset_name>.<asset_extension>?auth=<auth_token>
def self.url(media_id, asset_name, asset_extension = nil)
asset_extension = asset_name.split('_').first unless asset_extension
raise StandardError, "missing :media_id in params" unless media_id
raise StandardError, "missing :asset_name in params" unless asset_name
# Convert tags to values and sign_url
stream = DIRECT_STREAM
stream.gsub!('[PROTOCOL]', DMCloud.config[:protocol])
stream.gsub!('[USER_ID]', DMCloud.config[:user_key])
stream.gsub!('[MEDIA_ID]', media_id)
stream.gsub!('[ASSET_NAME]', asset_name)
stream.gsub!('[ASSET_EXTENSION]', asset_extension)
stream += '?auth=[AUTH_TOKEN]'.gsub!('[AUTH_TOKEN]', DMCloud::Signing.sign(stream))
stream
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment