Example #1
0
            $cmd = $cfg['decode_stdout'][$extension];
        } else {
            $cmd = $cfg['decode_stdout'][$extension] . ' 2>&1';
        }
        $cmd = str_replace('%source', escapeCmdArg($source), $cmd);
        $cmd = $cmd . ' > ' . escapeCmdArg($destination);
        $cmd_output = array();
        $cmd_return = 0;
        @exec($cmd, $cmd_output, $cmd_return);
        if ($cmd_return != 0) {
            message(__FILE__, __LINE__, 'error', '[b]Exec error[/b][br][b]Command:[/b] ' . $cmd . '[br][b]System output:[/b] ' . implode('[br]', $cmd_output) . '[br][b]System return code:[/b] ' . $cmd_return);
        }
        if (is_file($destination) == false) {
            message(__FILE__, __LINE__, 'error', '[b]Destination file not created[/b][br]File: ' . $destination . '[br]Command: ' . $cmd);
        }
        cacheUpdateFile($track['track_id'], -2, $destination);
        cacheCleanup();
    }
    echo '<script type="text/javascript">document.getElementById(\'status' . $i . '\').innerHTML=\'<img src="' . $cfg['img'] . 'small_check.png" alt="" class="small">\';</script>' . "\n";
    @ob_flush();
    flush();
}
echo '<script type="text/javascript">document.getElementById(\'record\').innerHTML=\'<img src="' . $cfg['img'] . 'small_animated_record.gif" alt="" class="small">\';</script>' . "\n";
@ob_flush();
flush();
// Record to disc
$cache_dir = cacheGetDir($track_id, $profile);
$pathinfo = pathinfo($track['relative_file']);
$destination = $pathinfo['filename'];
$destination = $cache_dir . $destination . '.' . $cfg['encode_extension'][$profile];
// Transcode
Example #2
0
function downloadAlbum($album_id)
{
    global $cfg, $db;
    $sid = get('sid');
    $download_id = (int) get('download_id');
    if ($sid) {
        // Download shared file
        header('Expires: Mon, 9 Oct 2000 18:00:00 GMT');
        header('Cache-Control: no-store, no-cache, must-revalidate');
        mysql_query('UPDATE share_download SET
			ip			= "' . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . '"
			WHERE sid	= BINARY "' . mysql_real_escape_string($sid) . '"
			AND ip		= ""');
        $query = mysql_query('SELECT album_id, download_id
			FROM share_download
			WHERE sid = BINARY "' . mysql_real_escape_string($sid) . '"
			AND ip = "' . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . '"
			AND expire_time > ' . (int) time());
        $share_download = mysql_fetch_assoc($query);
        if ($share_download == false || $cfg['album_share_download'] == false) {
            message(__FILE__, __LINE__, 'error', '[b]Download failed[/b][br]Authentication failed or share download is disabled');
        }
        $album_id = $share_download['album_id'];
        $download_id = $share_download['download_id'];
        if (cacheGetFile($album_id, $download_id)) {
            authenticate('access_always', true);
        } else {
            authenticate('access_always');
        }
        $download_url = NJB_HOME_URL . 'download.php?action=downloadAlbum&amp;sid=' . $sid;
    } else {
        // Common download
        if (cacheGetFile($album_id, $download_id)) {
            authenticate('access_download', true);
        } else {
            authenticate('access_download');
        }
        if ($cfg['album_download'] == false) {
            message(__FILE__, __LINE__, 'error', '[b]Error[/b][br]Download album disabled');
        }
        $download_url = NJB_HOME_URL . 'download.php?action=downloadAlbum&amp;album_id=' . rawurlencode($album_id) . '&amp;download_id=' . $download_id;
    }
    if ($download_id != -1 && isset($cfg['encode_extension'][$download_id]) == false) {
        message(__FILE__, __LINE__, 'error', '[b]Unsupported input value for[/b][br]download_id');
    }
    $query = mysql_query('SELECT track_id
		FROM track
		WHERE album_id	= "' . mysql_real_escape_string($album_id) . '"');
    if (mysql_num_rows($query) == 1) {
        // By one file downloadTrack()
        $track = mysql_fetch_assoc($query);
        downloadTrack($track['track_id']);
        if ($sid != '') {
            mysql_query('DELETE FROM share_download WHERE sid = BINARY "' . mysql_real_escape_string($sid) . '"');
        } else {
            updateCounter($album_id, NJB_COUNTER_DOWNLOAD);
        }
        exit;
    }
    if ($file = cacheGetFile($album_id, $download_id)) {
        // Download from cache
        $query = mysql_query('SELECT artist_alphabetic, album, year FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
        $album = mysql_fetch_assoc($query);
        $filename = $album['artist_alphabetic'] . ' - ';
        $filename .= $album['year'] ? $album['year'] . ' - ' : '';
        $filename .= $album['album'] . '.' . $cfg['download_album_extension'];
        $filename = downloadFilename($filename);
        streamFile($file, $cfg['download_album_mime_type'], 'attachment', $filename);
        if ($sid != '') {
            mysql_query('DELETE FROM share_download WHERE sid = BINARY "' . mysql_real_escape_string($sid) . '"');
        } else {
            updateCounter($album_id, NJB_COUNTER_DOWNLOAD);
        }
        exit;
    }
    ini_set('max_execution_time', 0);
    $query = mysql_query('SELECT artist_alphabetic, album FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
    $album = mysql_fetch_assoc($query);
    if ($album == false) {
        message(__FILE__, __LINE__, 'error', '[b]Error[/b][br]album_id not found in database');
    }
    // formattedNavigator
    $nav = array();
    $nav['name'][] = 'Media';
    $nav['url'][] = 'index.php';
    $nav['name'][] = $album['artist_alphabetic'];
    $nav['url'][] = 'index.php?action=view2&amp;artist=' . rawurlencode($album['artist_alphabetic']);
    $nav['name'][] = $album['album'];
    $nav['url'][] = 'index.php?action=view3&amp;album_id=' . $album_id;
    $nav['name'][] = 'Download album';
    require_once 'include/header.inc.php';
    ?>
<table cellspacing="0" cellpadding="0" class="border">
<tr class="header">
	<td class="space"></td>
	<td><?php 
    echo $download_id == -1 ? 'Source' : 'Transcode to ' . html($cfg['encode_name'][$download_id]);
    ?>
</td>
	<td class="textspace"></td>
	<td></td>
	<td class="textspace"></td>
	<td></td>
	<td class="space"></td>
</tr>
<tr class="line"><td colspan="7"></td></tr>
<?php 
    $i = 0;
    $query = mysql_query('SELECT title, artist FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
    while ($track = mysql_fetch_assoc($query)) {
        ?>
<tr class="<?php 
        echo $i++ & 1 ? 'even' : 'odd';
        ?>
">
	<td></td>
	<td><?php 
        echo html($track['artist']);
        ?>
</td>
	<td></td>
	<td><?php 
        echo html($track['title']);
        ?>
</td>
	<td></td>
	<td><span id="status<?php 
        echo $i;
        ?>
"></span></td>
	<td></td>
</tr>
<?php 
    }
    ?>
<tr class="line"><td colspan="7"></td></tr>
<tr class="header">
	<td></td>
	<td colspan="5">Download</td>
	<td></td>
</tr>
<tr class="line"><td colspan="7"></td></tr>
<tr class="odd">
	<td></td>
	<td colspan="3"><span id="text">Create <?php 
    echo $cfg['download_album_extension'];
    ?>
 file</span></td>
	<td></td>
	<td align="center"><span id="icon"></span></td>
	<td></td>
</tr>
</table>
<?php 
    $cfg['footer'] = 'dynamic';
    require 'include/footer.inc.php';
    $cache_dir = cacheGetDir($album_id, $download_id);
    $i = 0;
    $hash_data = '';
    $list = $cache_dir . $album_id . '.txt';
    $list_content = '';
    $query = mysql_query('SELECT track_id, relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
    while ($track = mysql_fetch_assoc($query)) {
        $i++;
        echo '<script type="text/javascript">document.getElementById(\'status' . $i . '\').innerHTML=\'<img src="' . $cfg['img'] . 'small_animated_progress.gif" alt="" class="small">\';</script>' . "\n";
        @ob_flush();
        flush();
        $source = transcode($track['track_id'], $download_id);
        $pathinfo = pathinfo($source);
        $source_name = $pathinfo['filename'];
        $pathinfo = pathinfo($track['relative_file']);
        $destination_name = $pathinfo['filename'];
        $destination_name = downloadFilename($destination_name, true, true);
        if ($source_name == $destination_name) {
            $destination = $source;
        } else {
            $destination = $cache_dir . $destination_name . '.' . $cfg['encode_extension'][$download_id];
            @copy($source, $destination) or message(__FILE__, __LINE__, 'error', '[b]Failed to copy file[/b][br]From: ' . $source . '[br]To: ' . $destination);
        }
        $pathinfo = pathinfo($destination);
        $hash_data .= $pathinfo['filename'];
        $destination = iconv(NJB_DEFAULT_CHARSET, 'UTF-8', $destination);
        $list_content .= $destination . "\n";
        echo '<script type="text/javascript">document.getElementById(\'status' . $i . '\').innerHTML=\'<img src="' . $cfg['img'] . 'small_check.png" alt="" class="small">\';</script>' . "\n";
        @ob_flush();
        flush();
    }
    if (file_put_contents($list, $list_content) === false) {
        message(__FILE__, __LINE__, 'error', '[b]Failed to write file:[/b][br]' . $list);
    }
    echo '<script type="text/javascript">document.getElementById(\'icon\').innerHTML=\'<img src="' . $cfg['img'] . 'small_animated_progress.gif" alt="" class="small">\';</script>' . "\n";
    @ob_flush();
    flush();
    $hash = md5($hash_data);
    $destination = $cache_dir . $album_id . '_' . $hash . '.' . $cfg['download_album_extension'];
    // Download album
    if (NJB_WINDOWS) {
        $cmd = $cfg['download_album_cmd'];
    } else {
        $cmd = $cfg['download_album_cmd'] . ' 2>&1';
    }
    $cmd = str_replace('%list', escapeCmdArg($list), $cmd);
    $cmd = str_replace('%destination', escapeCmdArg($destination), $cmd);
    $cmd_output = array();
    $cmd_return = 0;
    @exec($cmd, $cmd_output, $cmd_return);
    if ($cmd_return != 0) {
        message(__FILE__, __LINE__, 'error', '[b]Exec error[/b][br][b]Command:[/b] ' . $cmd . '[br][b]System output:[/b] ' . implode('[br]', $cmd_output) . '[br][b]System return code:[/b] ' . $cmd_return);
    }
    if (is_file($destination) == false) {
        message(__FILE__, __LINE__, 'error', '[b]Destination file not created[/b][br]File: ' . $destination . '[br]Command: ' . $cmd);
    }
    cacheUpdateFile($album_id, $download_id, $destination, '', $hash);
    // Cleanup
    @unlink($list);
    recursiveValidate($cache_dir);
    cacheCleanup();
    $download_url .= '&amp;timestamp=' . dechex(time());
    echo '<script type="text/javascript">document.getElementById(\'text\').innerHTML=\'<a href="' . $download_url . '"><img src="' . $cfg['img'] . 'small_download.png" alt="" class="small space">Download ' . $cfg['download_album_extension'] . ' file (' . formattedSize(filesize($destination)) . ')<\\/a>\';</script>' . "\n";
    echo '<script type="text/javascript">document.getElementById(\'icon\').innerHTML=\'\';</script>' . "\n";
    echo '<iframe src="' . $download_url . '" width="0" height="0" scrolling="no" frameborder="0"></iframe>' . "\n";
    $cfg['footer'] = 'close';
    require 'include/footer.inc.php';
}
Example #3
0
function cacheUpdateTag($track_id, $profile, $file)
{
    global $cfg, $db;
    $query = mysql_query('SELECT image, bitmap.flag
		FROM bitmap, track
		WHERE bitmap.album_id = track.album_id
		AND track_id = "' . mysql_real_escape_string($track_id) . '"');
    $bitmap = mysql_fetch_assoc($query);
    $query = mysql_query('SELECT
		LOWER(SUBSTRING_INDEX(relative_file, ".", -1)) AS extension,
		track.artist, title, album, year, disc, discs, number, audio_lossless
		FROM track, album
		WHERE track_id = "' . mysql_real_escape_string($track_id) . '" 
		AND track.album_id = album.album_id');
    $track = mysql_fetch_assoc($query);
    $query = mysql_query('SELECT tag_hash
		FROM cache
		WHERE id		= "' . mysql_real_escape_string($track_id) . '"
		AND profile		= ' . (int) $profile);
    $cache = mysql_fetch_assoc($query);
    // populate data array
    $tagData['title'][0] = iconv(NJB_DEFAULT_CHARSET, $cfg['tag_encoding'][$profile], $track['title']);
    $tagData['artist'][0] = iconv(NJB_DEFAULT_CHARSET, $cfg['tag_encoding'][$profile], $track['artist']);
    $tagData['album'][0] = iconv(NJB_DEFAULT_CHARSET, $cfg['tag_encoding'][$profile], $track['album']);
    $tagData['year'][0] = $track['year'];
    $tagData['comment'][0] = $track['audio_lossless'] ? 'Lossless audio source' : 'Transcoded from ' . $track['extension'] . ' source';
    if ($cfg['tag_format'][$profile] == 'id3v2.3' && $track['number']) {
        $tagData['tracknumber'][0] = $track['number'];
    }
    if ($cfg['tag_format'][$profile] == 'id3v2.3' && $track['discs'] > 1) {
        $tagData['part_of_a_set'][0] = $track['disc'] . '/' . $track['discs'];
    }
    if ($cfg['tag_format'][$profile] == 'id3v2.3' && $bitmap['flag'] == 3) {
        $tagData['attached_picture'][0]['data'] = $bitmap['image'];
        $tagData['attached_picture'][0]['picturetypeid'] = 0x3;
        // 0x03 => 'Cover (front)'
        $tagData['attached_picture'][0]['description'] = '';
        $tagData['attached_picture'][0]['mime'] = 'image/jpeg';
    }
    unset($bitmap, $track);
    $hash = $cfg['tag_format'][$profile];
    $hash .= $cfg['tag_encoding'][$profile];
    $hash .= $cfg['tag_padding'][$profile];
    $hash .= print_r($tagData, true);
    $hash = md5($hash);
    if ($hash != $cache['tag_hash']) {
        require_once NJB_HOME_DIR . 'getid3/getid3/getid3.php';
        require_once NJB_HOME_DIR . 'getid3/getid3/write.php';
        // Initialize getID3 engine
        $getID3 = new getID3();
        $getID3->setOption(array('encoding' => $cfg['tag_encoding'][$profile]));
        // Initialize getID3 tag-writing module
        $tagwriter = new getid3_writetags();
        $tagwriter->filename = $file;
        $tagwriter->tagformats = array($cfg['tag_format'][$profile]);
        // array('id3v2.3');
        // set various options (optional)
        $tagwriter->tag_encoding = $cfg['tag_encoding'][$profile];
        $tagwriter->overwrite_tags = true;
        $tagwriter->remove_other_tags = true;
        $tagwriter->id3v2_paddedlength = $cfg['tag_padding'][$profile];
        $tagwriter->tag_data = $tagData;
        if ($tagwriter->WriteTags() == false) {
            message(__FILE__, __LINE__, 'error', '[b]Failed to write tags[/b][br]Error: ' . implode('[br]', $tagwriter->errors) . '[br]File: ' . $file);
        }
        cacheUpdateFile($track_id, $profile, $file, $hash);
    }
}