Skip to content

Commit

Permalink
use name hash for fragment filename in case of very long names
Browse files Browse the repository at this point in the history
fixed #46
  • Loading branch information
K-S-V committed Apr 14, 2015
1 parent 3cc8ca9 commit 90f0167
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions AdobeHDS.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,12 @@ function DownloadFragments($cc, $manifest, $opt = array())
if ($lastSlash !== false)
$this->baseFilename = substr($this->baseFilename, $lastSlash + 1);
if (strpos($manifest, '?'))
$this->baseFilename = md5(substr($manifest, 0, strpos($manifest, '?'))) . '_' . $this->baseFilename;
$manifestHash = md5(substr($manifest, 0, strpos($manifest, '?')));
else
$this->baseFilename = md5($manifest) . '_' . $this->baseFilename;
$this->baseFilename .= "Seg" . $segNum . "-Frag";
$manifestHash = md5($manifest);
if (strlen($this->baseFilename) > 32)
$this->baseFilename = md5($this->baseFilename);
$this->baseFilename = $manifestHash . "_" . $this->baseFilename . "_Seg" . $segNum . "-Frag";

if ($fragNum >= $this->fragCount)
LogError("No fragment available for downloading");
Expand Down Expand Up @@ -1039,7 +1041,10 @@ function DecodeFragment($frag, $fragNum, $opt = array())
{
$debug = $this->debug;
$flv = false;
$test = false;
extract($opt, EXTR_IF_EXISTS);
if ($test)
$debug = false;

$flvData = "";
$fragPos = 0;
Expand Down Expand Up @@ -1316,7 +1321,7 @@ function WriteFragment($download, &$opt)
LogDebug("Writing fragment " . $frag['id'] . " to flv file");
if (!isset($opt['file']))
{
$opt['debug'] = false;
$opt['test'] = true;
if ($this->play)
$outFile = STDOUT;
else if ($this->outFile)
Expand All @@ -1339,7 +1344,7 @@ function WriteFragment($download, &$opt)
if ($this->metadata)
WriteMetadata($this, $opt['file']);

$opt['debug'] = $this->debug;
$opt['test'] = false;
$this->InitDecoder();
}
$flvData = $this->DecodeFragment($frag['response'], $frag['id'], $opt);
Expand Down Expand Up @@ -1390,6 +1395,12 @@ function ReadByte($str, $pos)
return $int[1];
}

function ReadInt16($str, $pos)
{
$int32 = unpack('N', "\x00\x00" . substr($str, $pos, 2));
return $int32[1];
}

function ReadInt24($str, $pos)
{
$int32 = unpack('N', "\x00" . substr($str, $pos, 3));
Expand All @@ -1410,6 +1421,12 @@ function ReadInt64($str, $pos)
return $int64;
}

function ReadDouble($str, $pos)
{
$double = unpack('d', strrev(substr($str, $pos, 8)));
return $double[1];
}

function ReadString($str, &$pos)
{
$len = 0;
Expand Down Expand Up @@ -1976,7 +1993,7 @@ function value_in_array_field($needle, $needle_field, $value_field, $haystack, $
$frag = file_get_contents($file . $fileExt);
if (!isset($opt['flv']))
{
$opt['debug'] = false;
$opt['test'] = true;
$f4f->InitDecoder();
$f4f->DecodeFragment($frag, $i, $opt);
if ($filesize)
Expand All @@ -1986,7 +2003,7 @@ function value_in_array_field($needle, $needle_field, $value_field, $haystack, $
if ($metadata)
WriteMetadata($f4f, $opt['flv']);

$opt['debug'] = $debug;
$opt['test'] = false;
$f4f->InitDecoder();
}
$f4f->DecodeFragment($frag, $i, $opt);
Expand Down
2 changes: 1 addition & 1 deletion BeatConvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function WriteFlvFile($outFile, $audio = true, $video = true)
$filePos = $filePos + 3 + $lookupSize;
LogDebug("Version: $version, Quality: $quality, LookupSize: $lookupSize");

// Retreive encryption key and iv
// Retrieve encryption key and iv
$key = "";
$iv = "";
for ($i = 0; $i < 32; $i += 2)
Expand Down

1 comment on commit 90f0167

@zwaart
Copy link

@zwaart zwaart commented on 90f0167 Apr 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me. How I can start automatically HDS Link Detector and AdobeHDS.php by time shedule? I.e. when livestream will start, it will be recoreded without clicking and other manual manipulation? Thanks for your work!

Please sign in to comment.