Skip to content
Browse files

Adds dates to HTTP directories.

This commit adds dates to directories and files listed from an HTTP
source and thus enables the user to sort them by date. It has been made
with Apache and Nginx autoindex modules in mind. There's also a small
change that enables XBMC to read the filesize from Nginx and it adds
the static method MonthStringToMonthNum() to CDateTime. CHTTPDirectory
uses this method to add dates to files/directories.
  • Loading branch information...
1 parent 95e613d commit a2e188cd0731dd54b422dacd75d37649c03cb397 dez-dk committed
Showing with 60 additions and 8 deletions.
  1. +12 −0 xbmc/XBDateTime.cpp
  2. +1 −0 xbmc/XBDateTime.h
  3. +47 −8 xbmc/filesystem/HTTPDirectory.cpp
View
12 xbmc/XBDateTime.cpp
@@ -1286,3 +1286,15 @@ CStdString CDateTime::GetAsRFC1123DateTime() const
result.Format("%s, %02i %s %04i %02i:%02i:%02i GMT", DAY_NAMES[time.GetDayOfWeek()], time.GetDay(), MONTH_NAMES[time.GetMonth()-1], time.GetYear(), time.GetHour(), time.GetMinute(), time.GetSecond());
return result;
}
+
+int CDateTime::MonthStringToMonthNum(const CStdString& month)
+{
+ const char* months[] = {"january","february","march","april","may","june","july","august","september","october","november","december"};
+ const char* abr_months[] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
+
+ int i = 0;
+ for (; i < 12 && month.CompareNoCase(months[i]) != 0 && month.CompareNoCase(abr_months[i]) != 0; i++);
+ i++;
+
+ return i;
+}
View
1 xbmc/XBDateTime.h
@@ -99,6 +99,7 @@ class CDateTime : public IArchivable
static CDateTime GetCurrentDateTime();
static CDateTime GetUTCDateTime();
+ static int MonthStringToMonthNum(const CStdString& month);
const CDateTime& operator =(const SYSTEMTIME& right);
const CDateTime& operator =(const FILETIME& right);
View
55 xbmc/filesystem/HTTPDirectory.cpp
@@ -54,6 +54,18 @@ bool CHTTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &item
CRegExp reItem(true); // HTML is case-insensitive
reItem.RegComp("<a href=\"(.*)\">(.*)</a>");
+ CRegExp reDateTime(true);
+ reDateTime.RegComp("<td align=\"right\">([0-9]{2})-([A-Z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}) +</td>");
+
+ CRegExp reDateTimeNginx(true);
+ reDateTimeNginx.RegComp("</a> +([0-9]{2})-([A-Z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}) ");
+
+ CRegExp reSize(true);
+ reSize.RegComp(">*([0-9.]+)(B|K|M|G| )</td>");
+
+ CRegExp reSizeNginx;
+ reSizeNginx.RegComp("([0-9]+)$");
+
/* read response from server into string buffer */
char buffer[MAX_PATH + 1024];
while(http.ReadString(buffer, sizeof(buffer)-1))
@@ -98,18 +110,32 @@ bool CHTTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &item
if(URIUtils::HasSlashAtEnd(pItem->GetPath()))
pItem->m_bIsFolder = true;
- if (!pItem->m_bIsFolder && g_advancedSettings.m_bHTTPDirectoryStatFilesize)
+ CStdString day, month, year, hour, minute;
+
+ if (reDateTime.RegFind(strBuffer.c_str()) >= 0)
{
- CFileCurl file;
- file.Open(url);
- pItem->m_dwSize= file.GetLength();
- file.Close();
+ day = reDateTime.GetReplaceString("\\1");
+ month = reDateTime.GetReplaceString("\\2");
+ year = reDateTime.GetReplaceString("\\3");
+ hour = reDateTime.GetReplaceString("\\4");
+ minute = reDateTime.GetReplaceString("\\5");
+ }
+ else if (reDateTimeNginx.RegFind(strBuffer.c_str()) >= 0)
+ {
+ day = reDateTimeNginx.GetReplaceString("\\1");
+ month = reDateTimeNginx.GetReplaceString("\\2");
+ year = reDateTimeNginx.GetReplaceString("\\3");
+ hour = reDateTimeNginx.GetReplaceString("\\4");
+ minute = reDateTimeNginx.GetReplaceString("\\5");
+ }
+
+ if (day.length() > 0 && month.length() > 0 && year.length() > 0)
+ {
+ pItem->m_dateTime = CDateTime(atoi(year.c_str()), CDateTime::MonthStringToMonthNum(month), atoi(day.c_str()), atoi(hour.c_str()), atoi(minute.c_str()), 0);
}
- if (!pItem->m_bIsFolder && pItem->m_dwSize == 0)
+ if (!pItem->m_bIsFolder)
{
- CRegExp reSize(true);
- reSize.RegComp(">*([0-9.]+)(B|K|M|G| )</td>");
if (reSize.RegFind(strBuffer.c_str()) >= 0)
{
double Size = atof(reSize.GetReplaceString("\\1"));
@@ -124,6 +150,19 @@ bool CHTTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &item
pItem->m_dwSize = (int64_t)Size;
}
+ else if (reSizeNginx.RegFind(strBuffer.c_str()) >= 0)
+ {
+ double Size = atof(reSizeNginx.GetReplaceString("\\1"));
+ pItem->m_dwSize = (int64_t)Size;
+ }
+ }
+
+ if (!pItem->m_bIsFolder && pItem->m_dwSize == 0 && g_advancedSettings.m_bHTTPDirectoryStatFilesize)
+ {
+ CFileCurl file;
+ file.Open(url);
+ pItem->m_dwSize= file.GetLength();
+ file.Close();
}
items.Add(pItem);

0 comments on commit a2e188c

Please sign in to comment.
Something went wrong with that request. Please try again.