If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

Why is cast not editable in metadata?

BavagoBavago Posts: 105Members ✭✭
Just curious as to why all metadata is editable except the cast list. Media Preview mode displays the first 3 cast members, but the cast lists seem to be in random order and rarely list the stars first. So the vast majority of the time you don't end up seeing who is starring in the movie, you see 3 names you've never heard of. It kinda defeats the purpose.

You can edit directors, writers and everything else, but not the cast list. If you could, it would be a simple matter of putting the cast in an order that makes sense.

Just a thought for future Plex improvements (or maybe this more of a skin issue?).
«13

Comments

  • kappaknightkappaknight Posts: 184Members, Plex Pass Plex Pass
    Just out of curiosity, why is this important to you? I only ask because I don't think I've ever paid attention to this particular field when I'm browsing for movies or shows to watch. I can usually get the gist from the movie poster on who the stars of the movie are.
  • BavagoBavago Posts: 105Members ✭✭

    Just out of curiosity, why is this important to you? I only ask because I don't think I've ever paid attention to this particular field when I'm browsing for movies or shows to watch. I can usually get the gist from the movie poster on who the stars of the movie are.


    Just seems really odd to me that they would build a metadata editor, give you the ability to edit everything, and then leave out just one field... Cast. I wonder if it was an oversight... can't imagine why it would get left out on purpose. You're right that movie posters often give you that info, but not always, or it's too small to read.

    Anyway, to answer your question, it isn't important... but obviously I wouldn't have brought it up if I didn't use that field. So it would be nice to be able to edit that field just like all the rest. They even let you edit some more obscure data like the name of the studio, the writers and the content rating... why not cast?
  • TomtasticTomtastic Posts: 184Members
    edited March 2012
    I look at it all the time, it's nice to see who's in a film before or after watching, besides top billing. I really liked the feature that was in Plex 8. You could click on the actor's name in info screen and it would bring up all the movies in your library that that actor was in. Unfortunately that feature is gone in 9, probably because of how the server is setup. The search is now at the front, which is better overall. I'm not sure that it's not editable, more that there just isn't a field for it. If Plex server isn't using these fields for search, then it probably could be added. Maybe.
  • Chris CChris C Posts: 11,826Members, Plex Employee, Plex Pass, Plex Ninja Plex Employee
    Technically, "Starring Actor" is not the only metadata field like that which isn't exposed in the UI - "Country" is the same.

    For that matter, there are other, more abstract, metadata fields that also aren't exposed: resolution, aspect ratio, video codec, audio codec, audio channels, etc. Though with those I'll certainly accept the argument that they're derived from inherent qualities of the actual media file in question and so it makes sense to not allow them to be modified. ...Except that just this week there was a request to be able to modify the aspect ratio info since some straight disc rips of content will include the black letterboxing bars and those bars are present when Plex's media analysis occurs, thus the aspect ratio reported can be different from what you actually see for the real video content itself. How's that for muddling the waters? heh =)

    Anyway, I can certainly understand a desire to be able to edit both "Starring Actor" and "Country" info, so I'd encourage you to ensure that it's been requested in the stickied "Feature Requests" thread for the Plex Media Server.

    Need help? Having trouble?
    » Visit our Support Site for documentation, guides, and more - including the Getting Started section!
    » Attach Log Files when reporting issues // See how to attach files in the forums
    » Name and Organize your content correctly for best results

    (no private messages for support unless requested, please)

  • BavagoBavago Posts: 105Members ✭✭
    Chris C wrote:

    Anyway, I can certainly understand a desire to be able to edit both "Starring Actor" and "Country" info, so I'd encourage you to ensure that it's been requested in the stickied "Feature Requests" thread for the Plex Media Server.


    Thanks for pointing that out... I've added it to the list.
  • clayton@acrophile.netclayton@acrophile.net Posts: 10Members, Plex Pass Plex Pass
    +1 for Cast list in the metadata... just seems like a no-brainer when you have writers, director etc etc...
  • yomamma_deyomamma_de Posts: 5Members
    I love PLEX, but when it comes to editing metadata I'm missing the ability to edit actors/cast. So I decided to do some PHP scripting. Why PHP? Because my PMS runs on a Synology NAS and I've linked the database to the root of the webserver and about 10 years ago I've already done some PHP scripting. Please be kind with my script - I am not a pro! I haven't done any front-end work, there are only HTML-links and the logic ... and be very carefull, backup your database before you use the script. Improvements are welcome ... :rolleyes:

    <html>
    <head>
    <title></title>
    </head>
    <body>
    <?
    $sqliteDb='com.plexapp.plugins.library.db';
    $db = new SQLite3($sqliteDb);
    
    
    // adds an actor to a movie and checks if the actor is already in the database
    
    if ( ($_POST["NEW"]=="NEW") && ($_POST["ADD19"]<>"ADD19") && ($_POST["tag_new"]<>"") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	$rows_new = $db->query('SELECT COUNT(*) as count FROM tags WHERE tag="'.$_POST["tag_new"].'" AND tag_type=6');
    	$row_new_count = $rows_new->fetchArray();
    
    	$date_new = date('Y-m-d H:i:s');
    
    	switch ($row_new_count['count']) {
    		// actor is not in the database and must be created
    		case 0:
    			$results_tags_new_0 =$db->query('INSERT INTO tags (tag,tag_type,created_at,updated_at) VALUES ("'.$_POST["tag_new"].'",6,"'.$date_new.'","'.$date_new.'")');
    
    			$results_tags_new_0_select = $db->query('SELECT id FROM tags WHERE tag="'.$_POST["tag_new"].'" AND tag_type=6');
    
    			while ($row_tags_new_0_select = $results_tags_new_0_select->fetchArray()) {
    
    				$results_taggings_new_0 =$db->query('INSERT INTO taggings (metadata_item_id,tag_id,text,created_at) VALUES ('.$_GET["metadata_items_id"].','.$row_tags_new_0_select["id"].',"'.$_POST["text_new"].'","'.$date_new.'")');
    
    			}
    
    		break;
    		// actor is in the database and must only be added to the movie
    		case 1:
    			$results_tags_new_1_select = $db->query('SELECT id FROM tags WHERE tag="'.$_POST["tag_new"].'" AND tag_type=6');
    
    			while ($row_tags_new_1_select = $results_tags_new_1_select->fetchArray()) {
    
    				$results_taggings_new_1 =$db->query('INSERT INTO taggings (metadata_item_id,tag_id,text,created_at) VALUES ('.$_GET["metadata_items_id"].','.$row_tags_new_1_select["id"].',"'.$_POST["text_new"].'","'.$date_new.'")');
    
    			}
    		break;
    		default:
    			echo "ERROR";
    		break;
    	}
    
    }
    
    
    // deletes, updates the name and role of actor within a movie
    
    if ( (!empty($_POST)) && ($_POST["NEW"]<>"NEW") && ($_POST["ADD19"]<>"ADD19") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	$results_tags = $db->query('SELECT tags.tag,tags.tag_type,taggings.text,taggings.id,taggings.tag_id  FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY taggings.id');
    
    	while ($row_tags = $results_tags->fetchArray()) {
    
    		if ($row_tags['tag_type']=='6') {
    			switch ($_POST[$row_tags['id']]) {
    				case "DELETE":
    					$results_taggings_delete =$db->query('DELETE FROM taggings WHERE id='.$row_tags['id'].'');
    				break;
    				case "UPDATE_Name":
    					$results_taggings_update_name =$db->query('UPDATE tags SET tag="'.$_POST["tag_".$row_tags['id']].'" WHERE id='.$row_tags['tag_id'].'');
    				break;
    				case "UPDATE_Role":
    					$results_taggings_update_role =$db->query('UPDATE taggings SET text="'.$_POST["text_".$row_tags['id']].'" WHERE id='.$row_tags['id'].'');
    				break;
    			}
    
    		}
    	
    	}
    }
    
    
    // is done every time the database is changed. Creates the attribute tags_star for the table metadata_itmes and the attribute user_fields by adding "lockedFields" Parameter "19" for the actors. Due to a bug in Plex/Web this is removed every time you save the metadata.
    
    if ( (!empty($_POST)) && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	$results_tags_general = $db->query('SELECT tags.tag,tags.tag_type,taggings.text,taggings.id,taggings.tag_id  FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY taggings.id');
    
    	$tags_star ="";
    
    	while ($row_tags_general = $results_tags_general->fetchArray()) {
    
    		if ($row_tags_general['tag_type']=='6') {
    			$tags_star .=$row_tags_general['tag']."|";
    		}
    	
    	}
    	$tags_star=rtrim($tags_star,'|');
    
    	$results_metadata_itmes_update_tags_star =$db->query('UPDATE metadata_items SET tags_star="'.$tags_star.'" WHERE id='.$_GET["metadata_items_id"].'');
    
    	
    	$results_metadata_items_general = $db->query('SELECT title,id,tags_star,user_fields FROM metadata_items WHERE id='.$_GET["metadata_items_id"].' ORDER BY title_sort');
    
    	$user_fields="";
    	$user_fields_trim="";
    	$user_fields_new="lockedFields=";
    
    	while ($row_metadata_items_general = $results_metadata_items_general->fetchArray()) {
    		$user_fields=$row_metadata_items_general['user_fields'];
    	}
    
    	$user_fields_trim = trim($user_fields, "lockedFields=");
    	$user_fields_parts = explode("|", $user_fields_trim);
    
    	if(in_array(19,$user_fields_parts)) {
    
       	} else {
    		$user_fields_parts[]=19;
       	}
    
    	sort($user_fields_parts);
    
    	for($i=0; $i < count($user_fields_parts); $i++)
       	{
       		$user_fields_new .=$user_fields_parts[$i]."|";
       	}
    	$user_fields_new=rtrim($user_fields_new,'|');
    
    	$results_metadata_itmes_update_user_fields =$db->query('UPDATE metadata_items SET user_fields="'.$user_fields_new.'" WHERE id='.$_GET["metadata_items_id"].'');
    }
    
    
    // returns a list of the sections
    
    if (($_GET["library_section_id"]=="") && ($_GET["metadata_items_id"]=="")) {
    
    	$body="";
    
    	$results_library_sections = $db->query('SELECT id,name FROM library_sections');
    
    	while ($row_library_sections = $results_library_sections->fetchArray()) {
    		$body.="<a href=\"".$_SERVER['PHP_SELF']."?library_section_id=".$row_library_sections['id']."\">".htmlentities($row_library_sections['name'], ENT_QUOTES, "UTF-8")."</a> (ID: ".$row_library_sections['id'].")<br>";
    	}
    
    	echo ($body);
    }
    
    
    // returns a list of movies within a section
    
    if (($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]=="")) {
    
    	$body="";
    
    	$results_metadata_items = $db->query('SELECT title,id FROM metadata_items WHERE library_section_id='.$_GET["library_section_id"].' ORDER BY title_sort');
    
    	$body.="<p><a href=\"".$_SERVER['PHP_SELF']."\">back</a></p>";
    
    	while ($row_metadata_items = $results_metadata_items->fetchArray()) {
    		$body.="<a href=\"".$_SERVER['PHP_SELF']."?library_section_id=".$_GET["library_section_id"]."&metadata_items_id=".$row_metadata_items['id']."\">".htmlentities($row_metadata_items['title'], ENT_QUOTES, "UTF-8")."</a> (ID: ".$row_metadata_items['id'].")<br>";
    	}
    
    	$body.="<p><a href=\"".$_SERVER['PHP_SELF']."\">back</a></p>";
    
    	echo ($body);
    }
    
    
    // returns an editable list of actors and some extra information of a movie
    
    if (($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"")) {
    
    	$body="";
    
    	$body.="<p><a href=\"".$_SERVER['PHP_SELF']."?library_section_id=".$_GET["library_section_id"]."\">back</a></p>";
    	$body.="<form action=\"".$_SERVER['PHP_SELF']."?metadata_items_id=".$_GET["metadata_items_id"]."&library_section_id=".$_GET["library_section_id"]."\" method=\"post\"><p>";
    
    	$results_metadata_items = $db->query('SELECT title,id,tags_star,user_fields FROM metadata_items WHERE id='.$_GET["metadata_items_id"].' ORDER BY title_sort');
    
    	while ($row_metadata_items = $results_metadata_items->fetchArray()) {
    		$body.="<p><u>Title:</u> ".htmlentities($row_metadata_items['title'], ENT_QUOTES, "UTF-8")." (ID: ".$row_metadata_items['id'].")</p><p><u>Tags Star:</u> ".htmlentities($row_metadata_items['tags_star'], ENT_QUOTES, "UTF-8")."</p><p><u>User Fields:</u> ".$row_metadata_items['user_fields']." <input type=\"submit\" value=\"ADD19\" name=\"ADD19\"></p>";
    	}
    
    	$results_tags = $db->query('SELECT tags.tag,tags.tag_type,taggings.text,taggings.id FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY taggings.id');
    
    	while ($row_tags = $results_tags->fetchArray()) {
    
    		if ($row_tags['tag_type']=='6') {
    
    			$body.="<u>Name:</u> <input name=\"tag_".$row_tags['id']."\" type=\"text\" size=\"30\" value=\"".$row_tags['tag']."\"> (ID: ".$row_tags['id'].") <u>Role:</u> <input name=\"text_".$row_tags['id']."\" type=\"text\" size=\"30\" value=\"".$row_tags['text']."\"><input type=\"submit\" value=\"UPDATE_Name\" name=\"".$row_tags['id']."\"><input type=\"submit\" value=\"UPDATE_Role\" name=\"".$row_tags['id']."\"><input type=\"submit\" value=\"DELETE\" name=\"".$row_tags['id']."\"><br>";
    
    		}
    	
    	}
    	$body.="<p><u>Name:</u> <input name=\"tag_new\" type=\"text\" size=\"30\" value=\"\"> <u>Role:</u> <input name=\"text_new\" type=\"text\" size=\"30\" value=\"\"><input type=\"submit\" value=\"NEW\" name=\"NEW\">";
    	$body.="</p></form>";
    	$body.="<p><a href=\"".$_SERVER['PHP_SELF']."?library_section_id=".$_GET["library_section_id"]."\">back</a></p>";
    
    	echo ($body);
    
    }
    
    ?>
    </body>
    </html>
    
    
  • thodesmetthodesmet Posts: 4Members ✭✭

    Hello

    I'm really interested in your script.

    Can you help me by telling where to put this?

    Thank you!

    Thomas

  • MReprogleMReprogle Posts: 25Members, Plex Pass Plex Pass
    yomamma_de wrote on January 11 2013, 9:39 PM: »

    I love PLEX, but when it comes to editing metadata I'm missing the ability to edit actors/cast. So I decided to do some PHP scripting. Why PHP? Because my PMS runs on a Synology NAS and I've linked the database to the root of the webserver and about 10 years ago I've already done some PHP scripting. Please be kind with my script - I am not a pro! I haven't done any front-end work, there are only HTML-links and the logic ... and be very carefull, backup your database before you use the script. Improvements are welcome ... :rolleyes:
     

    <html>
    <head>
    <title></title>
    </head>
    <body>
    <?
    $sqliteDb='com.plexapp.plugins.library.db';
    $db = new SQLite3($sqliteDb);
    
    
    // adds an actor to a movie and checks if the actor is already in the database
    
    if ( ($_POST["NEW"]=="NEW") && ($_POST["ADD19"]<>"ADD19") && ($_POST["tag_new"]<>"") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	$rows_new = $db->query('SELECT COUNT(*) as count FROM tags WHERE tag="'.$_POST["tag_new"].'" AND tag_type=6');
    	$row_new_count = $rows_new->fetchArray();
    
    	$date_new = date('Y-m-d H:i:s');
    
    	switch ($row_new_count) {
    		// actor is not in the database and must be created
    		case 0:
    			$results_tags_new_0 =$db->query('INSERT INTO tags (tag,tag_type,created_at,updated_at) VALUES ("'.$_POST["tag_new"].'",6,"'.$date_new.'","'.$date_new.'")');
    
    			$results_tags_new_0_select = $db->query('SELECT id FROM tags WHERE tag="'.$_POST["tag_new"].'" AND tag_type=6');
    
    			while ($row_tags_new_0_select = $results_tags_new_0_select->fetchArray()) {
    
    				$results_taggings_new_0 =$db->query('INSERT INTO taggings (metadata_item_id,tag_id,text,created_at) VALUES ('.$_GET["metadata_items_id"].','.$row_tags_new_0_select["id"].',"'.$_POST["text_new"].'","'.$date_new.'")');
    
    			}
    
    		break;
    		// actor is in the database and must only be added to the movie
    		case 1:
    			$results_tags_new_1_select = $db->query('SELECT id FROM tags WHERE tag="'.$_POST["tag_new"].'" AND tag_type=6');
    
    			while ($row_tags_new_1_select = $results_tags_new_1_select->fetchArray()) {
    
    				$results_taggings_new_1 =$db->query('INSERT INTO taggings (metadata_item_id,tag_id,text,created_at) VALUES ('.$_GET["metadata_items_id"].','.$row_tags_new_1_select["id"].',"'.$_POST["text_new"].'","'.$date_new.'")');
    
    			}
    		break;
    		default:
    			echo "ERROR";
    		break;
    	}
    
    }
    
    
    // deletes, updates the name and role of actor within a movie
    
    if ( (!empty($_POST)) && ($_POST["NEW"]<>"NEW") && ($_POST["ADD19"]<>"ADD19") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	$results_tags = $db->query('SELECT tags.tag,tags.tag_type,taggings.text,taggings.id,taggings.tag_id  FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY taggings.id');
    
    	while ($row_tags = $results_tags->fetchArray()) {
    
    		if ($row_tags=='6') {
    			switch ($_POST[$row_tags]) {
    				case "DELETE":
    					$results_taggings_delete =$db->query('DELETE FROM taggings WHERE id='.$row_tags.'');
    				break;
    				case "UPDATE_Name":
    					$results_taggings_update_name =$db->query('UPDATE tags SET tag="'.$_POST["tag_".$row_tags['id']].'" WHERE id='.$row_tags['tag_id'].'');
    				break;
    				case "UPDATE_Role":
    					$results_taggings_update_role =$db->query('UPDATE taggings SET text="'.$_POST["text_".$row_tags['id']].'" WHERE id='.$row_tags['id'].'');
    				break;
    			}
    
    		}
    	
    	}
    }
    
    
    // is done every time the database is changed. Creates the attribute tags_star for the table metadata_itmes and the attribute user_fields by adding "lockedFields" Parameter "19" for the actors. Due to a bug in Plex/Web this is removed every time you save the metadata.
    
    if ( (!empty($_POST)) && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	$results_tags_general = $db->query('SELECT tags.tag,tags.tag_type,taggings.text,taggings.id,taggings.tag_id  FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY taggings.id');
    
    	$tags_star ="";
    
    	while ($row_tags_general = $results_tags_general->fetchArray()) {
    
    		if ($row_tags_general=='6') {
    			$tags_star .=$row_tags_general."|";
    		}
    	
    	}
    	$tags_star=rtrim($tags_star,'|');
    
    	$results_metadata_itmes_update_tags_star =$db->query('UPDATE metadata_items SET tags_star="'.$tags_star.'" WHERE id='.$_GET["metadata_items_id"].'');
    
    	
    	$results_metadata_items_general = $db->query('SELECT title,id,tags_star,user_fields FROM metadata_items WHERE id='.$_GET["metadata_items_id"].' ORDER BY title_sort');
    
    	$user_fields="";
    	$user_fields_trim="";
    	$user_fields_new="lockedFields=";
    
    	while ($row_metadata_items_general = $results_metadata_items_general->fetchArray()) {
    		$user_fields=$row_metadata_items_general;
    	}
    
    	$user_fields_trim = trim($user_fields, "lockedFields=");
    	$user_fields_parts = explode("|", $user_fields_trim);
    
    	if(in_array(19,$user_fields_parts)) {
    
       	} else {
    		$user_fields_parts[]=19;
       	}
    
    	sort($user_fields_parts);
    
    	for($i=0; $i < count($user_fields_parts); $i++)
       	{
       		$user_fields_new .=$user_fields_parts[$i]."|";
       	}
    	$user_fields_new=rtrim($user_fields_new,'|');
    
    	$results_metadata_itmes_update_user_fields =$db->query('UPDATE metadata_items SET user_fields="'.$user_fields_new.'" WHERE id='.$_GET["metadata_items_id"].'');
    }
    
    
    // returns a list of the sections
    
    if (($_GET["library_section_id"]=="") && ($_GET["metadata_items_id"]=="")) {
    
    	$body="";
    
    	$results_library_sections = $db->query('SELECT id,name FROM library_sections');
    
    	while ($row_library_sections = $results_library_sections->fetchArray()) {
    		$body.="<a href=\"".$_SERVER."?library_section_id=".$row_library_sections."\">".htmlentities($row_library_sections, ENT_QUOTES, "UTF-8")."</a>&nbsp;(ID:&nbsp;".$row_library_sections.")<br>";
    	}
    
    	echo ($body);
    }
    
    
    // returns a list of movies within a section
    
    if (($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]=="")) {
    
    	$body="";
    
    	$results_metadata_items = $db->query('SELECT title,id FROM metadata_items WHERE library_section_id='.$_GET["library_section_id"].' ORDER BY title_sort');
    
    	$body.="<p><a href=\"".$_SERVER."\">back</a></p>";
    
    	while ($row_metadata_items = $results_metadata_items->fetchArray()) {
    		$body.="<a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."&metadata_items_id=".$row_metadata_items."\">".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."</a>&nbsp;(ID:&nbsp;".$row_metadata_items.")<br>";
    	}
    
    	$body.="<p><a href=\"".$_SERVER."\">back</a></p>";
    
    	echo ($body);
    }
    
    
    // returns an editable list of actors and some extra information of a movie
    
    if (($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"")) {
    
    	$body="";
    
    	$body.="<p><a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."\">back</a></p>";
    	$body.="<form action=\"".$_SERVER."?metadata_items_id=".$_GET["metadata_items_id"]."&library_section_id=".$_GET["library_section_id"]."\" method=\"post\"><p>";
    
    	$results_metadata_items = $db->query('SELECT title,id,tags_star,user_fields FROM metadata_items WHERE id='.$_GET["metadata_items_id"].' ORDER BY title_sort');
    
    	while ($row_metadata_items = $results_metadata_items->fetchArray()) {
    		$body.="<p><u>Title:</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."&nbsp;(ID:&nbsp;".$row_metadata_items.")</p><p><u>Tags Star:</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."</p><p><u>User Fields:</u>&nbsp;".$row_metadata_items."&nbsp;<input type=\"submit\" value=\"ADD19\" name=\"ADD19\"></p>";
    	}
    
    	$results_tags = $db->query('SELECT tags.tag,tags.tag_type,taggings.text,taggings.id FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY taggings.id');
    
    	while ($row_tags = $results_tags->fetchArray()) {
    
    		if ($row_tags=='6') {
    
    			$body.="<u>Name:</u>&nbsp;<input name=\"tag_".$row_tags."\" type=\"text\" size=\"30\" value=\"".$row_tags."\">&nbsp;(ID:&nbsp;".$row_tags.")&nbsp;<u>Role:</u>&nbsp;<input name=\"text_".$row_tags."\" type=\"text\" size=\"30\" value=\"".$row_tags."\"><input type=\"submit\" value=\"UPDATE_Name\" name=\"".$row_tags."\"><input type=\"submit\" value=\"UPDATE_Role\" name=\"".$row_tags."\"><input type=\"submit\" value=\"DELETE\" name=\"".$row_tags."\"><br>";
    
    		}
    	
    	}
    	$body.="<p><u>Name:</u>&nbsp;<input name=\"tag_new\" type=\"text\" size=\"30\" value=\"\">&nbsp;<u>Role:</u>&nbsp;<input name=\"text_new\" type=\"text\" size=\"30\" value=\"\"><input type=\"submit\" value=\"NEW\" name=\"NEW\">";
    	$body.="</p></form>";
    	$body.="<p><a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."\">back</a></p>";
    
    	echo ($body);
    
    }
    
    ?>
    </body>
    </html>
    
    

    Excuse me for being a bit of a noob, but how do I add this to my database. Do I have to run IIS on my Windows Server in order to run this php?

  • trevor01trevor01 Posts: 1Members
    edited June 2013

    Just loaded Plex server on my Vortexbox (Fedora), and players on my Roku and on my Mac. I am almost delighted, at least with the handling of Movies.

    But this thread raises an issue that is still a niggle, at least for me. If the contents of the "Cast" field don't include the stars of the show, then the "Search by starring actor" function is pretty much useless. The prepopulated and uneditable values in this field mean that I can't find Amadeus by searching for Tom Hulce or F Murray Abraham; I can't find De-Lovely by searching for Kevin Kline or Ashley Judd; I can't find Topsy-Turvy by searching for Jim Broadbent or Allan Cordiner; and (for heaven's sake) I can't find Ian McKellen's Richard III by searching for Ian McKellen. It's tempting to keep adding examples, but I'll stop there. 

    So, yes, I add my +1 for making the Cast field editable.

    However I found that the relevant Freebase entries do include at least some of the above-mentioned starring actors. So is there something screwed in the way Plex is pulling down the data? Perhaps that needs to be fixed too, so that users don't have to make the corrections themselves.

  • jiantjonjiantjon Posts: 25Members, Plex Pass Plex Pass
    kappaknight wrote on March 8 2012, 8:18 AM: »

    Just out of curiosity, why is this important to you? I only ask because I don't think I've ever paid attention to this particular field when I'm browsing for movies or shows to watch. I can usually get the gist from the movie poster on who the stars of the movie are.

    This is important because only three actors are listed and often the ones that are pulled from the sites are not the top tier actors.   This makes it difficult for me to search for a movie by actor when at my TV or on my mobile device.

  • GiraldoGiraldo Posts: 4Members, Plex Pass Plex Pass
    I justo watched Zero Dark Thirty on Plex and wondered why Idris Elba and Rooney Mara were not showing up. Turns out the source has the wrong Metadata for that movie; so +1 to it being noticeable.
  • yomamma_deyomamma_de Posts: 5Members

    Just did an massive update to my skript. Just working on an import function for metadata from TheMovieDB.org and TheTVDB.com

    <html>
    <head>
    <title></title>
    </head>
    <body>
    <?
    function object_2_array($data) 
    {
    	if(is_array($data) || is_object($data))
    	{
    		$result = array(); 
    		foreach ($data as $key => $value)
    		{ 
    			$result[$key] = object_2_array($value); 
    		}
    		return $result;
    	}
    	return $data;
    }
    
    function makeSortFunction($field)
    {
    	$code = "return strnatcmp(\$a, \$b);"; 
    	return create_function('$a,$b', $code); 
    }
    
    function saveTag($tag_new,$text_new,$metadata_items_id,$number,$tag_type)
    {
    	$sqliteDb='com.plexapp.plugins.library.db';
    	$db = new SQLite3($sqliteDb);
    
    	$strplace="'";
    	$tag_new=str_replace('"',$strplace, $tag_new);
    	$text_new=str_replace('"',$strplace, $text_new);
    
    	$rows_new = $db->query('SELECT COUNT(*) as count FROM tags WHERE tag="'.$tag_new.'" AND tag_type='.$tag_type.'');
    	$row_new_count = $rows_new->fetchArray();
    
    	$date_new = date('Y-m-d H:i:s');
    
    	switch ($row_new_count) {
    		// actor,director,writer, etc. is not in the database and must be created
    		case 0:
    			$results_tags_new_0 =$db->query('INSERT INTO tags (tag,tag_type,created_at,updated_at) VALUES ("'.$tag_new.'",'.$tag_type.',"'.$date_new.'","'.$date_new.'")');
    
    			$results_tags_new_0_select = $db->query('SELECT id FROM tags WHERE tag="'.$tag_new.'" AND tag_type='.$tag_type.'');
    
    			while ($row_tags_new_0_select = $results_tags_new_0_select->fetchArray()) {
    				if ($number=="") {
    					$results_taggings_new_0 =$db->query('INSERT INTO taggings (metadata_item_id,tag_id,text,created_at) VALUES ('.$metadata_items_id.','.$row_tags_new_0_select["id"].',"'.$text_new.'","'.$date_new.'")');
    				} else {
    					$results_taggings_new_0 =$db->query('INSERT INTO taggings (metadata_item_id,tag_id,text,created_at,`index`) VALUES ('.$metadata_items_id.','.$row_tags_new_0_select["id"].',"'.$text_new.'","'.$date_new.'",'.$number.')');
    				}
    			}
    
    		break;
    		// actor,director,writer, etc. is in the database and must only be added to the movie
    		case 1:
    			$results_tags_new_1_select = $db->query('SELECT id FROM tags WHERE tag="'.$tag_new.'" AND tag_type='.$tag_type.'');
    
    			while ($row_tags_new_1_select = $results_tags_new_1_select->fetchArray()) {
    				// check needed, because if the actors,directors,writers, etc. are in the database, they can already been added to the movie. for update or re-import the update- or delete-function must be used. 
    				$rows_new_taggings = $db->query('SELECT COUNT(*) as count FROM taggings WHERE metadata_item_id='.$metadata_items_id.' AND tag_id='.$row_tags_new_1_select["id"].'');
    				$row_new_count_taggings = $rows_new_taggings->fetchArray();
    				if ($row_new_count_taggings==0) {
    					if ($number=="") {
    						$results_taggings_new_1 =$db->query('INSERT INTO taggings (metadata_item_id,tag_id,text,created_at) VALUES ('.$metadata_items_id.','.$row_tags_new_1_select["id"].',"'.$text_new.'","'.$date_new.'")');
    					} else {
    						$results_taggings_new_1 =$db->query('INSERT INTO taggings (metadata_item_id,tag_id,text,created_at,`index`) VALUES ('.$metadata_items_id.','.$row_tags_new_1_select["id"].',"'.$text_new.'","'.$date_new.'",'.$number.')');
    					}					
    				}
    			}
    		break;
    		default:
    			echo "ERROR";
    		break;
    	}
    }
    
    function edit_user_fields($user_fields_general,$action,$metadata_items_id)
    {
    	$sqliteDb='com.plexapp.plugins.library.db';
    	$db = new SQLite3($sqliteDb);
    
    	$user_fields="";
    	$user_fields_trim="";
    	$user_fields_new="lockedFields=";
    
    	if ($action<>"rebuild") {
    
    		$results_metadata_items_general = $db->query('SELECT title,id,tags_star,user_fields FROM metadata_items WHERE id='.$metadata_items_id.' ORDER BY title_sort');
    
    		while ($row_metadata_items_general = $results_metadata_items_general->fetchArray()) {
    			$user_fields=$row_metadata_items_general;
    		}
    
    		$user_fields_trim = trim($user_fields, "lockedFields=");
    		$user_fields_parts = explode("|", $user_fields_trim);
    
    		switch ($action) {
    			case "add":
    				if(in_array($user_fields_general,$user_fields_parts)) {
    
       				} else {
    					$user_fields_parts[]=$user_fields_general;
       				}
    			break;
    			case "remove":
    				$user_fields_parts=array_diff($user_fields_parts, array($user_fields_general));
    			break;
    		}
    	} else  {
    		$user_fields_parts=&$user_fields_general;
    	}
    
    	sort($user_fields_parts);
    
    
    	for($i=0; $i < count($user_fields_parts); $i++)
       	{
       		$user_fields_new .=$user_fields_parts[$i]."|";
       	}
    
    	$user_fields_new=rtrim($user_fields_new,'|');
    
    	$results_metadata_itmes_update_user_fields =$db->query('UPDATE metadata_items SET user_fields="'.$user_fields_new.'" WHERE id='.$metadata_items_id.'');
    
    }
    
    function built_html_metadata($row_metadata_items)
    {
    	$lockedFields=array("1" => "Title", "2" => "Title Sort", "3" => "Original Title", "4" => "Studio", "5" => "Rating", "6" => "Tagline", "7" => "Summary", "8" => "Content Rating", "9" => "User Thumb Url", "10" => "User Art Url", "11" => "User Banner Url", "12" => "User Music Url", "13" => "Original Available At", "14" => "Year", "15" => "Tags Genre", "16" => "Tags Collection", "17" => "Tags Director", "18" => "Tags Writer", "19" => "Tags Star", "24" => "Tags Country");
    
    	$body.="<p><u>Title Sort:</u>&nbsp;<input name=\"title_sort\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_title_sort\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Original Title:</u>&nbsp;<input name=\"original_title\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_original_title\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Studio:</u>&nbsp;<input name=\"studio\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_studio\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Rating:</u>&nbsp;<input name=\"rating\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_rating\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Rating count:</u>&nbsp;<input name=\"rating_count\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_rating_count\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Tagline:</u>&nbsp;<input name=\"tagline\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_tagline\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Summary:</u><br><textarea name=\"summary\" cols=\"50\" rows=\"10\" >".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\"</textarea><br><input type=\"submit\" value=\"UPDATE_summary\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Trivia:</u>&nbsp;<input name=\"trivia\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_trivia\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Quotes:</u>&nbsp;<input name=\"quotes\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_quotes\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Content Rating:</u>&nbsp;<input name=\"content_rating\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_content_rating\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Content Rating Age:</u>&nbsp;<input name=\"content_rating_age\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_content_rating_age\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Originally available at:</u>&nbsp;<input name=\"originally_available_at\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_originally_available_at\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>Year:</u>&nbsp;<input name=\"year\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;<input type=\"submit\" value=\"UPDATE_year\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    	$body.="<p><u>User Fields:</u>&nbsp;".$row_metadata_items."&nbsp;<p>";
    	foreach ($lockedFields AS $key => $value) {
    		$user_fields_trim = trim($row_metadata_items, "lockedFields=");
    		$user_fields_parts = explode("|", $user_fields_trim);
    		if(in_array($key,$user_fields_parts)) {
    			$body.="<input type=\"checkbox\" name=\"lockedFields[]\" value=\"".$key."\" checked=\"checked\">(".$key.")&nbsp;".$value."&nbsp;";
       		} else {
    			$body.="<input type=\"checkbox\" name=\"lockedFields[]\" value=\"".$key."\">(".$key.")&nbsp;".$value."&nbsp;";
       		}
    	}
    	$body.="<input type=\"submit\" value=\"UPDATE_user_fields\" name=\"UPDATE_user_fields\"></p>";
    	$body.="<p><u>Tags Genre:</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."<br>";
    	$body.="<u>Tags Collection:</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."<br>";
    	$body.="<u>Tags Director:</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."<br>";
    	$body.="<u>Tags Writer:</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."<br>";
    	$body.="<u>Tags Star:</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."<br>";
    	$body.="<u>Tags Country:</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."</p>";
    	return $body;
    }
    
    
    $sqliteDb='com.plexapp.plugins.library.db';
    $db = new SQLite3($sqliteDb);
    
    define('TMDB_API_KEY', 'TMDB_API_KEY');
    define('TVDB_API_KEY', 'TVDB_API_KEY');
    define('TMDB_LANGUAGE', 'en');
    define('TVDB_LANGUAGE', 'de');
    
    use TvDb\Client;
    
    if (TMDB_API_KEY<>"TMDB_API_KEY") {
    	include("tmdb/tmdb_v3.php");
    	$tmdb_V3 = new TMDBv3(TMDB_API_KEY);
    }
    
    if (TVDB_API_KEY<>"TVDB_API_KEY") {
    	define('TVDB_URL', 'http://thetvdb.com');
    	include __DIR__.'/tvdb/Client.php';
    	include __DIR__.'/tvdb/Serie.php';
    	include __DIR__.'/tvdb/Banner.php';
    	include __DIR__.'/tvdb/Episode.php';
    	include __DIR__.'/tvdb/Actor.php';
    	$tvdb = new Client(TVDB_URL, TVDB_API_KEY);
    }
    
    $tag_type_general=0;
    $user_fields_general=0;
    
    
    // adds an actor to a movie and checks if the actor is already in the database
    
    if ( ($_POST["NEW"]=="NEW") && ($_POST["IMPORT"]<>"IMPORT") && ($_POST["UPDATE_user_fields"]<>"UPDATE_user_fields") && ($_POST["tag_new"]<>"") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	saveTag($_POST["tag_new"],$_POST["text_new"],$_GET["metadata_items_id"],$_POST["number_new"],$_POST["type_new"]);
    	$tag_type_general=$_POST["type_new"];
    
    }
    
    if ( ($_POST["IMPORT"]=="IMPORT") && ($_GET["library_section_type"]==1) && (TMDB_API_KEY<>"TMDB_API_KEY") && ($_POST["NEW"]<>"NEW") && ($_POST["UPDATE_user_fields"]<>"UPDATE_user_fields") && ($_GET["tmdb_id"]<>"") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	$tmdb_result_cast = $tmdb_V3->movieCastArray($_GET["tmdb_id"]);
    	usort($tmdb_result_cast, makeSortFunction('order'));
    	for($j=0; $j < count($tmdb_result_cast); $j++) {
    		saveTag($tmdb_result_cast[$j],$tmdb_result_cast[$j],$_GET["metadata_items_id"],($j+1),6);			
       	}
    
    }
    
    if ( ($_POST["IMPORT"]=="IMPORT") && ($_GET["library_section_type"]==2) && (TVDB_API_KEY<>"TVDB_API_KEY") && ($_POST["NEW"]<>"NEW") && ($_POST["UPDATE_user_fields"]<>"UPDATE_user_fields") && ($_GET["tvdb_id"]<>"") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	$tvdb_result_cast_object = $tvdb->getActors($_GET["tvdb_id"]);
    	$tvdb_result_cast_array = object_2_array($tvdb_result_cast_object);
    	usort($tvdb_result_cast_array, makeSortFunction('sortorder'));
    	for($j=0; $j < count($tvdb_result_cast_array); $j++) {
    		saveTag($tvdb_result_cast_array[$j],$tvdb_result_cast_array[$j],$_GET["metadata_items_id"],($j+1),6);
       	}
    	if ($_GET["parent_id"]<>"") {
    		$tvdb_result_episodes_object = $tvdb-> getSerieEpisodes($_GET["tvdb_id"],TVDB_LANGUAGE);
    		$tvdb_result_episodes_array = object_2_array($tvdb_result_episodes_object["episodes"]);
    
    		foreach ($tvdb_result_episodes_array as $tvdb_result_episode) {
    			if ($tvdb_result_episode["season"]==$_GET["season"]) {
    				if ($tvdb_result_episode["number"]==$_GET["episode"]) {
    				// all metadata is available and can be saved here for tvdb
    					foreach ($tvdb_result_episode["guestStars"] as $tvdb_result_episode_gueststar) {
    						saveTag(trim($tvdb_result_episode_gueststar),'',$_GET["metadata_items_id"],($j+1),6);
    						$j++;
    					}
       				}
       			}
       		}
       	}
    
    }
    
    if ( ($_POST["UPDATE_user_fields"]=="UPDATE_user_fields") && ($_POST["NEW"]<>"NEW") && ($_POST["IMPORT"]<>"IMPORT") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	edit_user_fields($_POST["lockedFields"],"rebuild",$_GET["metadata_items_id"]);
    }
    
    // deletes, updates the name and role of actor within a movie
    
    if ( (!empty($_POST)) && ($_POST["IMPORT"]<>"IMPORT") && ($_POST["NEW"]<>"NEW") && ($_POST["UPDATE_user_fields"]<>"UPDATE_user_fields") && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	if ($_POST]<>"")  {
    
    		switch ($_POST]) {
    		case "UPDATE_title":
    			$user_fields_general=1;
    		break;
    		case "UPDATE_title_sort":
    			$user_fields_general=2;
    		break;
    		case "UPDATE_original_title":
    			$user_fields_general=3;
    		break;
    		case "UPDATE_studio":
    			$user_fields_general=4;
    		break;
    		case "UPDATE_rating":
    			$user_fields_general=5;
    		break;
    		case "UPDATE_rating_count":
    			$user_fields_general=5;
    		break;
    		case "UPDATE_tagline":
    			$user_fields_general=6;
    		break;
    		case "UPDATE_summary":
    			$user_fields_general=7;
    		break;
    		case "UPDATE_trivia":
    			$user_fields_general=7;
    		break;
    		case "UPDATE_quotes":
    			$user_fields_general=7;
    		break;
    		case "UPDATE_content_rating":
    			$user_fields_general=8;
    		break;
    		case "UPDATE_content_rating_age":
    			$user_fields_general=8;
    		break;
    		case "UPDATE_originally_available_at":
    			$user_fields_general=13;
    		break;
    		case "UPDATE_year":
    			$user_fields_general=14;
    		break;
    		}
    
    		$metadata_item_update_variable=str_replace("UPDATE_","",$_POST]);
    
    		$results_metadata_itmes_update=$db->query('UPDATE metadata_items SET '.$metadata_item_update_variable.'="'.$_POST[$metadata_item_update_variable].'" WHERE id='.$_GET["metadata_items_id"].'');
    
    		if (strlen($_POST[$metadata_item_update_variable])==0) {
    			edit_user_fields($user_fields_general,"remove",$_GET["metadata_items_id"]);
    		} else {
    			edit_user_fields($user_fields_general,"add",$_GET["metadata_items_id"]);
    		}
    
    	}
    
    	$results_tags = $db->query('SELECT tags.tag,taggings.text,taggings.id,taggings.tag_id  FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY taggings.`index`');
    	$date_updated_at = date('Y-m-d H:i:s');
    
    	while ($row_tags = $results_tags->fetchArray()) {
    		switch ($_POST]) {
    			case "DELETE_Tag":
    				$results_taggings_delete =$db->query('DELETE FROM taggings WHERE id='.$row_tags.'');
    				$tag_type_general=$_POST["tag_type_".$row_tags];
    			break;
    			case "UPDATE_Tag_Name":
    				$results_taggings_update_name =$db->query('UPDATE tags SET tag="'.$_POST["tag_".$row_tags['id']].'", updated_at="'.$date_updated_at.'" WHERE id='.$row_tags['tag_id'].'');
    				$tag_type_general=$_POST["tag_type_".$row_tags];
    			break;
    			case "UPDATE_Tag_Role":
    				if ($_POST["number_".$row_tags]=="") {
    					$results_taggings_update_role =$db->query('UPDATE taggings SET text="'.$_POST["text_".$row_tags['id']].'", created_at="'.$date_updated_at.'" WHERE id='.$row_tags['id'].'');
    				} else {
    					$results_taggings_update_role =$db->query('UPDATE taggings SET text="'.$_POST["text_".$row_tags['id']].'", `index`='.$_POST["number_".$row_tags['id']].', created_at="'.$date_updated_at.'" WHERE id='.$row_tags.'');
    				}
    				$tag_type_general=$_POST["tag_type_".$row_tags];
    			break;
    		}
    	}
    }
    
    
    // is done every time the database is changed. Creates the attribute tags_star for the table metadata_itmes and the attribute user_fields by adding "lockedFields" Parameter "19" for the actors. Due to a bug in Plex/Web this is removed every time you save the metadata.
    
    if ( (!empty($_POST)) && ($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") ) {
    
    	// update the tags_* in metadata_items
    
    	if ($tag_type_general<>0) {
    
    		$results_tags_general = $db->query('SELECT tags.tag,tags.tag_type,taggings.text,taggings.id,taggings.tag_id  FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY taggings.`index`');
    
    		$tags_general="";
    
    		while ($row_tags_general = $results_tags_general->fetchArray()) {
    
    			if ($tag_type_general==$row_tags_general) {
    				$tags_general .=$row_tags_general."|";
    			}
    
    		}
    
    		$tags_general=rtrim($tags_general,'|');
    
    		switch ($tag_type_general) {
    		case 1:
    			$tags_general_field="tags_genre";
    			$user_fields_general=15;
    		break;
    		case 2:
    			$tags_general_field="tags_collection";
    			$user_fields_general=16;
    		break;
    		case 4:
    			$tags_general_field="tags_director";
    			$user_fields_general=17;
    		break;
    		case 5:
    			$tags_general_field="tags_writer";
    			$user_fields_general=18;
    		break;
    		case 6:
    			$tags_general_field="tags_star";
    			$user_fields_general=19;
    		break;
    		case 8:
    			$tags_general_field="tags_country";
    			$user_fields_general=24;
    		break;
    		}
    
    		$results_metadata_itmes_update_tags_star =$db->query('UPDATE metadata_items SET '.$tags_general_field.'="'.$tags_general.'" WHERE id='.$_GET["metadata_items_id"].'');
    
    		// and now update lockedFields when insert, changed and deleted
    
    		if (strlen($tags_general)==0) {
    			edit_user_fields($user_fields_general,"remove",$_GET["metadata_items_id"]);
    		} else {
    			edit_user_fields($user_fields_general,"add",$_GET["metadata_items_id"]);
    		}
    	}
    	
    }
    
    
    // returns a list of the sections
    
    if (($_GET["library_section_id"]=="") && ($_GET["metadata_items_id"]=="")) {
    
    	$body="";
    
    	$results_library_sections = $db->query('SELECT id,name,section_type FROM library_sections');
    
    	while ($row_library_sections = $results_library_sections->fetchArray()) {
    		$body.="<a href=\"".$_SERVER."?library_section_id=".$row_library_sections."&library_section_type=".$row_library_sections."\">".htmlentities($row_library_sections, ENT_QUOTES, "UTF-8")."</a>&nbsp;(ID:&nbsp;".$row_library_sections.")<br>";
    	}
    
    	echo ($body);
    }
    
    
    // returns a list of movies within a section
    
    if (($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]=="")) {
    
    	$body="";
    
    	$results_metadata_items = $db->query('SELECT title,id,parent_id FROM metadata_items WHERE library_section_id='.$_GET["library_section_id"].' ORDER BY title_sort');
    
    	$body.="<p><a href=\"".$_SERVER."\">back</a></p>";
    
    	while ($row_metadata_items = $results_metadata_items->fetchArray()) {
    		switch ($_GET["library_section_type"]) {
    			case 1:
    				$body.="<a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."&library_section_type=".$_GET["library_section_type"]."&metadata_items_id=".$row_metadata_items."\">".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."</a>&nbsp;(ID:&nbsp;".$row_metadata_items.")<br>";
    			break;
    			case 2:
    				if ($row_metadata_items=="") {	
    					$body.="<a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."&library_section_type=".$_GET["library_section_type"]."&metadata_items_id=".$row_metadata_items."\">".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."</a>&nbsp;(ID:&nbsp;".$row_metadata_items.")<br>";
    					
    					$results_metadata_items_seasons = $db->query('SELECT title,id,parent_id,`index` FROM metadata_items WHERE parent_id='.$row_metadata_items.' ORDER BY `index`');
    
    					while ($row_metadata_items_seasons = $results_metadata_items_seasons->fetchArray()) {
    						if ($row_metadata_items_seasons==0) {
    							$body.="<br>&nbsp;&nbsp;Special&nbsp;(ID:&nbsp;".$row_metadata_items_seasons.")<br>";
    						} else  {
    							$body.="<br>&nbsp;&nbsp;Season:&nbsp;".$row_metadata_items_seasons."&nbsp;(ID:&nbsp;".$row_metadata_items_seasons.")<br>";
    						}
    
    						$results_metadata_items_episodes = $db->query('SELECT title,id,parent_id,`index` FROM metadata_items WHERE parent_id='.$row_metadata_items_seasons.' ORDER BY `index`');
    
    						while ($row_metadata_items_episodes = $results_metadata_items_episodes->fetchArray()) {
    							$body.="&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."&library_section_type=".$_GET["library_section_type"]."&metadata_items_id=".$row_metadata_items_episodes."&parent_id=".$row_metadata_items_seasons."&season=".$row_metadata_items_seasons."&episode=".$row_metadata_items_episodes."\">Episode:&nbsp;".$row_metadata_items_episodes."&nbsp;-&nbsp;".htmlentities($row_metadata_items_episodes, ENT_QUOTES, "UTF-8")."</a>&nbsp;(ID:&nbsp;".$row_metadata_items_episodes.")<br>";
    						}
    					}
    					$body.="<br>";
    				}
    			break;
    		}
    	}
    
    	$body.="<p><a href=\"".$_SERVER."\">back</a></p>";
    
    	echo ($body);
    }
    
    
    // returns an editable list of actors and some extra information of a movie
    
    if (($_GET["library_section_id"]<>"") && ($_GET["metadata_items_id"]<>"") && ($_GET["library_section_type"]<>"")) {
    
    	$body="";
    
    	$body.="<p><a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."&library_section_type=".$_GET["library_section_type"]."\">back</a></p>";
    	$body.="<form accept-charset=\"UTF-8\" action=\"".$_SERVER."?metadata_items_id=".$_GET["metadata_items_id"]."&library_section_id=".$_GET["library_section_id"]."&library_section_type=".$_GET["library_section_type"]."&tmdb_id=".$_GET["tmdb_id"]."&tvdb_id=".$_GET["tvdb_id"]."&parent_id=".$_GET["parent_id"]."&season=".$_GET["season"]."&episode=".$_GET["episode"]."\" method=\"post\"><p>";
    
    	// Information from metadata_items
    
    	if ($_GET["parent_id"]=="") {
    		$results_metadata_items = $db->query('SELECT * FROM metadata_items WHERE id='.$_GET["metadata_items_id"].' ORDER BY title_sort');
    	} else  {
    		$results_metadata_items = $db->query('SELECT * FROM metadata_items WHERE id='.$_GET["parent_id"].' ORDER BY title_sort');
    	}
    
    	while ($row_metadata_items = $results_metadata_items->fetchArray()) {
    		if ($_GET["parent_id"]=="") {
    			$body.="<p><u>Title:</u>&nbsp;<input name=\"title\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."\">&nbsp;(ID:&nbsp;".$row_metadata_items.")&nbsp;<input type=\"submit\" value=\"UPDATE_title\" name=\"metadata_items_id_".$row_metadata_items."\"></p>";
    			$body.=built_html_metadata($row_metadata_items);
    		} else  {
    			$results_metadata_items_parent_id = $db->query('SELECT *FROM metadata_items WHERE id='.$_GET["metadata_items_id"].' ORDER BY title_sort');
    			while ($row_metadata_items_parent_id = $results_metadata_items_parent_id->fetchArray()) {
    				$body.="<p><u>Titel (Episode):</u>&nbsp;<input name=\"title\" type=\"text\" size=\"30\" value=\"".htmlentities($row_metadata_items_parent_id, ENT_QUOTES, "UTF-8")."\">&nbsp;(ID:&nbsp;".$row_metadata_items_parent_id.")&nbsp;<input type=\"submit\" value=\"UPDATE_title\" name=\"metadata_items_id_".$row_metadata_items_parent_id."\"><br>";
    				$body.="<u>Title (TV Show):</u>&nbsp;".htmlentities($row_metadata_items, ENT_QUOTES, "UTF-8")."&nbsp;(".$row_metadata_items.")&nbsp;(ID:&nbsp;".$row_metadata_items.")</p>";
    
    				$body.=built_html_metadata($row_metadata_items_parent_id);
    			}
    		}
    
    		switch ($_GET["library_section_type"]) {
    			case 1:
    			if (TMDB_API_KEY<>"TMDB_API_KEY") {
    				$tmdb_result = $tmdb_V3->searchMovie($row_metadata_items,TMDB_LANGUAGE);
    				$tmdb_result_array = $tmdb_result;
    				$tmbd_search_original_title = $row_metadata_items;
    			}
    			break;
    
    			case 2:
    				if (TVDB_API_KEY<>"TVDB_API_KEY") {
    					$tvdb_result = $tvdb->getSeries($row_metadata_items,TVDB_LANGUAGE);
    					$tvbd_search_original_title = $row_metadata_items;
    				}
    			break;
    		}
    	}
    
    	// Information from taggings
    
    	$results_tags = $db->query('SELECT tags.tag,tags.tag_type,taggings.text,taggings.id,taggings.`index` FROM taggings JOIN tags WHERE taggings.metadata_item_id='.$_GET["metadata_items_id"].' AND taggings.tag_id=tags.id ORDER BY tags.tag_type,taggings.`index`');
    
    	$tags_type_before=0;
    	while ($row_tags = $results_tags->fetchArray()) {
    		if ($tags_type_before<>$row_tags) {
    			switch ($row_tags) {
    			case 1:
    				$body.="<p><u>Tag:&nbsp;Genre</u>&nbsp;(<b>Don't use \"#\" and \"Text\"!</b> Maybe Plex will use one day \"#\", because it would make sense for sorting.)</p>";
    			break;
    			case 2:
    				$body.="<p><u>Tag:&nbsp;Collection</u>&nbsp;(<b>Don't use \"#\" and \"Text\"!</b> Maybe Plex will use one day \"#\", because it would make sense for sorting.)</p>";
    			break;
    			case 4:
    				$body.="<p><u>Tag:&nbsp;Director</u>&nbsp;(<b>Don't use \"#\" and \"Text\"!</b> Maybe Plex will use one day \"#\", because it would make sense for sorting.)</p>";
    			break;
    			case 5:
    				$body.="<p><u>Tag:&nbsp;Writer</u>&nbsp;(<b>Don't use \"#\" and \"Text\"!</b> Maybe Plex will use one day \"#\", because it would make sense for sorting.)</p>";
    			break;
    			case 6:
    				$body.="<p><u>Tag:&nbsp;Star</u>&nbsp;(Plex-Agents are using \"#\" for sorting and \"Text\" for the name of the role. <b>So use it!</b>)</p>";
    			break;
    			case 8:
    				$body.="<p><u>Tag:&nbsp;Country</u>&nbsp;(<b>Don't use \"#\" and \"Text\"!</b> Maybe Plex will use one day \"#\", because it would make sense for sorting.)</p>";
    			break;
    			}
    		}
    		$body.="<u>Name:</u>&nbsp;<input name=\"tag_".$row_tags."\" type=\"text\" size=\"20\" value=\"".htmlentities($row_tags, ENT_QUOTES, "UTF-8")."\">&nbsp;";
    		$body.="&nbsp;<u>#:</u>&nbsp;<input name=\"number_".$row_tags."\" type=\"text\" size=\"2\" value=\"".htmlentities($row_tags, ENT_QUOTES, "UTF-8")."\">&nbsp;<u>Text:</u>&nbsp;<input name=\"text_".$row_tags."\" type=\"text\" size=\"20\" value=\"".htmlentities($row_tags, ENT_QUOTES, "UTF-8")."\">&nbsp;(ID:&nbsp;".$row_tags.")&nbsp;";
    		$body.="<input type=\"hidden\" value=\"".$row_tags."\" name=\"tag_type_".$row_tags."\">";
    		$body.="<input type=\"submit\" value=\"UPDATE_Tag_Name\" name=\"taggings_id_".$row_tags."\">";
    		$body.="<input type=\"submit\" value=\"UPDATE_Tag_Role\" name=\"taggings_id_".$row_tags."\">";
    		$body.="<input type=\"submit\" value=\"DELETE_Tag\" name=\"taggings_id_".$row_tags."\"><br>";
    		$tags_type_before=$row_tags;	
    	}
    
    	$body.="<p><u>New Tag:</u>&nbsp;(<b>Only</b> use \"#\" and \"Text\" for Star.)</p>";
    	$body.="<p><u>Name:</u>&nbsp;<input name=\"tag_new\" type=\"text\" size=\"20\" list=\"tag_list\" value=\"\">&nbsp;";
    	$body.="<datalist id=\"tag_list\">";
    
    	$tag_list = $db->query('SELECT tag FROM tags GROUP BY tag');
    	while ($row_tag_list = $tag_list->fetchArray()) {
    		$body.="<option value=\"".htmlentities($row_tag_list , ENT_QUOTES, "UTF-8")."\"></option>";
    	}
    
    	$body.="</datalist>";
    	$body.="&nbsp;<u>#:</u>&nbsp;<input name=\"number_new\" type=\"text\" size=\"2\" value=\"\">&nbsp;<u>Text:</u>&nbsp;<input name=\"text_new\" type=\"text\" size=\"20\" value=\"\">&nbsp;";
    	$body.="<u>Type:</u>&nbsp;<select name=\"type_new\" size=\"1\"><option value=\"1\">Genre</option><option value=\"2\">Collection</option><option value=\"4\">Director</option><option value=\"5\">Writer</option><option value=\"6\">Star</option><option value=\"8\">Country</option></select>&nbsp;";
    	$body.="<input type=\"submit\" value=\"NEW\" name=\"NEW\"></p>";
    
    	// Information from TMDB or TVDB for import
    
    	switch ($_GET["library_section_type"]) {
    		case 1:
    		if (TMDB_API_KEY<>"TMDB_API_KEY") {
    			$body.="<br><p><u>The Movie Database - themoviedb.org</u>&nbsp;(Search Original Title:&nbsp;".htmlentities($tmbd_search_original_title, ENT_QUOTES, "UTF-8").")</p>";
    
    			for($i=0; $i < $tmdb_result; $i++) {
    				if ( ($tmdb_result_array[$i]<>"") && ($tmdb_result_array[$i]<>"") && ($tmdb_result_array[$i]<>"") ) {
       					$body.="<a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."&library_section_type=".$_GET["library_section_type"]."&metadata_items_id=".$_GET["metadata_items_id"]."&tmdb_id=".$tmdb_result_array[$i]."\">".htmlentities($tmdb_result_array[$i], ENT_QUOTES, "UTF-8")."</a>&nbsp;(".$tmdb_result_array[$i].")&nbsp;(TMDB ID:&nbsp;".$tmdb_result_array[$i].")<br>";
    				}
    		
    				if ( ($_GET["tmdb_id"]<>"") && ($_GET["tmdb_id"]==$tmdb_result_array[$i]) ) {
    					$tmdb_result_cast = $tmdb_V3->movieCastArray($_GET["tmdb_id"]);
    					usort($tmdb_result_cast, makeSortFunction('order'));
    					for($j=0; $j < count($tmdb_result_cast); $j++)
       					{
       						$body.="&nbsp;&nbsp;&nbsp;<u>Name:</u>&nbsp;".htmlentities($tmdb_result_cast[$j], ENT_QUOTES, "UTF-8")."&nbsp;<u>Role:</u>&nbsp;".htmlentities($tmdb_result_cast[$j], ENT_QUOTES, "UTF-8")."<br>";
       					}
    				$body.="&nbsp;&nbsp;&nbsp;<input type=\"submit\" value=\"IMPORT\" name=\"IMPORT\"><br><br>";
       				}
       			}
       		}
    		break;
    
    		case 2:
    		if (TVDB_API_KEY<>"TVDB_API_KEY") {
    			$body.="<br><p><u>TheTVDB.com</u>&nbsp;(Search Original Title:&nbsp;".htmlentities($tvbd_search_original_title, ENT_QUOTES, "UTF-8").")</p>";
    
    			$tvdb_result_id_array = array();
    
    			for($i=0; $i < count($tvdb_result); $i++) {
    				$tvdb_result_object = $tvdb_result[$i];
    				$tvdb_result_array = object_2_array($tvdb_result_object);
    				if(in_array($tvdb_result_array,$tvdb_result_id_array)) {
    
       				} else {
    					$tvdb_result_id_array[]=$tvdb_result_array;
    
       					$body.="<a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."&library_section_type=".$_GET["library_section_type"]."&metadata_items_id=".$_GET["metadata_items_id"]."&tvdb_id=".$tvdb_result_array."&parent_id=".$_GET["parent_id"]."&season=".$_GET["season"]."&episode=".$_GET["episode"]."\">".htmlentities($tvdb_result_array, ENT_QUOTES, "UTF-8")."</a>&nbsp;(TMDB ID:&nbsp;".$tvdb_result_array.")<br>";
    					if ( ($_GET["tvdb_id"]<>"") && ($_GET["tvdb_id"]==$tvdb_result_array) ) {
    						$tvdb_result_cast_object = $tvdb->getActors($_GET["tvdb_id"]);
    						$tvdb_result_cast_array = object_2_array($tvdb_result_cast_object);
    						usort($tvdb_result_cast_array, makeSortFunction('sortorder'));
    						for($j=0; $j < count($tvdb_result_cast_array); $j++)
       						{
       							$body.="&nbsp;&nbsp;&nbsp;<u>Name:</u>&nbsp;".htmlentities($tvdb_result_cast_array[$j], ENT_QUOTES, "UTF-8")."&nbsp;<u>Role:</u>&nbsp;".htmlentities($tvdb_result_cast_array[$j], ENT_QUOTES, "UTF-8")."<br>";
       						}
    						if ($_GET["parent_id"]<>"") {
    							$tvdb_result_episodes_object = $tvdb-> getSerieEpisodes($_GET["tvdb_id"],TVDB_LANGUAGE);
    							$tvdb_result_episodes_array = object_2_array($tvdb_result_episodes_object["episodes"]);
    
    							foreach ($tvdb_result_episodes_array as $tvdb_result_episode) {
    								if ($tvdb_result_episode["season"]==$_GET["season"]) {
    									if ($tvdb_result_episode["number"]==$_GET["episode"]) {
    										foreach ($tvdb_result_episode["guestStars"] as $tvdb_result_episode_gueststar) {
       											$body.="&nbsp;&nbsp;&nbsp;<u>Guest Name:</u>&nbsp;".htmlentities(trim($tvdb_result_episode_gueststar), ENT_QUOTES, "UTF-8")."&nbsp;<u>Role:</u>&nbsp;<br>";
    										}
       									}
       								}
       							}
       						}
    					$body.="&nbsp;&nbsp;&nbsp;<input type=\"submit\" value=\"IMPORT\" name=\"IMPORT\"><br><br>";
       					}
       				}
       			}
    		}
    		break;
    	}
    	
    	$body.="</form>";
    
    	$body.="<p><a href=\"".$_SERVER."?library_section_id=".$_GET["library_section_id"]."&library_section_type=".$_GET["library_section_type"]."\">back</a></p>";
    
    	echo ($body);
    }
    ?>
    </body>
    </html>
    
    


     have fun ... and stay tuned for the importer ...

  • wdrgmwdrgm Posts: 3Members, Plex Pass Plex Pass

    Another +1 for editable cast, for other reasons - HOME MOVIES.  I love being able to fill out the tag lines and descriptions for the Home vids - makes it look really professional when showing to the rest of the family.  Country, Genre, Collection, Year takes care of most of the sorting, but I really need that last piece - the people in the vid.  I could use Writer or Director, but actor is the right place to sort the people in the vids.

    Interesting though, I did manage to fill out an actor on one of my home movies, but I have no idea how I did it - and now I can't undo it.

  • rafilokrafilok Posts: 5Members, Plex Pass Plex Pass

    +1 for cast editing

    thanks for the great work!

    -raf

  • deadmonkiesdeadmonkies Posts: 2Members, Plex Pass Plex Pass
    yomamma_de wrote on July 13 2013, 9:25 PM: »

    have fun ... and stay tuned for the importer ...

    Are you working on some sort of tool other than using PHP? I've got some experience working with Perl and Python and would be interested in something along those lines. If not, I'll use your code as a jumping off point to write something else, probably just command line to start with. Not being able to edit cast members is my one gripe with Plex at this point.

  • tooclosetoseetooclosetosee Posts: 5Members, Plex Pass Plex Pass

    I would like this as well. The other day I wanted to see which movies in my collection had Jake Gyllenhal in them and it returned 0, but I know I have like 3 or so. I would be fine if it listed the top 5 biggest names, but too often it doesn't list the big name actors. 

    Instead I have a humongous list of actors and I only recognize 60% of them or so. 

  • icedragonslairicedragonslair Posts: 13Members ✭✭
    edited March 2014

    1 to editable cast as well

    I am also not getting the cast or even correct info at all on a lot of my films, and when I correct them they seem to change back a week later...thinking xbmc again...even though I have paid for this

  • jonguy1000jonguy1000 Posts: 2Members

    Hi

    Not long been using plex. On the whole a great experience but yes this is a glaring omission. Just added Elysium and Matt Damon isn't even show as one of the cast??

    +1 here!

  • jordangookin@gmail.comjordangookin@gmail.com Posts: 4Members, Plex Pass Plex Pass

    Yes, please PLEASE can we edit cast metadata?? Or fix how the data is pulled? Because I'm getting a little tired of seeing "12 Monkeys" starring "Jon SedaRick WarnerChristopher Meloni, "Back to the Future" starring "George DiCenzoHuey LewisJ.J. Cohen", and "The Godfather" starring "Sonny GrossoGray FredericksonCarmine Coppola.

«13
Sign In or Register to comment.