Author Topic: Batch (mass) assign cover art and attributes  (Read 1379 times)

lon22

  • Veteran
  • ***
  • Posts: 85
    • View Profile
Batch (mass) assign cover art and attributes
« on: January 20, 2008, 07:37:02 pm »
I created a script that will allow you to batch assign cover art and attributes to files. In order to use the script follow these steps:

1. Copy the script to the /var/www directory on the core machine.
2. Go to pluto-admin and edit the media attributes for one file out of the group of files that you want to assign cover art for. Remember which file you assigned cover art to.
3. Type in 192.168.80.1/BatchAssign in your web browser.
4. Enter your user name and password that has access to the database.
5. Search for the group of files by either typing in a file name or the name of the folder that contains the files.
6. Click the radio button next to the file that you assigned cover art for in step 2.
7. Click the checkbox next to any files that you want to have the same cover art and attributes as the file in step 2.
8. Click the "Add Attributes to selected file" button.
9. Now all of those files should have cover art and attributes associated with them.

This is a rough copy of the script, but it works. I will improve on it and make it more efficient. Maybe once it is optimized it can be added to the pluto-admin website. The script is attached.

lon22
« Last Edit: January 20, 2008, 07:38:47 pm by lon22 »

posde

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 2993
  • Wastes Life On LinuxMCE Since 2007
    • View Profile
    • My Home
Re: Batch (mass) assign cover art and attributes
« Reply #1 on: January 20, 2008, 08:34:29 pm »
Thanks for the code. I will look into it in more detail. I want to have a more automatic way of assigning Cover Art, though at the moment I don't know if it will be possible.

rgds
Oliver

jgaffney

  • Douchebag
  • Veteran
  • *
  • Posts: 138
    • View Profile
Re: Batch (mass) assign cover art and attributes
« Reply #2 on: February 02, 2008, 04:46:25 pm »
Could you re-post your script please?  The link appears to be broken.  I'm interested in giving this a shot.

lon22

  • Veteran
  • ***
  • Posts: 85
    • View Profile
Re: Batch (mass) assign cover art and attributes
« Reply #3 on: February 02, 2008, 07:15:32 pm »
Could you re-post your script please?  The link appears to be broken.  I'm interested in giving this a shot.

I get an error when I try to upload the file - "Cannot access attachments upload path!".

Just copy the code below into a text editor and save the file as BatchAssign.php.

Code: [Select]
<?php

$i 
0;
$con $_POST['con'];
$userID $_POST['userID'];
$passWord $_POST['passWord'];
$querStr $_POST['querStr'];
$querStr2 $_POST['querStr2'];
$isLoggedOn $_POST['isLoggedOn'];
$mediaSubTypeEnum = array (=> "TV Shows",=> "Movies",=> "Home Videos"=> "Sports Events"=> "Music Videos"=> "Alternative"=> "Popular Music"=> "Classical Music");
$fileFormatEnum = array (=> "Low Res",=> "DVD",=> "Standard Def"=> "HD 720"=> "HD 1080"=> "Low Quality"=> "MP3"=> "CD Quality"=> "High-def audio");


Echo 
"<html>";
Echo 
"<title>LMCE Batch Assign</title>
  <LINK REL=relationship HREF='URL' REL='Banner'> "
;


Echo  
"
<body bgcolor='Green'>
<h1> LinuxMCE: Batch Assign Cover Art & Attributes</h1>
<hr />
<br>
<form action="
.$_SERVER['PHP_SELF']." method='post'>";
if (isset(
$_POST['logon'])) {
$isLoggedOn 1;
}

if (!
$isLoggedOn) {
Echo "
Logon Name: <input name='userID' type='text' size='10'/>
Password: <input type='password' name='passWord' type='text' size='10'/>
<input type='submit' name='logon' value='Login'>
<hr />
"
;
}

if (
$isLoggedOn) {
$con mysql_connect("localhost"$userID$passWord);
if (!$con) {
$isLoggedOn 0;
Echo "
Logon Name: <input name='userID' type='text' size='10'/>
Password: <input type='password' name='passWord' type='text' size='10'/>
<input type='submit' name='logon' value='Login'>
<hr />
"
;
Echo "<input type='hidden' id='isLoggedOn' name='isLoggedOn' value='".$isLoggedOn."'/>";
    
die('Could not connect: ' mysql_error());
}
mysql_select_db("pluto_media") or die(mysql_error());

}
if (
$con) {
Echo  "
Search For File: <input name='querStr' type='text' size='10'/>
<input type='submit' name='submit' value='Find'>
Search For Directory: <input name='querStr2' type='text' size='10'/>
<input type='submit' name='submit3' value='Find'>
<input type='hidden' id='con' name='con' value='"
.$con."'/>
<input type='hidden' id='userID' name='userID' value='"
.$userID."'/>
<input type='hidden' id='passWord' name='passWord' value='"
.$passWord."'/>
<input type='hidden' id='isLoggedOn' name='isLoggedOn' value='"
.$isLoggedOn."'/>
<hr />
"
;

if(isset($_POST['submit'])) {
if (strlen($querStr) > 0) {
$result mysql_query("SELECT * FROM File WHERE Filename LIKE '%".$querStr."%'");


//<input type='checkbox' value='1' onclick='var w = document.getElementsByTagName('input'); for(var i = 0; i\"<\" w.length; i++){ if(w[i].type='checkbox'){ w[i].checked = this.checked;};};'>
Echo " <input type='submit' name='submit2' value='Add Attributes To Selected Files'>
<table border='1' bgcolor='White'>
<tr>
<th>Primary File</th>
<th>Update File</th>
<th>Filename</th>
<th>Path</th>
<th>MediaSubType</th>
<th>FileFormat</th>
</tr>"
;

while($row mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><input type='radio' name='primary[]' value=$i/></td>";
echo "<td><input type='checkbox' name='CopyFile[]' value='$i'/></td>";
echo "<td>".$row['Filename']."</td>";
echo "<td>".$row['Path']."</td>";

$FK_Media_Subtype[$i] = $row['FK_MediaSubType'];
$mediaSubtypeStr implode(",",$FK_Media_Subtype);
echo "<td>".$mediaSubTypeEnum[$FK_Media_Subtype[$i]]."</td>";

$FK_File_Format[$i] = $row['FK_FileFormat'];
$fileFormatStr implode(",",$FK_File_Format);
echo "<td>".$fileFormatEnum[$FK_File_Format[$i]]."</td>";      
   
$myArray[$i++] = $row['PK_File'];                            
echo "</tr>";
$saveStr implode(",",$myArray);
echo "<input type='hidden' id='arry' name='myArray' value='".$saveStr."'/>";
echo "<input type='hidden' id='arry2' name='fkmediasubtype' value='".$mediaSubtypeStr."'/>";
echo "<input type='hidden' id='arry3' name='fkfileformat' value='".$fileFormatStr."'/>";
}
echo "</table>";
}
else {
echo "Please enter a valid search string.";
}
}





if(isset($_POST['submit2'])) {
foreach($_POST['primary'] as $value) {
$value  = (int) $value;
echo "the primary is".$value."\n";
}               
$saveStr  $_POST['myArray'];
$myArray explode(",",$saveStr);

$saveStr  $_POST['fkmediasubtype'];
$FK_Media_Subtype explode(",",$saveStr);

$saveStr  $_POST['fkfileformat'];
$FK_File_Format explode(",",$saveStr);
$primaryVal $value;


$result mysql_query("SELECT * FROM Picture_File Where FK_File = '".$myArray[$value]."'");
$row mysql_fetch_array($result);
$FK_Picture $row['FK_Picture'];

$result mysql_query("SELECT * FROM File_Attribute Where FK_File = '".$myArray[$value]."'");
$i 0;
while ($row mysql_fetch_array($result)) {
$FK_File_Attribute[$i++] = $row['FK_Attribute'];
}


// echo "media type = ".$FK_File_Format[$primaryVal];
foreach($_POST['CopyFile'] as $value) {
$value = (int) $value;
mysql_query("INSERT INTO `Picture_File` VALUES ($FK_Picture,$myArray[$value],NULL,NULL,NULL,0,NULL,NULL)");
for ($i 0$i count($FK_File_Attribute); $i++) {
mysql_query("INSERT INTO `File_Attribute` VALUES ($myArray[$value],$FK_File_Attribute[$i],'0','0',NULL ,NULL ,NULL ,'0',NOW(), NULL)");
}
mysql_query("UPDATE File SET FK_MediaSubType=$FK_Media_Subtype[$primaryVal] ,FK_FileFormat=$FK_File_Format[$primaryVal] WHERE PK_File=$myArray[$value]");

}



if(isset($_POST['submit3'])) {
if (strlen($querStr2) > 0) {
$result mysql_query("SELECT * FROM File WHERE Path LIKE '%".$querStr2."%'");


//<input type='checkbox' value='1' onclick='var w = document.getElementsByTagName('input'); for(var i = 0; i\"<\" w.length; i++){ if(w[i].type='checkbox'){ w[i].checked = this.checked;};};'>
Echo " <input type='submit' name='submit2' value='Add Attributes To Selected Files'>
<table border='1' bgcolor='White'>
<tr>
<th>Primary File</th>
<th>Update File</th>
<th>Filename</th>
<th>Path</th>
<th>MediaSubType</th>
<th>FileFormat</th>
</tr>"
;

while($row mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><input type='radio' name='primary[]' value=$i/></td>";
echo "<td><input type='checkbox' name='CopyFile[]' value='$i'/></td>";
echo "<td>".$row['Filename']."</td>";
echo "<td>".$row['Path']."</td>";

$FK_Media_Subtype[$i] = $row['FK_MediaSubType'];
$mediaSubtypeStr implode(",",$FK_Media_Subtype);
echo "<td>".$mediaSubTypeEnum[$FK_Media_Subtype[$i]]."</td>";

$FK_File_Format[$i] = $row['FK_FileFormat'];
$fileFormatStr implode(",",$FK_File_Format);
echo "<td>".$fileFormatEnum[$FK_File_Format[$i]]."</td>";      
   
$myArray[$i++] = $row['PK_File'];                            
echo "</tr>";
$saveStr implode(",",$myArray);
echo "<input type='hidden' id='arry' name='myArray' value='".$saveStr."'/>";
echo "<input type='hidden' id='arry2' name='fkmediasubtype' value='".$mediaSubtypeStr."'/>";
echo "<input type='hidden' id='arry3' name='fkfileformat' value='".$fileFormatStr."'/>";
}
echo "</table>";
}
else {
echo "Please enter a valid search string.";
}
}

}

Echo 
"</form>";
Echo 
"</body>";
Echo 
"</html>";

?>



tschak909

  • LinuxMCE God
  • ****
  • Posts: 5498
  • DOES work for LinuxMCE.
    • View Profile
Re: Batch (mass) assign cover art and attributes
« Reply #4 on: February 02, 2008, 07:46:24 pm »
would you guys try to re-implement this so that it works inside the web admin itself?

-Thom

lon22

  • Veteran
  • ***
  • Posts: 85
    • View Profile
Re: Batch (mass) assign cover art and attributes
« Reply #5 on: February 02, 2008, 08:53:54 pm »
would you guys try to re-implement this so that it works inside the web admin itself?

-Thom


I'm currently working on that endeavor now.