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/>.
22 #include "BlurayDirectory.h"
23 #include "utils/log.h"
24 #include "utils/URIUtils.h"
25 #include "utils/StringUtils.h"
27 #include "DllLibbluray.h"
29 #include "video/VideoInfoTag.h"
30 #include "guilib/LocalizeStrings.h"
35 #define MAIN_TITLE_LENGTH_PERCENT 70 /** Minumum length of main titles, based on longest title */
37 CBlurayDirectory::CBlurayDirectory()
43 CBlurayDirectory::~CBlurayDirectory()
48 void CBlurayDirectory::Dispose()
52 m_dll->bd_close(m_bd);
59 CFileItemPtr CBlurayDirectory::GetTitle(const BLURAY_TITLE_INFO* title, const CStdString& label)
63 CFileItemPtr item(new CFileItem("", false));
65 buf = StringUtils::Format("BDMV/PLAYLIST/%05d.mpls", title->playlist);
66 path.SetFileName(buf);
67 item->SetPath(path.Get());
68 int duration = (int)(title->duration / 90000);
69 item->GetVideoInfoTag()->m_duration = duration;
70 item->GetVideoInfoTag()->m_iTrack = title->playlist;
71 buf = StringUtils::Format(label.c_str(), title->playlist);
72 item->m_strTitle = buf;
74 chap = StringUtils::Format(g_localizeStrings.Get(25007), title->chapter_count, StringUtils::SecondsToTimeString(duration).c_str());
75 item->SetProperty("Addon.Summary", chap);
77 item->SetIconImage("DefaultVideo.png");
78 for(unsigned int i = 0; i < title->clip_count; ++i)
79 item->m_dwSize += title->clips[i].pkt_count * 192;
84 void CBlurayDirectory::GetTitles(bool main, CFileItemList &items)
86 unsigned titles = m_dll->bd_get_titles(m_bd, TITLES_RELEVANT, 0);
89 std::vector<BLURAY_TITLE_INFO*> buffer;
91 uint64_t duration = 0;
93 for(unsigned i=0; i < titles; i++)
95 BLURAY_TITLE_INFO *t = m_dll->bd_get_title_info(m_bd, i, 0);
98 CLog::Log(LOGDEBUG, "CBlurayDirectory - unable to get title %d", i);
101 if(t->duration > duration)
102 duration = t->duration;
108 duration = duration * MAIN_TITLE_LENGTH_PERCENT / 100;
112 for(std::vector<BLURAY_TITLE_INFO*>::iterator it = buffer.begin(); it != buffer.end(); ++it)
114 if((*it)->duration < duration)
116 items.Add(GetTitle(*it, main ? g_localizeStrings.Get(25004) /* Main Title */ : g_localizeStrings.Get(25005) /* Title */));
120 for(std::vector<BLURAY_TITLE_INFO*>::iterator it = buffer.begin(); it != buffer.end(); ++it)
121 m_dll->bd_free_title_info(*it);
124 void CBlurayDirectory::GetRoot(CFileItemList &items)
126 GetTitles(true, items);
131 path.SetFileName(URIUtils::AddFileToFolder(m_url.GetFileName(), "titles"));
132 item.reset(new CFileItem());
133 item->SetPath(path.Get());
134 item->m_bIsFolder = true;
135 item->SetLabel(g_localizeStrings.Get(25002) /* All titles */);
136 item->SetIconImage("DefaultVideoPlaylists.png");
139 path.SetFileName("BDMV/MovieObject.bdmv");
140 item.reset(new CFileItem());
141 item->SetPath(path.Get());
142 item->m_bIsFolder = false;
143 item->SetLabel(g_localizeStrings.Get(25003) /* Menus */);
144 item->SetIconImage("DefaultProgram.png");
148 bool CBlurayDirectory::GetDirectory(const CStdString& path, CFileItemList &items)
152 CStdString root = m_url.GetHostName();
153 CStdString file = m_url.GetFileName();
154 URIUtils::RemoveSlashAtEnd(file);
155 URIUtils::RemoveSlashAtEnd(root);
157 m_dll = new DllLibbluray();
160 CLog::Log(LOGERROR, "CBlurayDirectory::GetDirectory - failed to load dll");
164 m_dll->bd_register_dir(DllLibbluray::dir_open);
165 m_dll->bd_register_file(DllLibbluray::file_open);
166 m_dll->bd_set_debug_handler(DllLibbluray::bluray_logger);
167 m_dll->bd_set_debug_mask(DBG_CRIT | DBG_BLURAY | DBG_NAV);
169 m_bd = m_dll->bd_open(root.c_str(), NULL);
173 CLog::Log(LOGERROR, "CBlurayDirectory::GetDirectory - failed to open %s", root.c_str());
179 else if(file == "titles")
180 GetTitles(false, items);
184 items.AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS("%L", "%D", "%L", "")); // FileName, Duration | Foldername, empty
185 items.AddSortMethod(SortBySize, 553, LABEL_MASKS("%L", "%I", "%L", "%I")); // FileName, Size | Foldername, Size
191 } /* namespace XFILE */