Version 0.72.2cmk001 wrote:Thanks for such a nice programme, youtube is working now. Will appreciate if we can connect to Dailymotion and Metacafe Videos.
Settings - Transcoder - Profiles - Add
Name: Podcasts (Metacafe,DailyMotion)
Execute mode: Transcoding
Language: PascalScript
Transcoding parameters:
Code: Select all
function HTTPDecode(const AStr: string): string;
var
C, R: Char;
i: Integer;
begin
Result := ''; i := 1;
while i <= Length(aStr) do begin
C := aStr[i];
R := #0;
if C = '+' then
R := ' '
else if (C = '%') and (i < Length(aStr)) then begin
Inc(i);
C := aStr[i];
if C = '%' then
R := '%'
else begin
R := Chr(StrToIntDef('$' + Copy(aStr, i, 2), 0));
Inc(i)
end
end else
R := C;
if R <> #0 then
Result := Result + R;
Inc(i)
end
end;
function SearchLink(const aText, aRegEx: string; var aMatch: string): Boolean;
begin
with TRegExpr.Create(aRegEx) do try
Result := Search(aText);
if Result then
aMatch := HttpDecode(Match)
finally
Free
end
end;
function SearchSize(const aText, aRegEx: string; var aWidth, aHeight: Integer): Boolean;
begin
with TRegExpr.Create(aRegEx) do try
Result := Search(aText);
if Result then begin
aWidth := StrToIntDef(Match, 0);
aHeight := StrToIntDef(Match(2), 0);
end
finally
Free
end
end;
function SelectDailyMotionLink(const aLink: string): string;
var
sLink, sBestLink, sCurLink: string;
i, iWidth, iHeight, iBestFrameSize: Integer;
begin
sLink := aLink; sBestLink := '';
iBestFrameSize := 0;
while sLink <> '' do begin
i := Pos('||', sLink);
if i > 0 then begin
sCurLink := Copy(sLink, 1, i - 1);
sLink := Copy(sLink, i + 2, Length(sLink))
end else begin
sCurLink := sLink;
sLink := ''
end;
if SearchSize(sCurLink, 'FLV-(\d*)x(\d*)', iWidth, iHeight) or
SearchSize(sCurLink, 'H264-(\d*)x(\d*)', iWidth, iHeight) then begin
if iBestFrameSize < iWidth * iHeight then begin
iBestFrameSize := iWidth * iHeight;
sBestLink := sCurLink;
end
end;
if sBestLink = '' then
sBestLink := sCurLink
end;
Result := sBestLink
end;
var
sLink, sPage, sTranscoderParams: string;
begin
sPage := WmsDownloadURL(InputFileName); sLink := '';
if Pos('http://www.metacafe.com', LowerCase(InputFileName)) > 0 then begin
SearchLink(sPage, 'mediaURL=(.*?)&postRollContentURL', sLink)
end else if Pos('http://www.dailymotion.com', LowerCase(InputFileName)) > 0 then begin
if SearchLink(sPage, 'addVariable\("video", "(.*?)"', sLink) then
sLink := SelectDailyMotionLink(sLink)
end;
if sLink <> '' then begin
sTranscoderParams := WmsTranscodingProfileParams('Movies (primary)') + ' "<OUTPUT FILE>"';
TranscodingResult := WmsTranscodingExecute('WMSMPEG', sTranscoderParams, True,
WmsDownloadURLToPipe(sLink), OutputFileName)
end else
TranscodingResult := False
end.