Coding Questions

So I have been trying to do something I thought would be pretty straight forward. Just get Plex to play a DVD VIDEO_TS folder when it was in the format MovieTitle/Video_TS/VIDEO_TS.IFO - because that is how they are generally created (if there is a reason XBMC doesn’t do this already I would be curious why - if anyone knows). And also so the scrapper would recognize these folders as DVDs and put them into the library correctly.



I first looked at the stacking code, but stack seems to be more for just removing other files - like stacking currently does with DVD images - it looks for VIDEO_TS.IFO and if it exists removes all the other files (I think anyways). This didn’t seem to be what I was looking for. So I found where the click method was - CGUIMediaWindow::OnClick(int iItem) and thought the next step was to just loop through the contents of pItem - but I can’t seem to even figure that out. There doesn’t seem to be any method on CFileItem to search the contents of a directory (although it knows it’s a directory) and if you create a CFileItemList from it CFileItemList items(pItem->m_strPath) it doesn’t seem to have been initialized like I would expect - Sise() returns zero and I don’t know what I am supposed to do to fill a CFileItemList so I can loop over it. I was trying to start with something fairly small because I haven’t played with C++ much.



I’m not even sure if this is the right path or not, but I wanted to try playing around with the code. Any pushes in the right direction would be appreciated! Thanks!

Playing with the stacking code would be the way to go, but a quick search through that code reveals that it’s already done.



The code for stacking the dvd folders happens like this (See CFileItemList::Stack()):



if (item is a folder)<br />
{<br />
  if ( not on remote share or on a smb share or on a xbms share or in a zip or rar)<br />
  {<br />
	 if (folder name is something like "CD2")<br />
	 {<br />
	 }<br />
	 else<br />
	 {<br />
		dvdpath = "";<br />
		if (<foldername>\video_ts.ifo exists)<br />
		{<br />
		   dvdpath = <foldername>\video_ts.ifo<br />
		}<br />
		else if (foldername\video_ts\video_ts.ifo exists)<br />
		{<br />
		   dvdpath = <foldername>\video_ts\video_ts.ifo<br />
		}<br />
		if (dvdpath)<br />
		{<br />
		   change path of item to dvdpath, and make it a file instead of a folder.<br />
		}<br />
	 }<br />
  }<br />
}



So it seems to me it should work out of the box (assuming it's either local or smb or xbms) etc.

Cheers,
Jonathan

Hmm, that is not what I am seeing -

http://github.com/elan/xbmc-fork/tree/v0.5/xbmc/FileItem.cpp



We are never doing a check for the \VIDEO_TS\VIDEO_TS.IFO in the Stack().



Following your suggestion I added this:



	  if( item->m_bIsFolder)<br />
	  {<br />
		// check for any dvd directories, only on known fast types<br />
		// i'm adding xbms even thou it really isn't fast due to<br />
		// opening file to check for existence<br />
		if( !item->IsRemote()<br />
		 || item->IsSmb()<br />
		 || CUtil::IsInRAR(item->m_strPath)<br />
		 || CUtil::IsInZIP(item->m_strPath)<br />
		 || item->m_strPath.Left(5).Equals("xbms", false)<br />
		 )<br />
		{<br />
		  CStdString path;<br />
		  CUtil::AddFileToFolder(item->m_strPath, "VIDEO_TS.IFO", path);<br />
		  if (CFile::Exists(path))<br />
		  {<br />
			/* set the thumbnail based on folder */<br />
			item->SetCachedVideoThumb();<br />
			if (!item->HasThumbnail())<br />
			  item->SetUserVideoThumb();<br />
 <br />
			item->m_bIsFolder = false;<br />
			item->m_strPath = path;<br />
			item->SetLabel2("");<br />
			item->SetLabelPreformated(true);<br />
			m_sortMethod = SORT_METHOD_NONE; /* sorting is now broken */<br />
 <br />
			/* override the previously set thumb if video_ts.ifo has any */<br />
			/* otherwise user can't set icon on the stacked file as that */<br />
			/* will allways be set on the video_ts.ifo file */<br />
			CStdString thumb(item->GetCachedVideoThumb());<br />
			if(CFile::Exists(thumb))<br />
			  item->SetThumbnailImage(thumb);<br />
			else<br />
			  item->SetUserVideoThumb();<br />
 <br />
		  }<br />
		}<br />
		continue;<br />
	  }



to


	  if( item->m_bIsFolder)<br />
	  {<br />
		// check for any dvd directories, only on known fast types<br />
		// i'm adding xbms even thou it really isn't fast due to<br />
		// opening file to check for existence<br />
		if( !item->IsRemote()<br />
		 || item->IsSmb()<br />
		 || CUtil::IsInRAR(item->m_strPath)<br />
		 || CUtil::IsInZIP(item->m_strPath)<br />
		 || item->m_strPath.Left(5).Equals("xbms", false)<br />
		 )<br />
		{<br />
	  CStdString dvdPath="";<br />
		  CStdString path;<br />
		  CUtil::AddFileToFolder(item->m_strPath, "VIDEO_TS.IFO", path);<br />
		  if (CFile::Exists(path))<br />
		  {<br />
		dvdPath=path;<br />
		}<br />
		else<br />
	   {<br />
			  CUtil::AddFileToFolder(item->m_strPath, "VIDEO_TS\\VIDEO_TS.IFO", path);<br />
			  if (CFile::Exists(path))<br />
		  {<br />
			 dvdPath=path;<br />
		   }	<br />
		}<br />
		if (dvdPath)<br />
	   {<br />
			/* set the thumbnail based on folder */<br />
			item->SetCachedVideoThumb();<br />
			if (!item->HasThumbnail())<br />
			  item->SetUserVideoThumb();<br />
<br />
			item->m_bIsFolder = false;<br />
			item->m_strPath = path;<br />
			item->SetLabel2("");<br />
			item->SetLabelPreformated(true);<br />
			m_sortMethod = SORT_METHOD_NONE; /* sorting is now broken */<br />
<br />
			/* override the previously set thumb if video_ts.ifo has any */<br />
			/* otherwise user can't set icon on the stacked file as that */<br />
			/* will allways be set on the video_ts.ifo file */<br />
			CStdString thumb(item->GetCachedVideoThumb());<br />
			if(CFile::Exists(thumb))<br />
			  item->SetThumbnailImage(thumb);<br />
			else<br />
			  item->SetUserVideoThumb();<br />
<br />
		  }<br />
		}<br />
		continue;<br />
	  }



And movies seems to work perfectly now!

Elan - can we get this change into the next build? I've seen more then one thread complaining about this in the forums. And this was one of the last things I was still using Sapphire for - my DVD rips.

This stacking doesn't seem to work properly for TV Shows though because in CGUIWindowVideoFiles::GetDirectory we do this check


  if (m_database.GetScraperForPath(strDirectory,info2) && info2.strContent.Equals("tvshows"))<br />
  { // dont stack in tv dirs<br />
	g_stSettings.m_iMyVideoStack |= STACK_UNAVAILABLE;<br />
  }<br />
  else if (!items.IsStack() && g_stSettings.m_iMyVideoStack != STACK_NONE)<br />
	items.Stack();



Changing it to


  if (!items.IsStack() && g_stSettings.m_iMyVideoStack != STACK_NONE)<br />
	items.Stack();



Doesn't seem to have any negative effect. I'm not sure why we wouldn't want to stack on TV shows - they could be on DVD too. There might be some issues with the scrapper and TV shows, I'm not sure yet.

It looks like the code in question is different in Plex vs XBMC. There are some changes I haven’t merged yet. You can ask Git to show you the difference in the two trees:



$ git diff HEAD xbmc – xbmc/FileItem.cpp



Part of the problem is that we haven’t merged the code for CFileItemPtr yet, so the merge can’t be done trivially.



Please compare the code you’ve suggested to the current code in XBMC and see how it sizes up, and then request a pull from me on Github, and I’ll incorporate it. Thanks for tracking this down!



(Apropos the TV show stacking, please test and see if there are any issues with scraping/library, and if not we’ll get that fix in too.)

I get



$ git diff HEAD xbmc -- xbmc/FileItem.cpp<br />
fatal: bad revision 'xbmc'



but I don't think I have ever gotten anything in Git to work properly :).

Is the XBMC branch in GitHub? I can't seem to find it - I would like to keep my changes as close to theirs so later merging won't have any issues.


Yeah, the XBMC branch is in Git. If you're pulling from my repository, you can reference the remote branch like this (assuming you've fetched the latest):


$ git diff HEAD origin/xbmc -- xbmc/FileItem.cpp



However, it looks like you've forked me, which means you can add me as a remote and diff from there:


$ git remote add elan git://github.com/elan/xbmc-fork.git<br />
$ git diff HEAD elan/xbmc -- xbmc/FileItem.cpp



That *should* work, you might need to insert a "git fetch elan" in the middle!

Is there another environment variable I need to set with the Plex rebranding - like XBMC_HOME? I updated my code and get a crash when I start up from source -



01:07:31 T:2689429408 M:1611259904   ERROR: unable to load /Users/dan/projects/xbmc-fork/build/Debug/Plex.app/Contents/MacOS/language/English/langinfo.xml: Failed to open file at line 0<br />
01:07:31 T:2689429408 M:1611255808   ERROR: unable to load /Users/dan/projects/xbmc-fork/build/Debug/Plex.app/Contents/MacOS/language/English/keyboardmap.xml: Failed to open file at line 0<br />
01:07:31 T:2689429408 M:1612075008   ERROR: Unable to load /Users/dan/projects/xbmc-fork/build/Debug/Plex.app/Contents/MacOS/system/ImageLib-osx.so, reason: dlopen(/Users/dan/projects/xbmc-fork/build/Debug/Plex.app/Contents/MacOS/system/ImageLib-osx.so, 1): image not found<br />
01:07:31 T:2689429408 M:1612075008   ERROR: Texture manager unable to load file: /Users/dan/projects/xbmc-fork/build/Debug/Plex.app/Contents/MacOS/media/splash.png<br />
01:07:33 T:2689429408 M:1607540736   ERROR: unable to load /Users/dan/projects/xbmc-fork/build/Debug/Plex.app/Contents/MacOS/language/English/strings.xml: Failed to open file at line 0<br />
01:07:33 T:2689429408 M:1607540736   ERROR: unable to load Q:\language\english\strings.xml: Failed to open file at line 0<br />
01:07:33 T:2689429408 M:1607540736 WARNING: Emergency recovery console starting...



I think it is just looking for files in the wrong place.

My code looks pretty similar to the XBMC branch - this is the updated code:


	  if( item->m_bIsFolder)<br />
	  {<br />
		// check for any dvd directories, only on known fast types<br />
		// i'm adding xbms even thou it really isn't fast due to<br />
		// opening file to check for existence<br />
		if( !item->IsRemote()<br />
		 || item->IsSmb()<br />
		 || CUtil::IsInRAR(item->m_strPath)<br />
		 || CUtil::IsInZIP(item->m_strPath)<br />
		 || item->m_strPath.Left(5).Equals("xbms", false)<br />
		 )<br />
		{<br />
		  CStdString path;<br />
					CStdString dvdPath="";<br />
		  CUtil::AddFileToFolder(item->m_strPath, "VIDEO_TS.IFO", path);<br />
		  if (CFile::Exists(path))<br />
		  {<br />
						dvdPath=path;<br />
					}<br />
					else<br />
					{<br />
						CUtil::AddFileToFolder(item->m_strPath, "VIDEO_TS", dvdPath);<br />
						CUtil::AddFileToFolder(dvdPath, "VIDEO_TS.IFO", path);<br />
						dvdPath.Empty();						<br />
			if (CFile::Exists(path))<br />
						{<br />
						  dvdPath=path;<br />
					  }	<br />
					}<br />
					if (!dvdPath.IsEmpty())<br />
					{<br />
			/* set the thumbnail based on folder */<br />
			item->SetCachedVideoThumb();<br />
			if (!item->HasThumbnail())<br />
			  item->SetUserVideoThumb();<br />
<br />
			item->m_bIsFolder = false;<br />
			item->m_strPath = dvdPath;<br />
			item->SetLabel2("");<br />
			item->SetLabelPreformated(true);<br />
			m_sortMethod = SORT_METHOD_NONE; /* sorting is now broken */<br />
<br />
			/* override the previously set thumb if video_ts.ifo has any */<br />
			/* otherwise user can't set icon on the stacked file as that */<br />
			/* will allways be set on the video_ts.ifo file */<br />
			CStdString thumb(item->GetCachedVideoThumb());<br />
			if(CFile::Exists(thumb))<br />
			  item->SetThumbnailImage(thumb);<br />
			else<br />
			  item->SetUserVideoThumb();<br />
<br />
		  }<br />
		}<br />
		continue;<br />
	  }

Crap, sorry, it’s now PLEX_HOME, and it goes to Plex.app/Contents/Resources/Plex.



I’ll include your code in the next (final?) RC, thanks a bunch for it!!!

I actually had to set XBMC_HOME to /Applications/Plex.app/Contents/Resources. I might not have the most up to date code or something.



I played around with check for stacking the TV shows and it seems to mess up TV Shows when stacking is on for non VIDEO_TS files. I’m not sure what exactly is happening yet, but the update to check for VIDEO_TS folders seems to work as expected. I think DVD rips are used for movies more often anyways. And if you don’t set a content type it works fine in file mode.




Awesome, I'm glad I can help out a little bit! Thanks and keep up the good work!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.