PDA

View Full Version : Flazr - open source RTMP stream saver


jace89
05-04-2009, 11:50 AM
i found a new program called flazr (http://flazr.com/)
I don't know how to use that. maybe you can help.

it is not a user-friendly software. flazr is more for programmers than for regular users.

Flazr is a Java implementation of the RTMP protocol using the excellent Apache Mina project. I think I was able to come up with a far more concise and readable implementation than what the Red5 project uses - which is not that surprising - because the scope of Red5 is much bigger and Flazr focuses only on the client side. I do feel that Flazr will be useful as an additional reference for those interested in understanding the details of the RTMP protocol.

One of the highlights of Flazr (especially from a Java perspective) is the usage of Groovy for scripting. Groovy allows the end-user to script things such as scraping the HTML from a given URL, parsing it and then invoking the RTMP client routine with the right parameters. All this in a platform-independent manner, without the need to compile anything and using a normal text-editor. I expect Flazr’s Groovy approach to be much easier to use (and arguably more powerful) than the PERL-driven approach that projects like “get_iplayer” and “rtmpdump” use.

Flazr has been designed so that end-users can extend the capabilities far beyond what the core supports - using just some plain-text Groovy scripts. This means that end-users won’t need to depend on the project team (*ahem* just me for now :) to pitch in and make changes. I’m quite interested to see how this turns out in practice.

flazr v.0.5 doesn't support RTMP h.264 streams.

Stream Recorder
06-17-2009, 03:24 AM
Script for downloading videos from Yahoo ! Music with flazr
This is an example of how you can easily write a script to request an HTML page (or XML data in this case), parse the contents and extract the values needed to invoke the main RTMP client / download routine

import com.flazr.*

def videoId = "201620741"

def url = "http://video.music.yahoo.com/ver/268.0/process/getPlaylistFOP.php?node_id=v" \
+ videoId + "&tech=flash&bitrate=5000&eventid=1301797";

def xml = Utils.getOverHttp(url)

println xml

def data = new XmlSlurper().parseText(xml)
def stream = data.'SEQUENCE-ITEM'[1].STREAM

def tcUrl = stream.@APP.text()
def host = stream.@SERVER.text()
def queryString = stream.@QUERYSTRING.text()
def path = stream.@PATH.text().substring(1)

def app = tcUrl.substring(tcUrl.lastIndexOf('/') + 1)
def playParam = path.substring(0, path.lastIndexOf('.')) + '?' + queryString

println 'queryString: ' + queryString + '\n'
println 'path: ' + path + '\n'
println 'playParam: ' + playParam + '\n'
println 'app: ' + app + '\n'

def session = new RtmpSession(host, 1935, app, playParam, 'test.flv')

RtmpClient.connect session

Stream Recorder
06-17-2009, 03:26 AM
Script for downloading videos from Yahoo ! Music with flazr
this is an example of how you can customize the low-level details of things like the handshake and pass values that the server is expecting
import com.flazr.*


def videoId = "201620741"

def url = "http://video.music.yahoo.com/ver/268.0/process/getPlaylistFOP.php?node_id=v" \
+ videoId + "&tech=flash&bitrate=58&mode=&lg=Lox6nE093DOEBHJ_XTuPaP&vidH=326&vidW=576&rd=new.music.yahoo.com&lang=us&tf=controls&eventid=1301797&tk=";

def xml = Utils.getOverHttp(url)

println xml

def data = new XmlSlurper().parseText(xml)
def stream = data.'SEQUENCE-ITEM'[1].STREAM

def tcUrl = stream.@APP.text()
def host = stream.@SERVER.text()
def queryString = stream.@QUERYSTRING.text()
def path = stream.@PATH.text().substring(1)

def app = tcUrl.substring(tcUrl.lastIndexOf('/') + 1)
def playParam = path.substring(0, path.lastIndexOf('.')) + '?' + queryString

println 'tcUrl: ' + tcUrl
println 'queryString: ' + queryString
println 'path: ' + path
println 'playParam: ' + playParam
println 'app: ' + app

def mysession = new RtmpSession(host, 1935, app, playParam, 'test.flv')

params = mysession.connectParams

params.flashVer = 'WIN 10,0,12,36'
params.swfUrl = 'http://d.yimg.com/cosmos.bcst.yahoo.com/ver/268.0/embedflv/swf/fop.swf'
params.tcUrl = tcUrl
params.pageUrl = 'http://new.music.yahoo.com/videos/Beyonc/Single-Ladies-(Put-A-Ring-On-It)--201620741'
params.audioCodecs = 3191
params.remove 'objectEncoding'

println params

def handler = { Object[] args -> invoke = args[0]; session = args[1];
resultFor = session.resultFor(invoke)
switch (resultFor) {
case "connect":
packet = Packet.serverBw(0x2625A0)
packet.header.time = 2436539
session.send packet
session.send new Invoke("createStream", 3)
break
case "createStream":
streamId = invoke.lastArgAsInt
println 'using streamId: ' + streamId
session.send Packet.ping(3, 1, 0)
play = new Invoke(streamId, "play", 8, null, playParam)
play.time = 2335
session.send play
break
default:
println "not handling result for: " + resultFor
}
} as InvokeResultHandler

mysession.invokeResultHandler = handler

RtmpClient.connect mysession

Stream Recorder
06-17-2009, 03:28 AM
Script for downloading from oxy.videolectures.net with flazr
this is the simplest example, if you know the host and the values for the "app" and "play" params you can use this
import com.flazr.*

def host = 'oxy.videolectures.net'
def app = 'video'
def playParam = '2008/active/iswc08_karlsruhe/swcbtc/iswc08_swcbtc_01'
def saveAs = 'test.flv'

def session = new RtmpSession(host, 1935, app, playParam, saveAs)

RtmpClient.connect session

matt7277
06-23-2009, 02:15 PM
Were the def url and other variables taken from within a Wireshark (http://all-streaming-media.com/find-stream-URL/Wireshark-free-network-protocol-analyzer.htm) capture as I have seen the basic scripts do? Would you be able to give any advice on making this reusable? Could an html page hypothetically be created to pass the url through and have the script auto generated?

Thanks in advance!
Matt

Script for downloading from Yahoo Video with flazr
This is an example of how you can easily write a script to request an HTML page (or XML data in this case), parse the contents and extract the values needed to invoke the main RTMP client / download routine

import com.flazr.*

def videoId = "201620741"

def url = "http://video.music.yahoo.com/ver/268.0/process/getPlaylistFOP.php?node_id=v" \
+ videoId + "&tech=flash&bitrate=5000&eventid=1301797";

def xml = Utils.getOverHttp(url)

println xml

def data = new XmlSlurper().parseText(xml)
def stream = data.'SEQUENCE-ITEM'[1].STREAM

def tcUrl = stream.@APP.text()
def host = stream.@SERVER.text()
def queryString = stream.@QUERYSTRING.text()
def path = stream.@PATH.text().substring(1)

def app = tcUrl.substring(tcUrl.lastIndexOf('/') + 1)
def playParam = path.substring(0, path.lastIndexOf('.')) + '?' + queryString

println 'queryString: ' + queryString + '\n'
println 'path: ' + path + '\n'
println 'playParam: ' + playParam + '\n'
println 'app: ' + app + '\n'

def session = new RtmpSession(host, 1935, app, playParam, 'test.flv')

RtmpClient.connect session

Stream Recorder
06-23-2009, 09:42 PM
Were the def url and other variables taken from within a Wireshark capture as I have seen the basic scripts do? Would you be able to give any advice on making this reusable? Could an html page hypothetically be created to pass the url through and have the script auto generated?
These scripts come with Flazr. I don't think this can be automated, because web-sites use differenet XML files or don't use them at all.

These groovy scripts are reusable, but they hardly can be created without some programming skills.

IMHO the approach should be different. It should be similar to Replay Media Catcher (http://all-streaming-media.com/record-video-stream/Replay-Media-Catcher-HTTP-RTMP-FLV-MP3-ripper-recorder.htm). The RTMP URL should be sniffed first and then the RTMP downloader should start downloading the RTMP stream automatically.

matt7277
06-24-2009, 06:58 AM
Thanks for your response, I agree that the Replay Media Catcher (http://all-streaming-media.com/record-video-stream/Replay-Media-Catcher-HTTP-RTMP-FLV-MP3-ripper-recorder.htm) is great at sniffing the RTMP URL. One item that got me pondering was the included groovy script for yahoo. Was this video RTMP or RTMPE? I ask because I saw no traffic through Wireshark when filtering RTMPT and also didnt notice any RTMPE url within the pages source. Does the swf verification pass the connection through regular HTTP protocol?


These scripts come with Flazr. I don't think this can be automated, because web-sites use differenet XML files or don't use them at all.

These groovy scripts are reusable, but they hardly can be created without some programming skills.

IMHO the approach should be different. It should be similar to Replay Media Catcher (http://all-streaming-media.com/record-video-stream/Replay-Media-Catcher-HTTP-RTMP-FLV-MP3-ripper-recorder.htm). The RTMP URL should be sniffed first and then the RTMP downloader should start downloading the RTMP stream automatically.

matt7277
06-24-2009, 07:18 PM
I've downloaded the trunk of the latest version with RTMPE support but I'm getting hung up on operating as I did with the .5 release (i.e can you still call the batch file and use the same groovy scripts?) Ive attempted passing along a RTMPE url and save location but failed to actually download. I know there are different ways to call the command:



(String host, int port, String app, String playName, String saveAsFileName)

(String host, int port, String app, String playName, String saveAsFileName, boolean encrypted)

(String url, String saveAsFileName)



how are these used?

Stream Recorder
06-24-2009, 10:24 PM
One item that got me pondering was the included groovy script for yahoo. Was this video RTMP or RTMPE? I ask because I saw no traffic through Wireshark when filtering RTMPT and also didnt notice any RTMPE url within the pages source.

In RTMP Tunneled (RTMPT), RTMP data is encapsulated and exchanged via HTTP, and messages from the client (the media player, in this case) are addressed to port 80 (the default for HTTP) on the server.

Yahoo ! Music uses RTMP protocol, so you should filter for RTMP, not for RTMPT or RTMPE.

Does the swf verification pass the connection through regular HTTP protocol?
Most probably yes, but Yahoo ! Music doesn't use SWF verification.