2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "BlurayDirectory.h"
22 #include "utils/log.h"
23 #include "utils/URIUtils.h"
24 #include "utils/StringUtils.h"
26 #include "DllLibbluray.h"
28 #include "video/VideoInfoTag.h"
29 #include "guilib/LocalizeStrings.h"
34 #define MAIN_TITLE_LENGTH_PERCENT 70 /** Minumum length of main titles, based on longest title */
36 CBlurayDirectory::CBlurayDirectory()
42 CBlurayDirectory::~CBlurayDirectory()
47 void CBlurayDirectory::Dispose()
51 m_dll->bd_close(m_bd);
58 CFileItemPtr CBlurayDirectory::GetTitle(const BLURAY_TITLE_INFO* title, const CStdString& label)
61 CFileItemPtr item(new CFileItem("", false));
63 buf = StringUtils::Format("BDMV/PLAYLIST/%05d.mpls", title->playlist);
64 path.SetFileName(buf);
65 item->SetPath(path.Get());
66 item->GetVideoInfoTag()->m_duration = (int)(title->duration / 90000);
67 item->GetVideoInfoTag()->m_iTrack = title->playlist;
68 buf = StringUtils::Format(label.c_str(), title->playlist);
69 item->m_strTitle = buf;
72 item->SetIconImage("DefaultVideo.png");
73 for(unsigned int i = 0; i < title->clip_count; ++i)
74 item->m_dwSize += title->clips[i].pkt_count * 192;
79 void CBlurayDirectory::GetTitles(bool main, CFileItemList &items)
81 unsigned titles = m_dll->bd_get_titles(m_bd, TITLES_RELEVANT, 0);
84 std::vector<BLURAY_TITLE_INFO*> buffer;
86 uint64_t duration = 0;
88 for(unsigned i=0; i < titles; i++)
90 BLURAY_TITLE_INFO *t = m_dll->bd_get_title_info(m_bd, i, 0);
93 CLog::Log(LOGDEBUG, "CBlurayDirectory - unable to get title %d", i);
96 if(t->duration > duration)
97 duration = t->duration;
103 duration = duration * MAIN_TITLE_LENGTH_PERCENT / 100;
107 for(std::vector<BLURAY_TITLE_INFO*>::iterator it = buffer.begin(); it != buffer.end(); ++it)
109 if((*it)->duration < duration)
111 items.Add(GetTitle(*it, main ? g_localizeStrings.Get(25004) /* Main Title */ : g_localizeStrings.Get(25005) /* Title */));
115 for(std::vector<BLURAY_TITLE_INFO*>::iterator it = buffer.begin(); it != buffer.end(); ++it)
116 m_dll->bd_free_title_info(*it);
119 void CBlurayDirectory::GetRoot(CFileItemList &items)
121 GetTitles(true, items);
126 path.SetFileName(URIUtils::AddFileToFolder(m_url.GetFileName(), "titles"));
127 item.reset(new CFileItem());
128 item->SetPath(path.Get());
129 item->m_bIsFolder = true;
130 item->SetLabel(g_localizeStrings.Get(25002) /* All titles */);
131 item->SetIconImage("DefaultVideoPlaylists.png");
134 path.SetFileName("BDMV/MovieObject.bdmv");
135 item.reset(new CFileItem());
136 item->SetPath(path.Get());
137 item->m_bIsFolder = false;
138 item->SetLabel(g_localizeStrings.Get(25003) /* Menus */);
139 item->SetIconImage("DefaultProgram.png");
143 bool CBlurayDirectory::GetDirectory(const CStdString& path, CFileItemList &items)
147 CStdString root = m_url.GetHostName();
148 CStdString file = m_url.GetFileName();
149 URIUtils::RemoveSlashAtEnd(file);
150 URIUtils::RemoveSlashAtEnd(root);
152 m_dll = new DllLibbluray();
155 CLog::Log(LOGERROR, "CBlurayDirectory::GetDirectory - failed to load dll");
159 m_dll->bd_register_dir(DllLibbluray::dir_open);
160 m_dll->bd_register_file(DllLibbluray::file_open);
161 m_dll->bd_set_debug_handler(DllLibbluray::bluray_logger);
162 m_dll->bd_set_debug_mask(DBG_CRIT | DBG_BLURAY | DBG_NAV);
164 m_bd = m_dll->bd_open(root.c_str(), NULL);
168 CLog::Log(LOGERROR, "CBlurayDirectory::GetDirectory - failed to open %s", root.c_str());
174 else if(file == "titles")
175 GetTitles(false, items);
179 items.AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS("%L", "%D", "%L", "")); // FileName, Duration | Foldername, empty
180 items.AddSortMethod(SortBySize, 553, LABEL_MASKS("%L", "%I", "%L", "%I")); // FileName, Size | Foldername, Size
186 } /* namespace XFILE */