/
BlurayDirectory.cpp
185 lines (154 loc) · 5 KB
/
BlurayDirectory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "BlurayDirectory.h"
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "URL.h"
#include "DllLibbluray.h"
#include "FileItem.h"
#include "video/VideoInfoTag.h"
#include "guilib/LocalizeStrings.h"
namespace XFILE
{
#define MAIN_TITLE_LENGTH_PERCENT 70 /** Minumum length of main titles, based on longest title */
CBlurayDirectory::CBlurayDirectory()
: m_dll(NULL)
, m_bd(NULL)
{
}
CBlurayDirectory::~CBlurayDirectory()
{
Dispose();
}
void CBlurayDirectory::Dispose()
{
if(m_bd)
{
m_dll->bd_close(m_bd);
m_bd = NULL;
}
delete m_dll;
m_dll = NULL;
}
CFileItemPtr CBlurayDirectory::GetTitle(const BLURAY_TITLE_INFO* title, const CStdString& label)
{
CStdString buf;
CFileItemPtr item(new CFileItem("", false));
CURL path(m_url);
buf.Format("BDMV/PLAYLIST/%05d.mpls", title->playlist);
path.SetFileName(buf);
item->SetPath(path.Get());
item->GetVideoInfoTag()->m_strRuntime.Format("%d",title->duration / 90000);
item->GetVideoInfoTag()->m_iTrack = title->playlist;
buf.Format(label.c_str(), title->playlist);
item->m_strTitle = buf;
item->SetLabel(buf);
item->m_dwSize = 0;
item->SetIconImage("DefaultVideo.png");
for(unsigned int i = 0; i < title->clip_count; ++i)
item->m_dwSize += title->clips[i].pkt_count * 192;
return item;
}
void CBlurayDirectory::GetTitles(bool main, CFileItemList &items)
{
unsigned titles = m_dll->bd_get_titles(m_bd, TITLES_RELEVANT, 0);
CStdString buf;
std::vector<BLURAY_TITLE_INFO*> buffer;
uint64_t duration = 0;
for(unsigned i=0; i < titles; i++)
{
BLURAY_TITLE_INFO *t = m_dll->bd_get_title_info(m_bd, i, 0);
if(!t)
{
CLog::Log(LOGDEBUG, "CBlurayDirectory - unable to get title %d", i);
continue;
}
if(t->duration > duration)
duration = t->duration;
buffer.push_back(t);
}
if(main)
duration = duration * MAIN_TITLE_LENGTH_PERCENT / 100;
else
duration = 0;
for(std::vector<BLURAY_TITLE_INFO*>::iterator it = buffer.begin(); it != buffer.end(); ++it)
{
if((*it)->duration < duration)
continue;
items.Add(GetTitle(*it, main ? g_localizeStrings.Get(25004) /* Main Title */ : g_localizeStrings.Get(25005) /* Title */));
}
for(std::vector<BLURAY_TITLE_INFO*>::iterator it = buffer.begin(); it != buffer.end(); ++it)
m_dll->bd_free_title_info(*it);
}
void CBlurayDirectory::GetRoot(CFileItemList &items)
{
GetTitles(true, items);
CURL path(m_url);
CFileItemPtr item;
path.SetFileName(URIUtils::AddFileToFolder(m_url.GetFileName(), "titles"));
item.reset(new CFileItem());
item->SetPath(path.Get());
item->m_bIsFolder = true;
item->SetLabel(g_localizeStrings.Get(25002) /* All titles */);
item->SetIconImage("DefaultVideoPlaylists.png");
items.Add(item);
path.SetFileName("BDMV/MovieObject.bdmv");
item.reset(new CFileItem());
item->SetPath(path.Get());
item->m_bIsFolder = false;
item->SetLabel(g_localizeStrings.Get(25003) /* Menus */);
item->SetIconImage("DefaultProgram.png");
items.Add(item);
}
bool CBlurayDirectory::GetDirectory(const CStdString& path, CFileItemList &items)
{
Dispose();
m_url.Parse(path);
CStdString root = m_url.GetHostName();
CStdString file = m_url.GetFileName();
URIUtils::RemoveSlashAtEnd(file);
m_dll = new DllLibbluray();
if (!m_dll->Load())
{
CLog::Log(LOGERROR, "CBlurayDirectory::GetDirectory - failed to load dll");
return false;
}
m_dll->bd_register_dir(DllLibbluray::dir_open);
m_dll->bd_register_file(DllLibbluray::file_open);
m_dll->bd_set_debug_handler(DllLibbluray::bluray_logger);
m_dll->bd_set_debug_mask(DBG_CRIT | DBG_BLURAY | DBG_NAV);
m_bd = m_dll->bd_open(root.c_str(), NULL);
if(!m_bd)
{
CLog::Log(LOGERROR, "CBlurayDirectory::GetDirectory - failed to open %s", root.c_str());
return false;
}
if(file == "")
GetRoot(items);
else if(file == "titles")
GetTitles(false, items);
else
return false;
items.AddSortMethod(SORT_METHOD_TRACKNUM , 554, LABEL_MASKS("%L", "%D", "%L", "")); // FileName, Duration | Foldername, empty
items.AddSortMethod(SORT_METHOD_SIZE , 553, LABEL_MASKS("%L", "%I", "%L", "%I")); // FileName, Size | Foldername, Size
return true;
}
} /* namespace XFILE */