added: Smartplaylists for tvshows and episodes. Needs decent testing + cleanup.
[xbmc:xbmc-antiquated.git] / xbmc / FileSystem / SmartPlaylistDirectory.cpp
1 #include "stdafx.h"
2 #include "SmartPlaylistDirectory.h"
3 #include "../utils/log.h"
4 #include "../SmartPlaylist.h"
5 #include "../MusicDatabase.h"
6 #include "../VideoDatabase.h"
7 #include "../Util.h"
8
9 using namespace PLAYLIST;
10
11 namespace DIRECTORY
12 {
13   CSmartPlaylistDirectory::CSmartPlaylistDirectory()
14   {
15   }
16
17   CSmartPlaylistDirectory::~CSmartPlaylistDirectory()
18   {
19   }
20
21   bool CSmartPlaylistDirectory::GetDirectory(const CStdString& strPath, CFileItemList& items)
22   {
23     // Load in the SmartPlaylist and get the WHERE query
24     CSmartPlaylist playlist;
25     if (!playlist.Load(strPath))
26       return false;
27     bool success = false, success2 = false;
28     if (playlist.GetType().Equals("tvshows"))
29     {
30       CVideoDatabase db;
31       db.Open();
32       CStdString whereOrder = playlist.GetWhereClause() + " " + playlist.GetOrderClause();
33       success = db.GetTvShowsByWhere("videodb://2/2/", whereOrder, items);
34       items.SetContent("tvshows");
35       db.Close();
36       return success;
37     }
38     else if (playlist.GetType().Equals("episodes"))
39     {
40       CVideoDatabase db;
41       db.Open();
42       CStdString whereOrder = playlist.GetWhereClause() + " " + playlist.GetOrderClause();
43       success = db.GetEpisodesByWhere("videodb://2/2/", whereOrder, items);
44       items.SetContent("episodes");
45       db.Close();
46       return success;
47     }
48     if (playlist.GetType().Equals("music") || playlist.GetType().Equals("mixed") || playlist.GetType().IsEmpty())
49     {
50       CMusicDatabase db;
51       db.Open();
52       CStdString type=playlist.GetType();
53       if (type.IsEmpty())
54         type = "music";
55       if (playlist.GetType().Equals("mixed"))
56         playlist.SetType("music");
57
58       CStdString whereOrder = playlist.GetWhereClause() + " " + playlist.GetOrderClause();
59       success = db.GetSongsByWhere("", whereOrder, items);
60       db.Close();
61       playlist.SetType(type);
62     }
63     if (playlist.GetType().Equals("video") || playlist.GetType().Equals("mixed"))
64     {
65       CVideoDatabase db;
66       db.Open();
67       CStdString type=playlist.GetType();
68       if (playlist.GetType().Equals("mixed"))
69         playlist.SetType("video");
70       CStdString whereOrder = playlist.GetWhereClause() + " " + playlist.GetOrderClause();
71       CFileItemList items2;
72       success2 = db.GetMusicVideosByWhere("videodb://3/2/", whereOrder, items2);
73       db.Close();
74       items.Append(items2);
75       playlist.SetType(type);
76     }
77     if (playlist.GetType().Equals("mixed"))
78       return success || success2;
79     else if (playlist.GetType().Equals("video"))
80       return success2;
81     else
82       return success;
83   }
84
85   bool CSmartPlaylistDirectory::ContainsFiles(const CStdString& strPath)
86   {
87     // smart playlists always have files??
88     return true;
89   }
90
91   CStdString CSmartPlaylistDirectory::GetPlaylistByName(const CStdString& name)
92   {
93     CFileItemList list;
94     if (CDirectory::GetDirectory("special://musicplaylists/", list, "*.xsp"))
95     {
96       for (int i = 0; i < list.Size(); i++)
97       {
98         CFileItem *item = list[i];
99         if (item->GetLabel().CompareNoCase(name) == 0)
100         { // found :)
101           return item->m_strPath;
102         } 
103       }
104     }
105     return "";
106   }
107 }
108
109