Ticket #9265: backendvideoscan.diff
File backendvideoscan.diff, 18.1 KB (added by , 14 years ago) |
---|
-
libs/libmyth/mythcommandlineparser.cpp
34 34 setverbose(false), 35 35 resched(false), 36 36 nosched(false), 37 scanvideos(false), 37 38 noupnp(false), 38 39 nojobqueue(false), 39 40 nohousekeeper(false), … … 238 239 nosched = true; 239 240 return true; 240 241 } 242 else if ((parseTypes && kCLPReschedule) && 243 !strcmp(argv[argpos],"--scanvideos")) 244 { 245 scanvideos = true; 246 return true; 247 } 241 248 else if ((parseTypes && kCLPNoUPnP) && 242 249 !strcmp(argv[argpos],"--noupnp")) 243 250 { … … 836 843 << "Do not perform any scheduling" << endl; 837 844 } 838 845 846 if (parseTypes & kCLPScanVideos) 847 { 848 msg << "--scanvideos " 849 << "Scan for new video content" << endl; 850 } 851 839 852 if (parseTypes & kCLPNoUPnP) 840 853 { 841 854 msg << "--noupnp " -
libs/libmyth/mythcommandlineparser.h
44 44 kCLPStartTime = 0x0080000000ULL, 45 45 kCLPPrintExpire = 0x0100000000ULL, 46 46 kCLPGeneratePreview = 0x0200000000ULL, 47 kCLPScanVideos = 0x0400000000ULL, 47 48 } ParseType; 48 49 49 50 class MPUBLIC MythCommandLineParser … … 87 88 88 89 bool SetVerbose(void) const { return setverbose; } 89 90 bool Reschedule(void) const { return resched; } 91 bool ScanVideos(void) const { return scanvideos; } 90 92 bool ClearSettingsCache(void) const { return clearsettingscache; } 91 93 bool WantUPnPRebuild(void) const { return wantupnprebuild; } 92 94 … … 101 103 !eventString.isEmpty() || wantupnprebuild || 102 104 setverbose || clearsettingscache || 103 105 printsched || testsched || 104 resched || !printexpire.isEmpty(); 106 resched || scanvideos || 107 !printexpire.isEmpty(); 105 108 } 106 109 107 110 bool WantsToExit(void) const { return wantsToExit; } … … 137 140 bool setverbose; 138 141 bool resched; 139 142 bool nosched; 143 bool scanvideos; 140 144 bool noupnp; 141 145 bool nojobqueue; 142 146 bool nohousekeeper; -
libs/libmythmetadata/videometadata.cpp
7 7 8 8 #include "mythcontext.h" 9 9 #include "mythdb.h" 10 #include "storagegroup.h" 10 11 #include "remotefile.h" 11 12 #include "remoteutil.h" 12 13 #include "util.h" … … 942 943 QString VideoMetadata::VideoFileHash(const QString &file_name, 943 944 const QString &host) 944 945 { 945 if (!host.isEmpty() )946 if (!host.isEmpty() && !isHostMaster(host)) 946 947 { 947 948 QString url = generate_file_url("Videos", host, file_name); 948 949 return RemoteFile::GetFileHash(url); 949 950 } 951 else if (!host.isEmpty()) 952 { 953 StorageGroup sgroup("Videos", host); 954 QString fullname = sgroup.FindRecordingFile(file_name); 955 return FileHash(fullname); 956 } 950 957 else 951 958 return FileHash(file_name); 952 959 } -
libs/libmythmetadata/videoscan.cpp
81 81 VideoMetadataListManager::metadata_list ml; 82 82 VideoMetadataListManager::loadAllFromDatabase(ml); 83 83 m_dbmetadata->setList(ml); 84 84 m_HasGUI = gCoreContext->HasGUI(); 85 85 m_ListUnknown = gCoreContext->GetNumSetting("VideoListUnknownFiletypes", 0); 86 86 } 87 87 … … 100 100 imageExtensions.push_back(QString(*p)); 101 101 } 102 102 103 VERBOSE(VB_GENERAL, QString("Beginning Video Scan.")); 104 103 105 uint counter = 0; 104 106 FileCheckList fs_files; 105 107 failedSGHosts.clear(); 106 108 107 SendProgressEvent(counter, (uint)m_directories.size(), 108 tr("Searching for video files")); 109 if (m_HasGUI) 110 SendProgressEvent(counter, (uint)m_directories.size(), 111 tr("Searching for video files")); 109 112 for (QStringList::const_iterator iter = m_directories.begin(); 110 113 iter != m_directories.end(); ++iter) 111 114 { … … 122 125 VERBOSE(VB_GENERAL, QString("Failed to scan :%1:").arg(*iter)); 123 126 } 124 127 } 125 126 SendProgressEvent(++counter);128 if (m_HasGUI) 129 SendProgressEvent(++counter); 127 130 } 128 131 129 132 PurgeList db_remove; … … 184 187 int counter = 0; 185 188 FileCheckList::iterator iter; 186 189 187 SendProgressEvent(counter, (uint)m_dbmetadata->getList().size(), 188 tr("Verifying video files")); 190 if (m_HasGUI) 191 SendProgressEvent(counter, (uint)m_dbmetadata->getList().size(), 192 tr("Verifying video files")); 189 193 190 194 // For every file we know about, check to see if it still exists. 191 195 for (VideoMetadataListManager::metadata_list::const_iterator p = … … 223 227 } 224 228 } 225 229 } 226 227 SendProgressEvent(++counter);230 if (m_HasGUI) 231 SendProgressEvent(++counter); 228 232 } 229 233 } 230 234 … … 234 238 int ret = 0; 235 239 uint counter = 0; 236 240 QList<int> preservelist; 237 SendProgressEvent(counter, (uint)(add.size() + remove.size()), 238 tr("Updating video database")); 241 if (m_HasGUI) 242 SendProgressEvent(counter, (uint)(add.size() + remove.size()), 243 tr("Updating video database")); 239 244 240 245 for (FileCheckList::const_iterator p = add.begin(); p != add.end(); ++p) 241 246 { … … 289 294 } 290 295 ret += 1; 291 296 } 292 SendProgressEvent(++counter); 297 if (m_HasGUI) 298 SendProgressEvent(++counter); 293 299 } 294 300 295 301 // When prompting is restored, account for the answer here. … … 299 305 { 300 306 if (!preservelist.contains(p->first)) 301 307 removeOrphans(p->first, p->second); 302 SendProgressEvent(++counter); 308 if (m_HasGUI) 309 SendProgressEvent(++counter); 303 310 } 304 311 305 312 return ret; … … 332 339 bool m_ListUnknown; 333 340 bool m_RemoveAll; 334 341 bool m_KeepAll; 342 bool m_HasGUI; 335 343 QStringList m_directories; 336 344 QStringList failedSGHosts; 337 345 … … 357 365 if (m_scanThread->isRunning()) 358 366 return; 359 367 360 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 368 if (gCoreContext->HasGUI()) 369 { 370 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 361 371 362 MythUIProgressDialog *progressDlg = new MythUIProgressDialog("",363 popupStack, "videoscanprogressdialog");372 MythUIProgressDialog *progressDlg = new MythUIProgressDialog("", 373 popupStack, "videoscanprogressdialog"); 364 374 365 if (progressDlg->Create()) 366 { 367 popupStack->AddScreen(progressDlg, false); 368 connect(m_scanThread, SIGNAL(finished()), 369 progressDlg, SLOT(Close())); 370 connect(m_scanThread, SIGNAL(finished()), 371 SLOT(finishedScan())); 375 if (progressDlg->Create()) 376 { 377 popupStack->AddScreen(progressDlg, false); 378 connect(m_scanThread, SIGNAL(finished()), 379 progressDlg, SLOT(Close())); 380 connect(m_scanThread, SIGNAL(finished()), 381 SLOT(finishedScan())); 382 } 383 else 384 { 385 delete progressDlg; 386 progressDlg = NULL; 387 } 388 m_scanThread->SetProgressDialog(progressDlg); 372 389 } 373 else374 {375 delete progressDlg;376 progressDlg = NULL;377 }378 390 379 391 m_scanThread->SetDirs(dirs); 380 m_scanThread->SetProgressDialog(progressDlg);381 392 m_scanThread->start(); 382 393 } 383 394 -
libs/libmythmetadata/videoscan.h
26 26 27 27 private: 28 28 class VideoScannerThread *m_scanThread; 29 bool m_cancel;29 bool m_cancel; 30 30 }; 31 31 32 32 #endif -
libs/libmythmetadata/dirscan.cpp
9 9 #include "mythcontext.h" 10 10 #include "mythverbose.h" 11 11 #include "videoutils.h" 12 #include "storagegroup.h" 12 13 13 14 DirectoryHandler::~DirectoryHandler() 14 15 { … … 111 112 112 113 bool scan_sg_dir(const QString &start_path, const QString &host, 113 114 const QString &base_path, DirectoryHandler *handler, 114 const ext_lookup &ext_settings)115 const ext_lookup &ext_settings, bool isMaster = false) 115 116 { 116 117 QString path = start_path; 117 118 … … 125 126 path = ""; 126 127 127 128 QStringList list; 128 bool ok = RemoteGetFileList(host, start_path, &list, "Videos");129 bool ok = false; 129 130 130 if ( !ok || list.at(0).startsWith("SLAVE UNREACHABLE"))131 if (isMaster) 131 132 { 133 StorageGroup sg("Videos", host); 134 list = sg.GetFileInfoList(start_path); 135 ok = true; 136 } 137 else 138 ok = RemoteGetFileList(host, start_path, &list, "Videos"); 139 140 if (!ok || (!list.isEmpty() && list.at(0).startsWith("SLAVE UNREACHABLE"))) 141 { 132 142 VERBOSE(VB_GENERAL, QString("Backend : %1 : Is currently Unreachable. Skipping this one.") 133 143 .arg(host)); 134 144 return false; 135 145 } 136 146 137 if ((!list.size()) || (list.at(0) == "EMPTY LIST")) 147 if ((!list.size()) || (list.at(0) == "EMPTY LIST")) 138 148 return true; 139 149 140 150 for (QStringList::iterator p = list.begin(); p != list.end(); ++p) … … 164 174 // so ignore the results and continue. As long as we reached it once 165 175 // to make it this far than we know he SG/Path exists 166 176 (void) scan_sg_dir(start_path + "/" + fileName, host, base_path, 167 dh, ext_settings );177 dh, ext_settings, isMaster); 168 178 } 169 179 else 170 180 { … … 231 241 QString host = sgurl.host(); 232 242 QString path = sgurl.path(); 233 243 234 if (!scan_sg_dir(path, host, path, handler, extlookup ))244 if (!scan_sg_dir(path, host, path, handler, extlookup, isHostMaster(host))) 235 245 { 236 246 VERBOSE(VB_GENERAL, QString("MythVideo::ScanVideoDirectory failed to scan %1 ").arg(host)); 237 247 pathScanned = false; -
libs/libmythmetadata/videoutils.cpp
241 241 ret = "no"; 242 242 return ret; 243 243 } 244 245 bool isHostMaster(const QString &host) 246 { 247 bool isMaster = false; 248 QString masterIP = gCoreContext->GetSetting("MasterServerIP"); 249 QString hostIP; 250 251 MSqlQuery query(MSqlQuery::InitCon()); 252 query.prepare("SELECT data FROM settings WHERE " 253 "value = 'BackendServerIP' AND " 254 "hostname = :HOSTNAME;"); 255 query.bindValue(":HOSTNAME", host); 256 257 if (query.exec() && query.next()) 258 { 259 hostIP = query.value(0).toString(); 260 if (hostIP == masterIP) 261 isMaster = true; 262 } 263 264 return isMaster; 265 } -
libs/libmythmetadata/videoutils.h
51 51 MPUBLIC QString ParentalLevelToState(const ParentalLevel &level); 52 52 MPUBLIC QString WatchedToState(bool watched); 53 53 54 MPUBLIC bool isHostMaster(const QString &host); 55 54 56 // this needs to be an inline and pull in the storage group and context 55 57 // headers since it this used in dbcheck.cpp. 56 58 #include <storagegroup.h> -
programs/programs-libs.pro
1 1 INCLUDEPATH += ../.. ../../libs/ ../../libs/libmyth ../../libs/libmythtv 2 2 INCLUDEPATH += ../../external/FFmpeg 3 INCLUDEPATH += ../../libs/libmythupnp ../../libs/libmythui 3 INCLUDEPATH += ../../libs/libmythupnp ../../libs/libmythui ../../libs/libmythmetadata 4 4 INCLUDEPATH += ../../libs/libmythlivemedia ../../libs/libmythdb ../../libmythhdhomerun 5 5 INCLUDEPATH += ../../libs/libmythdvdnav ../../libs/libmythbluray ../../libs/libmythsamplerate 6 6 … … 13 13 LIBS += -L../../libs/libmythdb 14 14 LIBS += -L../../libs/libmythui 15 15 LIBS += -L../../libs/libmythupnp 16 LIBS += -L../../libs/libmythmetdata 16 17 17 18 LIBS += -lmythtv-$$LIBVERSION 18 19 LIBS += -lmythswscale … … 24 25 LIBS += -lmythdb-$$LIBVERSION 25 26 LIBS += -lmythui-$$LIBVERSION 26 27 LIBS += -lmyth-$$LIBVERSION 28 LIBS += -lmythmetadata-$$LIBVERSION 27 29 28 30 using_live:LIBS += -L../../libs/libmythlivemedia -lmythlivemedia-$$LIBVERSION 29 31 using_mheg:LIBS += -L../../libs/libmythfreemheg -lmythfreemheg-$$LIBVERSION -
programs/mythbackend/mainserver.h
28 28 class ProcessRequestThread; 29 29 class QUrl; 30 30 class MythServer; 31 class VideoScanner; 31 32 class QTimer; 32 33 33 34 class MainServer : public QObject, public MythSocketCBs … … 66 67 void reconnectTimeout(void); 67 68 void deferredDeleteSlot(void); 68 69 void autoexpireUpdate(void); 70 void finishVideoScan(bool changed); 69 71 70 72 private slots: 71 73 void newConnection(MythSocket *); … … 158 160 void HandleSetBookmark(QStringList &tokens, PlaybackSock *pbs); 159 161 void HandleSettingQuery(QStringList &tokens, PlaybackSock *pbs); 160 162 void HandleSetSetting(QStringList &tokens, PlaybackSock *pbs); 163 void HandleScanVideos(PlaybackSock *pbs); 161 164 void HandleVersion(MythSocket *socket, const QStringList &slist); 162 165 void HandleBackendRefresh(MythSocket *socket); 163 166 void HandleQueryLoad(PlaybackSock *pbs); … … 209 212 QMap<int, EncoderLink *> *encoderList; 210 213 211 214 MythServer *mythserver; 215 VideoScanner *videoscanner; 212 216 213 217 QReadWriteLock sockListLock; 214 218 vector<PlaybackSock *> playbackList; -
programs/mythbackend/main.cpp
81 81 kCLPTestSchedule | 82 82 kCLPReschedule | 83 83 kCLPNoSchedule | 84 kCLPScanVideos | 84 85 kCLPNoUPnP | 85 86 kCLPUPnPRebuild | 86 87 kCLPNoJobqueue | -
programs/mythbackend/main_helpers.cpp
511 511 return (ok) ? BACKEND_EXIT_OK : BACKEND_EXIT_NO_CONNECT; 512 512 } 513 513 514 if (cmdline.ScanVideos()) 515 { 516 bool ok = false; 517 if (gCoreContext->ConnectToMasterServer()) 518 { 519 RemoteSendMessage("SCAN_VIDEOS"); 520 VERBOSE(VB_IMPORTANT, "Requested video scan"); 521 ok = true; 522 } 523 else 524 VERBOSE(VB_IMPORTANT, "Cannot connect to master for video scan"); 525 526 return (ok) ? BACKEND_EXIT_OK : BACKEND_EXIT_NO_CONNECT; 527 } 528 514 529 if (!cmdline.GetPrintExpire().isEmpty()) 515 530 { 516 531 expirer = new AutoExpire(); -
programs/mythbackend/mainserver.cpp
64 64 #include "mythcoreutil.h" 65 65 #include "mythdirs.h" 66 66 #include "mythdownloadmanager.h" 67 #include "videoscan.h" 68 #include "videoutils.h" 67 69 68 69 70 /** Milliseconds to wait for an existing thread from 70 71 * process request thread pool. 71 72 */ … … 645 646 else 646 647 HandleSetSetting(tokens, pbs); 647 648 } 649 else if (command == "SCAN_VIDEOS") 650 { 651 HandleScanVideos(pbs); 652 } 648 653 else if (command == "ALLOW_SHUTDOWN") 649 654 { 650 655 if (tokens.size() != 1) … … 2182 2187 return ok; 2183 2188 } 2184 2189 2190 void MainServer::finishVideoScan(bool changed) 2191 { 2192 if (changed) 2193 VERBOSE(VB_FILE, QString("Video scan completed, new entries added")); 2194 delete videoscanner; 2195 videoscanner = NULL; 2196 2197 } 2198 2185 2199 void MainServer::HandleCheckRecordingActive(QStringList &slist, 2186 2200 PlaybackSock *pbs) 2187 2201 { … … 4798 4812 return; 4799 4813 } 4800 4814 4815 void MainServer::HandleScanVideos(PlaybackSock *pbs) 4816 { 4817 MythSocket *pbssock = pbs->getSocket(); 4818 4819 QStringList retlist; 4820 4821 videoscanner = new VideoScanner(); 4822 4823 if (videoscanner) 4824 { 4825 connect(videoscanner, SIGNAL(finished(bool)), 4826 SLOT(finishVideoScan(bool))); 4827 videoscanner->doScan(GetVideoDirs()); 4828 retlist << "OK"; 4829 } 4830 else 4831 retlist << "ERROR"; 4832 4833 if (pbssock) 4834 SendResponse(pbssock, retlist); 4835 } 4836 4801 4837 void MainServer::HandleFileTransferQuery(QStringList &slist, 4802 4838 QStringList &commands, 4803 4839 PlaybackSock *pbs)