diff --git a/sections/better/index.php b/sections/better/index.php
index 3133fc51..04f23f94 100644
--- a/sections/better/index.php
+++ b/sections/better/index.php
@@ -7,6 +7,9 @@
case 'transcode':
include(SERVER_ROOT.'/sections/better/transcode.php');
break;
+ case 'transcode_beta':
+ include(SERVER_ROOT.'/sections/better/transcode_beta.php');
+ break;
case 'single':
include(SERVER_ROOT.'/sections/better/single.php');
break;
diff --git a/sections/better/transcode_beta.php b/sections/better/transcode_beta.php
new file mode 100644
index 00000000..942a0f92
--- /dev/null
+++ b/sections/better/transcode_beta.php
@@ -0,0 +1,322 @@
+
+/**
+ * New transcode module:
+ * $_GET['filter'] determines which torrents should be shown and can be empty/all (default), uploaded, snatched or seeding
+ * $_GET['target'] further filters which transcodes one would like to do and can be empty/any (default), v0, v2, 320 or all
+ * Here, 'any' means that at least one of the formats V0, V2 and 320 is missing and 'all' means that all of them are missing.
+ * 'v0' etc mean that this specific format is missing (but others might be present).
+ *
+ * Furthermore, there's $_GET['userid'] which allows to see the page as a different user would see it (specifically relevant for uploaded/snatched/seeding).
+ */
+
+if (!empty($_GET['userid']) && is_number($_GET['userid'])) {
+ if (check_perms('users_override_paranoia')) {
+ $UserID = $_GET['userid'];
+ } else {
+ error(403);
+ }
+} else {
+ $UserID = $LoggedUser['ID'];
+}
+
+if(empty($_GET['filter']) || !in_array($_GET['filter'], array('uploaded', 'seeding', 'snatched'))) {
+ $_GET['filter'] = 'all';
+}
+if(empty($_GET['target']) || !in_array($_GET['target'], array('v0', 'v2', '320', 'all'))) {
+ $_GET['target'] = 'any';
+}
+$Encodings = array('v0' => 'V0 (VBR)', 'v2' => 'V2 (VBR)', '320' => '320');
+
+function transcode_init_sphql() {
+ // Initializes a basic SphinxQL_Query object
+ $SphQL = new SphinxQL_Query();
+ $SphQL->select('groupid')
+ ->from('better_transcode')
+ ->where('logscore', 100)
+ ->where_match('FLAC', 'format')
+ ->order_by('RAND()')
+ ->limit(0, TORRENTS_PER_PAGE, TORRENTS_PER_PAGE);
+ if (in_array($_GET['target'], array('v0', 'v2', '320'))) {
+ // v0/v2/320 is missing
+ $SphQL->where_match('!'.$_GET['target'], 'encoding', false);
+ } elseif($_GET['target'] == 'all') {
+ // all transcodes are missing
+ $SphQL->where_match('!(v0 | v2 | 320)', 'encoding', false);
+ } else {
+ // any transcode is missing
+ $SphQL->where_match('!(v0 v2 320)', 'encoding', false);
+ }
+ if(!empty($_GET['search'])) {
+ $SphQL->where_match($_GET['search'], '(groupname,artistname,year,taglist)');
+ }
+ return $SphQL;
+}
+
+function transcode_parse_groups($Groups) {
+ $TorrentGroups = array();
+ foreach ($Groups as $GroupID => $Group) {
+ if (empty($Group['Torrents'])) {
+ continue;
+ }
+ foreach ($Group['Torrents'] as $TorrentID => $Torrent) {
+ $RemIdent = "$Torrent[Media] $Torrent[RemasterYear] $Torrent[RemasterTitle] $Torrent[RemasterRecordLabel] $Torrent[RemasterCatalogueNumber]";
+ if (!isset($TorrentGroups[$GroupID])) {
+ $TorrentGroups[$GroupID] = array(
+ 'Year' => $Group['Year'],
+ 'ExtendedArtists' => $Group['ExtendedArtists'],
+ 'Name' => $Group['Name'],
+ 'ReleaseType' => $Group['ReleaseType'],
+ 'TagList' => $Group['TagList'],
+ 'Editions' => array()
+ );
+ }
+ if (!isset($TorrentGroups[$GroupID]['Editions'][$RemIdent])) {
+ if($Torrent['Remastered'] && $Torrent['RemasterYear'] != 0) {
+ $EditionName = $Torrent['RemasterYear'];
+ $AddExtra = " - ";
+ if($Torrent['RemasterRecordLabel']) { $EditionName .= $AddExtra.display_str($Torrent['RemasterRecordLabel']); $AddExtra=' / '; }
+ if($Torrent['RemasterCatalogueNumber']) { $EditionName .= $AddExtra.display_str($Torrent['RemasterCatalogueNumber']); $AddExtra=' / '; }
+ if($Torrent['RemasterTitle']) { $EditionName .= $AddExtra.display_str($Torrent['RemasterTitle']); $AddExtra=' / '; }
+ $EditionName .= $AddExtra.display_str($Torrent['Media']);
+ } else {
+ $AddExtra = " / ";
+ if(!$Torrent['Remastered']) {
+ $EditionName = "Original Release";
+ if($Group['RecordLabel']) { $EditionName .= $AddExtra.$Group['RecordLabel']; $AddExtra=' / '; }
+ if($Group['CatalogueNumber']) { $EditionName .= $AddExtra.$Group['CatalogueNumber']; $AddExtra=' / '; }
+ } else {
+ $EditionName = "Unknown Release(s)";
+ }
+ $EditionName .= $AddExtra.display_str($Torrent['Media']);
+ }
+ $TorrentGroups[$GroupID]['Editions'][$RemIdent] = array(
+ 'FlacIDs' => array(),
+ 'MP3s' => array(),
+ 'Media' => $Torrent['Media'],
+ 'EditionName' => $EditionName,
+ 'FLACIsSnatched' => false
+ );
+ }
+
+ if ($Torrent['Format'] == 'MP3') {
+ $TorrentGroups[$GroupID]['Editions'][$RemIdent]['MP3s'][$Torrent['Encoding']] = true;
+ } elseif ($Torrent['Format'] == 'FLAC' && ($Torrent['LogScore'] == 100 || $Torrent['Media'] != 'CD')
+ && !isset($TorrentGroups[$GroupID]['Editions'][$RemIdent]['FlacIDs'][$TorrentID])) {
+ $TorrentGroups[$GroupID]['Editions'][$RemIdent]['FlacIDs'][$TorrentID] = true;
+ $TorrentGroups[$GroupID]['Editions'][$RemIdent]['FLACIsSnatched'] = $TorrentGroups[$GroupID]['Editions'][$RemIdent]['FLACIsSnatched'] || $Torrent['IsSnatched'];
+ }
+ }
+ }
+ return $TorrentGroups;
+}
+
+$Groups = array();
+$ResultCount = 0;
+if(in_array($_GET['filter'], array('all', 'uploaded'))) {
+ $SphQL = transcode_init_sphql();
+ if($_GET['filter'] == 'uploaded') {
+ $SphQL->where('uploader', $UserID);
+ }
+
+ $SphQLResult = $SphQL->query();
+ $ResultCount = $SphQLResult->get_meta('total');
+ if ($ResultCount != 0) {
+ $Results = $SphQLResult->collect('groupid');
+ $Groups = Torrents::get_groups(array_values($Results));
+ $Groups = transcode_parse_groups($Groups['matches']);
+ }
+ unset($SphQL, $SphQLResult, $Results);
+} elseif(in_array($_GET['filter'], array('snatched', 'seeding'))) {
+ // Read all snatched/seeding torrents
+ $DB->query("SELECT t.GroupID, x.fid
+ FROM ".($_GET['filter'] == 'seeding' ? 'xbt_files_users' : 'xbt_snatched')." AS x
+ JOIN torrents AS t ON t.ID=x.fid
+ JOIN torrents_group AS tg ON tg.ID = t.GroupID
+ WHERE t.Format='FLAC'
+ AND (t.LogScore = '100' OR t.Media != 'CD')
+ AND tg.CategoryID = 1
+ AND x.uid='$UserID'
+ ".($_GET['filter'] == 'seeding' ? "AND x.active=1 AND x.Remaining=0" : ""));
+ $Snatched = $DB->to_array();
+ shuffle($Snatched); // randomize results
+ while($ResultCount < TORRENTS_PER_PAGE && count($Snatched) > 0) {
+ // we throw TORRENTS_PER_PAGE results into Sphinx until we have at least TORRENTS_PER_PAGE results (or no snatches left)
+ $SnatchedTmp = array_slice($Snatched, 0, TORRENTS_PER_PAGE);
+ $Snatched = array_slice($Snatched, TORRENTS_PER_PAGE);
+
+ $SphQL = transcode_init_sphql();
+ $SphQL->where('groupid', array_map(function ($row) { return $row['GroupID']; }, $SnatchedTmp));
+
+ $SphQLResult = $SphQL->query();
+ $ResultsTmp = $SphQLResult->collect('groupid');
+ $GroupsTmp = Torrents::get_groups(array_values($ResultsTmp));
+ $GroupsTmp = transcode_parse_groups($GroupsTmp['matches']);
+ // Since we're asking SphinxQL about groups and remidents, the result can/will contain different editions that are transcodable but weren't snatched, so let's filter them out
+ foreach($GroupsTmp as $GroupID => $Group) {
+ foreach($Group['Editions'] as $RemIdent => $Edition) {
+ $EditionSnatched = false;
+ foreach($SnatchedTmp as $SnatchedTmpE) {
+ if(isset($Edition['FlacIDs'][$SnatchedTmpE['fid']])) {
+ $EditionSnatched = true;
+ break;
+ }
+ }
+ if(!$EditionSnatched || count($Edition['MP3s']) == 3) {
+ unset($GroupsTmp[$GroupID]['Editions'][$RemIdent]);
+ }
+ }
+ $ResultCount += count($GroupsTmp[$GroupID]['Editions']);
+ if(count($GroupsTmp[$GroupID]['Editions']) == 0) {
+ unset($GroupsTmp[$GroupID]);
+ }
+ }
+ $Groups = $GroupsTmp + $Groups;
+ unset($SnatchedTmp, $SphQL, $SphQLResult, $ResultsTmp, $GroupsTmp);
+ }
+}
+$Debug->log_var($Groups, 'Groups');
+
+$Counter = array(
+ 'total' => 0, //how many FLAC torrents can be transcoded?
+ 'miss_total' => 0, //how many transcodes are missing?
+ 'miss_V0 (VBR)' => 0, //how many V0 transcodes are missing?
+ 'miss_V2 (VBR)' => 0, //how many V2 transcodes are missing?
+ 'miss_320' => 0, //how many 320 transcodes are missing?
+);
+foreach($Groups as $GroupID => $Group) {
+ foreach($Group['Editions'] as $RemIdent => $Edition) {
+ if (count($Edition['FlacIDs']) == 0 //no FLAC in this group
+ || (!empty($Edition['MP3s']) && $_GET['target'] == 'all') //at least one transcode present when we only wanted groups containing no transcodes at all
+ || isset($Edition['MP3s'][$Encodings[$_GET['target']]]) //the transcode we asked for is already there
+ || count($Edition['MP3s']) == 3) //all 3 transcodes are there already (this can happen due to the caching of Sphinx's better_transcode table)
+ {
+ $Debug->log_var($Edition, 'Skipping '.$RemIdent);
+ unset($Groups[$GroupID]['Editions'][$RemIdent]);
+ continue;
+ }
+ $edition_miss = 0; //number of transcodes missing in this edition
+ foreach($Encodings as $Encoding) {
+ if(!isset($Edition['MP3s'][$Encoding])) {
+ ++$edition_miss;
+ ++$Counter['miss_'.$Encoding];
+ }
+ }
+ $Counter['miss_total'] += $edition_miss;
+ $Counter['total'] += (bool)$edition_miss;
+ }
+}
+$Debug->log_var($Counter, 'counter');
+
+View::show_header('Transcode Search');
+?>
+
+
+ This page aims at listing =TORRENTS_PER_PAGE?> random transcodable perfect FLACs matching the options you selected above, but there can be more or less matches on this page. The following numbers tell you something about the torrents currently listed below and can change if you reload.
+
+ Number of perfect FLACs you can transcode: =number_format($Counter['total'])?>
+ Number of missing transcodes: =number_format($Counter['miss_total'])?>
+ Number of missing V2 / V0 / 320 transcodes: =number_format($Counter['miss_V2 (VBR)'])?> / =number_format($Counter['miss_V0 (VBR)'])?> / =number_format($Counter['miss_320'])?>
+
Torrent | +V2 | +V0 | +320 | +
No results found! | |||
+
+ DL
+
+ =$DisplayName?>
+ =$Edition['EditionName']?>
+
+ |
+ YES' : 'class="important_text">NO'?> | +YES' : 'class="important_text">NO'?> | +YES' : 'class="important_text">NO'?> | +