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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
|
#include "stdafx.h"
#include "GUIWindowVideoFiles.h"
#include "Util.h"
#include "Picture.h"
#include "Utils/IMDB.h"
#include "Utils/HTTP.h"
#include "GUIWindowVideoInfo.h"
#include "PlayListFactory.h"
#include "Application.h"
#include "NFOFile.h"
#include "PlayListPlayer.h"
#include "GUIPassword.h"
#include "GUIDialogContextMenu.h"
#include "GUIDialogMediaSource.h"
#include "GUIDialogContentSettings.h"
#include "FileSystem/StackDirectory.h"
#include "utils/RegExp.h"
using namespace XFILE;
using namespace PLAYLIST;
#define CONTROL_LIST 50
#define CONTROL_THUMBS 51
#define CONTROL_PLAY_DVD 6
#define CONTROL_STACK 7
#define CONTROL_BTNSCAN 8
#define CONTROL_IMDB 9
#define CONTROL_BTNPLAYLISTS 13
CGUIWindowVideoFiles::CGUIWindowVideoFiles()
: CGUIWindowVideoBase(WINDOW_VIDEO_FILES, "MyVideo.xml")
{
m_bIsScanning = false;
}
CGUIWindowVideoFiles::~CGUIWindowVideoFiles()
{
}
bool CGUIWindowVideoFiles::OnAction(const CAction &action)
{
if (action.wID == ACTION_SHOW_PLAYLIST)
{
OutputDebugString("activate guiwindowvideoplaylist!\n");
m_gWindowManager.ActivateWindow(WINDOW_VIDEO_PLAYLIST);
return true;
}
return CGUIWindowVideoBase::OnAction(action);
}
bool CGUIWindowVideoFiles::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_WINDOW_INIT:
{
// check for a passed destination path
CStdString strDestination = message.GetStringParam();
if (!strDestination.IsEmpty())
{
message.SetStringParam("");
g_stSettings.m_iVideoStartWindow = GetID();
CLog::Log(LOGINFO, "Attempting to quickpath to: %s", strDestination.c_str());
// reset directory path, as we have effectively cleared it here
m_history.ClearPathHistory();
}
// is this the first time accessing this window?
// a quickpath overrides the a default parameter
if (m_vecItems.m_strPath == "?" && strDestination.IsEmpty())
{
m_vecItems.m_strPath = strDestination = g_stSettings.m_szDefaultVideos;
CLog::Log(LOGINFO, "Attempting to default to: %s", strDestination.c_str());
}
// try to open the destination path
if (!strDestination.IsEmpty())
{
// open root
if (strDestination.Equals("$ROOT"))
{
m_vecItems.m_strPath = "";
CLog::Log(LOGINFO, " Success! Opening root listing.");
}
// open playlists location
else if (strDestination.Equals("$PLAYLISTS"))
{
m_vecItems.m_strPath = "special://videoplaylists/";
CLog::Log(LOGINFO, " Success! Opening destination path: %s", m_vecItems.m_strPath.c_str());
}
else
{
// default parameters if the jump fails
m_vecItems.m_strPath = "";
bool bIsBookmarkName = false;
SetupShares();
VECSHARES shares;
m_rootDir.GetShares(shares);
int iIndex = CUtil::GetMatchingShare(strDestination, shares, bIsBookmarkName);
if (iIndex > -1)
{
bool bDoStuff = true;
if (shares[iIndex].m_iHasLock == 2)
{
CFileItem item(shares[iIndex]);
if (!g_passwordManager.IsItemUnlocked(&item,"video"))
{
m_vecItems.m_strPath = ""; // no u don't
bDoStuff = false;
CLog::Log(LOGINFO, " Failure! Failed to unlock destination path: %s", strDestination.c_str());
}
}
// set current directory to matching share
if (bDoStuff)
{
if (bIsBookmarkName)
m_vecItems.m_strPath=shares[iIndex].strPath;
else
m_vecItems.m_strPath=strDestination;
CUtil::RemoveSlashAtEnd(m_vecItems.m_strPath);
CLog::Log(LOGINFO, " Success! Opened destination path: %s", strDestination.c_str());
}
}
else
{
CLog::Log(LOGERROR, " Failed! Destination parameter (%s) does not match a valid share!", strDestination.c_str());
}
}
SetHistoryForPath(m_vecItems.m_strPath);
}
return CGUIWindowVideoBase::OnMessage(message);
}
break;
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
//if (iControl == CONTROL_BTNSCAN)
//{
// OnScan();
// }
/*else*/ if (iControl == CONTROL_STACK)
{
// toggle between the following states:
// 0 : no stacking
// 1 : stacking
g_stSettings.m_iMyVideoStack++;
if (g_stSettings.m_iMyVideoStack > STACK_SIMPLE)
g_stSettings.m_iMyVideoStack = STACK_NONE;
if (g_stSettings.m_iMyVideoStack != STACK_NONE)
g_stSettings.m_bMyVideoCleanTitles = true;
else
g_stSettings.m_bMyVideoCleanTitles = false;
g_settings.Save();
UpdateButtons();
Update( m_vecItems.m_strPath );
}
else if (iControl == CONTROL_BTNPLAYLISTS)
{
if (!m_vecItems.m_strPath.Equals("special://videoplaylists/"))
{
CStdString strParent = m_vecItems.m_strPath;
UpdateButtons();
Update("special://videoplaylists/");
}
}
// list/thumb panel
else if (m_viewControl.HasControl(iControl))
{
int iItem = m_viewControl.GetSelectedItem();
int iAction = message.GetParam1();
const CFileItem* pItem = m_vecItems[iItem];
// use play button to add folders of items to temp playlist
if (iAction == ACTION_PLAYER_PLAY && pItem->m_bIsFolder && !pItem->IsParentFolder())
{
if (pItem->IsDVD())
return CAutorun::PlayDisc();
if (pItem->m_bIsShareOrDrive)
return false;
// if playback is paused or playback speed != 1, return
if (g_application.IsPlayingVideo())
{
if (g_application.m_pPlayer->IsPaused()) return false;
if (g_application.GetPlaySpeed() != 1) return false;
}
// not playing, or playback speed == 1
// queue folder or playlist into temp playlist and play
if ((pItem->m_bIsFolder && !pItem->IsParentFolder()) || pItem->IsPlayList())
PlayItem(iItem);
return true;
}
}
}
}
return CGUIWindowVideoBase::OnMessage(message);
}
void CGUIWindowVideoFiles::UpdateButtons()
{
CGUIWindowVideoBase::UpdateButtons();
const CGUIControl *stack = GetControl(CONTROL_STACK);
if (stack)
{
if (stack->GetControlType() == CGUIControl::GUICONTROL_RADIO)
{
SET_CONTROL_SELECTED(GetID(), CONTROL_STACK, g_stSettings.m_iMyVideoStack == STACK_SIMPLE);
SET_CONTROL_LABEL(CONTROL_STACK, 14000); // Stack
}
else
{
SET_CONTROL_LABEL(CONTROL_STACK, g_stSettings.m_iMyVideoStack + 14000);
}
}
}
bool CGUIWindowVideoFiles::GetDirectory(const CStdString &strDirectory, CFileItemList &items)
{
if (!CGUIWindowVideoBase::GetDirectory(strDirectory, items))
return false;
if (!items.IsStack() && g_stSettings.m_iMyVideoStack != STACK_NONE)
items.Stack();
return true;
}
void CGUIWindowVideoFiles::OnPrepareFileItems(CFileItemList &items)
{
CGUIWindowVideoBase::OnPrepareFileItems(items);
if (g_stSettings.m_bMyVideoCleanTitles)
items.CleanFileNames();
}
bool CGUIWindowVideoFiles::OnClick(int iItem)
{
if ( iItem < 0 || iItem >= (int)m_vecItems.Size() ) return true;
CFileItem* pItem = m_vecItems[iItem];
CStdString strExtension;
CUtil::GetExtension(pItem->m_strPath, strExtension);
if ( strcmpi(strExtension.c_str(), ".nfo") == 0) // WTF??
{
SScraperInfo info;
info.strPath = "imdb.xml";
info.strContent = "movies";
OnInfo(iItem,info);
return true;
}
return CGUIWindowVideoBase::OnClick(iItem);
}
bool CGUIWindowVideoFiles::OnPlayMedia(int iItem)
{
if ( iItem < 0 || iItem >= (int)m_vecItems.Size() ) return false;
CFileItem* pItem = m_vecItems[iItem];
if (pItem->IsDVD())
return CAutorun::PlayDisc();
if (pItem->m_bIsShareOrDrive)
return false;
if (pItem->m_strPath == "add" && pItem->GetLabel() == g_localizeStrings.Get(1026)) // 'add source button' in empty root
{
if (CGUIDialogMediaSource::ShowAndAddMediaSource("video"))
{
Update("");
return true;
}
return false;
}
else
{
AddFileToDatabase(pItem);
return CGUIWindowVideoBase::OnPlayMedia(iItem);
}
}
void CGUIWindowVideoFiles::OnInfo(int iItem, const SScraperInfo& info)
{
if ( iItem < 0 || iItem >= (int)m_vecItems.Size() ) return ;
bool bFolder(false);
CStdString strFolder = "";
int iSelectedItem = m_viewControl.GetSelectedItem();
CFileItem* pItem = m_vecItems[iItem];
CStdString strFile = pItem->m_strPath;
if (pItem->m_bIsFolder && pItem->IsParentFolder()) return ;
if (pItem->m_bIsShareOrDrive) // oh no u don't
return ;
if (pItem->m_bIsFolder)
{
// IMDB is done on a folder
// stack and then find first file in folder
bFolder = true;
CFileItemList vecitems;
GetStackedDirectory(pItem->m_strPath, vecitems);
bool bFoundFile(false);
for (int i = 0; i < (int)vecitems.Size(); ++i)
{
CFileItem *item = vecitems[i];
if (!item->m_bIsFolder)
{
if (item->IsVideo() && !item->IsNFO() && !item->IsPlayList() )
{
bFoundFile = true;
strFile = item->m_strPath;
break;
}
}
else
{ // check for a dvdfolder
if (item->GetLabel().CompareNoCase("VIDEO_TS") == 0)
{ // found a dvd folder - grab the main .ifo file
CUtil::AddFileToFolder(item->m_strPath, "VIDEO_TS.IFO", strFile);
if (CFile::Exists(strFile))
{
bFoundFile = true;
break;
}
}
// check for a "CD1" folder
if (item->GetLabel().CompareNoCase("CD1") == 0)
{
CFileItemList items;
GetStackedDirectory(item->m_strPath, items);
for (int i = 0; i < items.Size(); i++)
{
CFileItem *item = items[i];
if (!item->m_bIsFolder && item->IsVideo() && !item->IsNFO() && !item->IsPlayList() )
{
bFoundFile = true;
strFile = item->m_strPath;
break;
}
}
if (bFoundFile)
break;
}
}
}
if (!bFoundFile)
{
// no video file in this folder?
// then just lookup IMDB info and show it
ShowIMDB(pItem,info);
m_viewControl.SetSelectedItem(iSelectedItem);
return ;
}
}
// setup our item with the label and thumb information
CFileItem item(strFile, pItem->m_bIsFolder);
item.SetLabel(pItem->GetLabel());
// hack since our label sometimes contains extensions
if(!pItem->m_bIsFolder && !g_guiSettings.GetBool("filelists.hideextensions") && !pItem->IsLabelPreformated())
item.RemoveExtension();
item.SetCachedVideoThumb();
if (!item.HasThumbnail()) // inherit from the original item if it exists
item.SetThumbnailImage(pItem->GetThumbnailImage());
AddFileToDatabase(&item);
ShowIMDB(&item,info);
// apply any IMDb icon to our item
if (pItem->m_bIsFolder)
ApplyIMDBThumbToFolder(pItem->m_strPath, item.GetThumbnailImage());
Update(m_vecItems.m_strPath);
}
void CGUIWindowVideoFiles::AddFileToDatabase(const CFileItem* pItem)
{
if (!pItem->IsVideo()) return ;
if ( pItem->IsNFO()) return ;
if ( pItem->IsPlayList()) return ;
/* subtitles are assumed not to exist here, if we need it */
/* player should update this when it figures out if it has */
m_database.AddFile(pItem->m_strPath);
if (pItem->IsStack())
{ // get stacked items
// TODO: This should be removed as soon as we no longer need the individual
// files for saving settings etc.
vector<CStdString> movies;
GetStackedFiles(pItem->m_strPath, movies);
for (unsigned int i = 0; i < movies.size(); i++)
{
CFileItem item(movies[i], false);
m_database.AddFile(item.m_strPath);
}
}
}
void CGUIWindowVideoFiles::OnRetrieveVideoInfo(CFileItemList& items, const SScraperInfo& info, bool bDirNames)
{
CStdString strMovieName;
if (bDirNames)
{
strMovieName = items.m_strPath;
CUtil::RemoveSlashAtEnd(strMovieName);
strMovieName = CUtil::GetFileName(strMovieName);
}
if(m_dlgProgress)
{
m_dlgProgress->ShowProgressBar(true);
m_dlgProgress->SetPercentage(0);
}
// for every file found
for (int i = 0; i < (int)items.Size(); ++i)
{
g_application.ResetScreenSaver();
CFileItem* pItem = items[i];
// This code tests if we have a DVD folder
if (pItem->m_bIsFolder)
{ // test to see whether we have a DVD folder
CStdString dvdFile;
CUtil::AddFileToFolder(pItem->m_strPath, "VIDEO_TS.IFO", dvdFile);
if (!CFile::Exists(dvdFile))
{ // try <folder>/VIDEO_TS/VIDEO_TS.IFO
CStdString dvdFolder;
CUtil::AddFileToFolder(pItem->m_strPath, "VIDEO_TS", dvdFolder);
CUtil::AddFileToFolder(dvdFolder, "VIDEO_TS.IFO", dvdFile);
}
if (CFile::Exists(dvdFile))
{ // have a dvd folder, set the path to that item
// and make it a file - the code below will take care of the rest
// note that the label is the foldername (good to lookup on)
pItem->m_strPath = dvdFile;
pItem->m_bIsFolder = false;
pItem->SetLabelPreformated(true);
}
}
if (!pItem->m_bIsFolder)
{
if (pItem->IsVideo() && !pItem->IsNFO() && !pItem->IsPlayList() )
{
if (!bDirNames)
{
if(pItem->IsLabelPreformated())
strMovieName = pItem->GetLabel();
else
{
strMovieName = CUtil::GetFileName(pItem->m_strPath);
CUtil::RemoveExtension(strMovieName);
}
}
if (m_dlgProgress)
{
m_dlgProgress->SetHeading(189);
m_dlgProgress->SetLine(0, strMovieName);
m_dlgProgress->SetLine(1, "");
m_dlgProgress->SetPercentage(100*i / items.Size());
m_dlgProgress->Progress();
if (m_dlgProgress->IsCanceled()) return ;
}
AddFileToDatabase(pItem);
if (!m_database.HasMovieInfo(pItem->m_strPath))
{
// handle .nfo files
CStdString strNfoFile = GetnfoFile(pItem);
if ( !strNfoFile.IsEmpty() && info.strContent.Equals("movies") )
{
CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfoFile.c_str());
if ( CFile::Cache(strNfoFile, "Z:\\movie.nfo", NULL, NULL))
{
CNfoFile nfoReader;
if ( nfoReader.Create("Z:\\movie.nfo") == S_OK)
{
CIMDBUrl url;
url.m_strURL.push_back(nfoReader.m_strImDbUrl);
url.m_strURL.push_back(nfoReader.m_strImDbUrl+"/plotsummary");
//url.m_strURL.push_back(nfoReader.m_strImDbUrl);
CLog::Log(LOGDEBUG,"-- imdb url: %s", url.m_strURL[0].c_str());
url.m_strID = nfoReader.m_strImDbNr;
SScraperInfo info2(info);
info2.strPath = "imdb.xml"; // fallback to imdb scraper no matter what is configured
GetIMDBDetails(pItem, url, info2);
continue;
}
else
CLog::Log(LOGERROR,"Unable to find an imdb url in nfo file: %s", strNfoFile.c_str());
}
else
CLog::Log(LOGERROR,"Unable to cache nfo file: %s", strNfoFile.c_str());
}
// do IMDB lookup...
if (m_dlgProgress)
{
m_dlgProgress->SetHeading(197);
m_dlgProgress->SetLine(0, strMovieName);
m_dlgProgress->SetLine(1, "");
m_dlgProgress->Progress();
}
CIMDB IMDB;
IMDB_MOVIELIST movielist;
IMDB.SetScraperInfo(info);
if (IMDB.FindMovie(strMovieName, movielist, m_dlgProgress))
{
int iMoviesFound = movielist.size();
if (iMoviesFound > 0)
{
CIMDBUrl url = movielist[0];
// show dialog that we're downloading the movie info
if (m_dlgProgress)
{
m_dlgProgress->SetHeading(198);
m_dlgProgress->SetLine(0, strMovieName);
m_dlgProgress->SetLine(1, url.m_strTitle);
m_dlgProgress->Progress();
}
CUtil::ClearCache();
GetIMDBDetails(pItem, url, info);
}
}
}
}
}
}
if(m_dlgProgress)
m_dlgProgress->ShowProgressBar(false);
}
void CGUIWindowVideoFiles::OnScan(const CStdString& strPath, const SScraperInfo& info, int iDirNames, int iScanRecursively)
{
// GetStackedDirectory() now sets and restores the stack state!
SScanSettings settings = {};
if(iDirNames>0)
{
settings.parent_name = true;
settings.recurse = 1; /* atleast one, otherwise this makes no sence */
}
else if (info.strContent.Equals("movies") && iDirNames == -1)
{
bool bCanceled;
if (!CGUIDialogYesNo::ShowAndGetInput(13346,20332,-1,-1,20334,20331,bCanceled))
{
settings.parent_name = true;
settings.recurse = 1; /* atleast one, otherwise this makes no sence */
}
if (bCanceled)
return;
}
if(iScanRecursively > 0)
settings.recurse = INT_MAX;
else if (iScanRecursively == -1)
{
bool bCanceled;
if( CGUIDialogYesNo::ShowAndGetInput(13346,20335,-1,-1,bCanceled) )
settings.recurse = INT_MAX;
if (bCanceled)
return;
}
if (m_dlgProgress)
{
m_dlgProgress->SetHeading(189);
m_dlgProgress->SetLine(0, "");
m_dlgProgress->SetLine(1, "");
m_dlgProgress->SetLine(2, "" );
m_dlgProgress->StartModal();
}
CFileItemList items;
GetStackedDirectory(strPath, items);
m_database.SetScraperForPath(strPath,info.strPath,info.strContent);
DoScan(items, info, settings);
CUtil::DeleteVideoDatabaseDirectoryCache();
if (m_dlgProgress)
m_dlgProgress->Close();
Update(m_vecItems.m_strPath);
}
void CGUIWindowVideoFiles::OnUnAssignContent(int iItem)
{
bool bCanceled;
if (CGUIDialogYesNo::ShowAndGetInput(20338,20340,20341,20022,bCanceled))
{
m_database.RemoveContentForPath(m_vecItems[iItem]->m_strPath);
CUtil::DeleteVideoDatabaseDirectoryCache();
}
else
{
if (!bCanceled)
{
m_database.SetScraperForPath(m_vecItems[iItem]->m_strPath,"","");
}
}
}
void CGUIWindowVideoFiles::OnAssignContent(int iItem, int iFound, SScraperInfo& info)
{
bool bScan=false, bScanRecursive=true, bUseDirNames=false;
if (iFound == 0)
{
m_database.GetScraperForPath(m_vecItems[iItem]->m_strPath,info.strPath,info.strContent);
}
SScraperInfo info2 = info;
if (CGUIDialogContentSettings::Show(info2,bScan,bScanRecursive,bUseDirNames))
{
if (info2.strContent.IsEmpty())
{
if (!info.strContent.IsEmpty())
OnUnAssignContent(iItem);
return;
}
m_database.SetScraperForPath(m_vecItems[iItem]->m_strPath,info2.strPath,info2.strContent);
if (bScan)
OnScan(m_vecItems[iItem]->m_strPath,info2,bUseDirNames?1:0,bScanRecursive?1:0);
}
/* if (item.GetLabel().Equals(g_localizeStrings.Get(20336)))
{
if (CGUIDialogYesNo::ShowAndGetInput(13346,20342,20343,-1))
OnScan(m_vecItems[iItem]->m_strPath,scrapers[strLabel][iDummy].second,strLabel);
else
m_database.SetScraperForPath(m_vecItems[iItem]->m_strPath,scrapers[strLabel][iDummy].second,strLabel);
}
else if (item.GetLabel().Equals(g_localizeStrings.Get(20337)))
{
items.Clear();
CUtil::GetRecursiveListing(m_vecItems[iItem]->m_strPath,items,g_stSettings.m_videoExtensions);
// enumerate
std::vector<CStdString> expression;
expression.push_back("[^\\.\\-_ ]*[\\.\\-_\\[ ]*[Ss]?([0-9]*)[^0-9]*[Ee]?([0-9]*)"); // foo.s01.e01, foo.1x09.avi
expression.push_back("[^\\.\\-_ ]*[^\\.\\-_ ]([0-9])([0-9]*)"); // foo.103*
std::map<int,std::vector<std::pair<int,CStdString> > > episodes;
for (int i=0;i<items.Size();++i)
{
if (items[i]->m_bIsFolder)
continue;
for (unsigned int j=0;j<expression.size();++j)
{
CRegExp reg;
if (!reg.RegComp(expression[j]))
break;
CLog::DebugLog("label: %s",items[i]->GetLabel().c_str());
if (reg.RegFind(items[i]->GetLabel().c_str()) > -1)
{
char* season = reg.GetReplaceString("\\1");
char* episode = reg.GetReplaceString("\\2");
if (season && episode)
{
int iSeason = atoi(season);
int iEpisode = atoi(episode);
std::map<int,std::vector<std::pair<int,CStdString> > >::iterator iter = episodes.find(iSeason);
if (iter == episodes.end()) // none from this season - add to map
{
std::vector<std::pair<int,CStdString> > vec;
vec.push_back(std::make_pair<int,CStdString>(iEpisode,items[i]->m_strPath));
episodes.insert(std::make_pair<int,std::vector<std::pair<int,CStdString> > >(iSeason,vec));
}
else
{
iter->second.push_back(std::make_pair<int,CStdString>(iEpisode,items[i]->m_strPath));
}
break;
}
}
}
}
}*/
}
bool CGUIWindowVideoFiles::DoScan(CFileItemList& items, const SScraperInfo& info, const SScanSettings &settings, int depth)
{
// remove username + password from strPath for display in Dialog
CURL url(items.m_strPath);
CStdString strStrippedPath;
url.GetURLWithoutUserDetails(strStrippedPath);
bool bCancel = false;
if (m_dlgProgress)
{
m_dlgProgress->SetLine(2, strStrippedPath );
if (m_dlgProgress->IsCanceled())
{
bCancel = true;
}
}
if(depth > 0)
OnRetrieveVideoInfo(items,info,settings.parent_name);
else
OnRetrieveVideoInfo(items,info,settings.parent_name_root);
if (!bCancel && settings.recurse > depth)
{
for (int i = 0; i < (int)items.Size(); ++i)
{
CFileItem *pItem = items[i];
if (m_dlgProgress)
{
if (m_dlgProgress->IsCanceled())
{
bCancel = true;
break;
}
}
if ( pItem->m_bIsFolder )
{
if (!pItem->IsParentFolder() && pItem->GetLabel().CompareNoCase("sample") != 0)
{
// load subfolder
CFileItemList subDirItems;
GetStackedDirectory(pItem->m_strPath, subDirItems);
if (!DoScan(subDirItems, info, settings, depth+1))
{
bCancel = true;
}
if (bCancel) break;
}
}
}
}
return !bCancel;
}
void CGUIWindowVideoFiles::GetStackedDirectory(const CStdString &strPath, CFileItemList &items)
{
items.Clear();
m_rootDir.GetDirectory(strPath, items);
// force stacking to be enabled
// save stack state
int iStack = g_stSettings.m_iMyVideoStack;
g_stSettings.m_iMyVideoStack = STACK_SIMPLE;
/*bool bUnroll = m_guiState->UnrollArchives();
g_guiSettings.SetBool("filelists.unrollarchives",true);*/
items.Stack();
// restore stack
g_stSettings.m_iMyVideoStack = iStack;
//g_guiSettings.SetBool("VideoFiles.FileLists",bUnroll);
}
void CGUIWindowVideoFiles::LoadPlayList(const CStdString& strPlayList)
{
// load a playlist like .m3u, .pls
// first get correct factory to load playlist
auto_ptr<CPlayList> pPlayList (CPlayListFactory::Create(strPlayList));
if ( NULL != pPlayList.get())
{
// load it
if (!pPlayList->Load(strPlayList))
{
CGUIDialogOK::ShowAndGetInput(6, 0, 477, 0);
return ; //hmmm unable to load playlist?
}
}
int iSize = pPlayList->size();
if (g_application.ProcessAndStartPlaylist(strPlayList, *pPlayList, PLAYLIST_VIDEO))
{
if (m_guiState.get())
m_guiState->SetPlaylistDirectory("playlistvideo://");
// activate the playlist window if its not activated yet
if (GetID() == m_gWindowManager.GetActiveWindow() && iSize > 1)
{
m_gWindowManager.ActivateWindow(WINDOW_VIDEO_PLAYLIST);
}
}
}
void CGUIWindowVideoFiles::OnPopupMenu(int iItem, bool bContextDriven /* = true */)
{
// calculate our position
float posX = 200;
float posY = 100;
const CGUIControl *pList = GetControl(CONTROL_LIST);
if (pList)
{
posX = pList->GetXPosition() + pList->GetWidth() / 2;
posY = pList->GetYPosition() + pList->GetHeight() / 2;
}
if ( m_vecItems.IsVirtualDirectoryRoot() )
{
if (iItem < 0)
{ // TODO: We should add the option here for shares to be added if there aren't any
return ;
}
// mark the item
m_vecItems[iItem]->Select(true);
// and do the popup menu
if (CGUIDialogContextMenu::BookmarksMenu("video", m_vecItems[iItem], posX, posY))
{
Update(m_vecItems.m_strPath);
return ;
}
m_vecItems[iItem]->Select(false);
return ;
}
CGUIWindowVideoBase::OnPopupMenu(iItem, bContextDriven);
}
void CGUIWindowVideoFiles::GetIMDBDetails(CFileItem *pItem, CIMDBUrl &url, const SScraperInfo& info)
{
CIMDB IMDB;
CIMDBMovie movieDetails;
IMDB.SetScraperInfo(info);
movieDetails.m_strSearchString = pItem->m_strPath;
if ( IMDB.GetDetails(url, movieDetails, m_dlgProgress) )
{
// add to all movies in the stacked set
m_database.SetMovieInfo(pItem->m_strPath, movieDetails);
// get & save thumbnail
CStdString strThumb = "";
CStdString strImage = movieDetails.m_strPictureURL;
if (strImage.size() > 0 && movieDetails.m_strSearchString.size() > 0)
{
// check for a cached thumb or user thumb
pItem->SetVideoThumb();
if (pItem->HasThumbnail())
return;
strThumb = pItem->GetCachedVideoThumb();
CStdString strExtension;
CUtil::GetExtension(strImage, strExtension);
CStdString strTemp = "Z:\\temp";
strTemp += strExtension;
::DeleteFile(strTemp.c_str());
if (m_dlgProgress)
{
m_dlgProgress->SetLine(2, 415);
m_dlgProgress->Progress();
}
CHTTP http;
http.Download(strImage, strTemp);
try
{
CPicture picture;
picture.DoCreateThumbnail(strTemp, strThumb);
}
catch (...)
{
CLog::Log(LOGERROR,"Could not make imdb thumb from %s", strImage.c_str());
::DeleteFile(strThumb.c_str());
}
::DeleteFile(strTemp.c_str());
}
}
}
void CGUIWindowVideoFiles::OnQueueItem(int iItem)
{
CGUIWindowVideoBase::OnQueueItem(iItem);
}
|