Recover Movies patch

Alles rund um das grafische Benutzerinterface Enigma
Sat-turner
Neugieriger
Neugieriger
Beiträge: 11
Registriert: Freitag 18. März 2005, 13:47

Recover Movies patch

Beitrag von Sat-turner »

Hello,

Summary: Existing records in recordings.epl are preserved when executing "Recover Movies" from the webinterface.

A couple of months ago I posted a patch to improve (in my opinion anyway) the functioning of Recover Movies in the web interface. In this message I would like to post a complete rewrite of this code. This time the existing Enigma classes are used more extensively.

Below is a description of the functionality. There a not many changes since last post:
In the original image the file recordings.epl is completely deleted and filled again every time the option "Recover Movies" is chosen. The description field is always filled with the comlete filename (minus ".ts").

This has been modified. First recordings.epl is read. The contents of the description field will be reused. All records of non-existant recordings are deleted. New records will be added for recordings not yet in recordings.epl.

The records will be sorted on the description. This was my choice. Maybe another sorting order is more convenient.

One big advantage is that once you edit the description (manually) in the file recordings.epl. These changes will be preserved.

Below is the patch against the original Enigma (13 June). Please let me know what you think of it. Feedback is appreciated ;-)

Code: Alles auswählen

--- /var/local/dreambox/tuxbox-rel.org/apps/tuxbox/enigma/include/lib/dvb/serviceplaylist.h     2005-06-08 14:30:02.000000000 +0200
+++ enigma/include/lib/dvb/serviceplaylist.h    2005-06-13 19:15:22.000000000 +0200
@@ -84,6 +84,10 @@
                else
                        return e.service == service && e.time_begin == time_begin;
        }
+       bool operator < (const ePlaylistEntry &e) const
+       {
+               return ( service.descr.compare( e.service.descr ) < 0 ) ;
+       }
 };

 class ePlaylist: public eService
--- /var/local/dreambox/tuxbox-rel.org/apps/tuxbox/enigma/src/enigma_dyn.cpp   2005-06-13 19:01:20.000000000 +0200
+++ enigma/src/enigma_dyn.cpp   2005-06-13 19:15:24.000000000 +0200
@@ -1724,37 +1724,123 @@
 }

 #ifndef        DISABLE_FILE
+// Extract the description from the filename.
+eString getDesc( const eString& str )
+{
+       unsigned int leftbound, rightbound ;
+       eString tbtrimmed ;
+
+       leftbound = str.find( '-' ) ;
+       rightbound = str.find( '-', leftbound + 1 ) ;
+       if ( ( rightbound == eString::npos ) || ( rightbound - leftbound < 1 ) )
+       {
+               tbtrimmed = str ;
+       } else {
+               tbtrimmed = str.substr( leftbound + 1, rightbound - leftbound - 1 ) ;
+       }
+
+       leftbound = tbtrimmed.find_first_not_of( ' ' ) ;
+       rightbound = tbtrimmed.find_last_not_of( ' ' ) ;
+
+       // If the extracted description is empty use the value of str as the description.
+       if ( rightbound - leftbound < 1 ) {
+               tbtrimmed = str ;
+               leftbound = tbtrimmed.find_first_not_of( ' ' ) ;
+               rightbound = tbtrimmed.find_last_not_of( ' ' ) ;
+       }
+       return tbtrimmed.substr( leftbound, rightbound - leftbound + 1 ) ;
+}
+
+// Recover index with recordings on harddisk in /hdd/movie.
 bool rec_movies()
 {
+       eString filen ;
+       int i ;
        bool result = false;
-       FILE *rec = fopen("/hdd/movie/recordings.epl", "w");
-       if (rec)
-       {
-               fprintf(rec, "#NAME Aufgenommene Filme\n");

-               struct dirent **namelist;
-               int n = scandir("/hdd/movie", &namelist, 0, alphasort);
-               if (n > 0)
-               {
-                       for (int i = 0; i < n; i++)
+       eZapMain::getInstance()->loadRecordings();
+       ePlaylist *recordings = eZapMain::getInstance()->getRecordings();
+       std::list<ePlaylistEntry>& rec_list = recordings->getList() ;
+       struct dirent **namelist;
+       int n = scandir("/hdd/movie", &namelist, 0, alphasort);
+
+       if ( n > 0 )
+       {
+               // There will be 2 passes through recordings list:
+               // 1) Delete entries from list that are not on disk.
+               // 2) Add entries to list that do not exist yet.
+
+               // Pass 1
+               std::list<ePlaylistEntry>::iterator it(rec_list.begin()) ;
+               std::list<ePlaylistEntry>::iterator it_next ;
+               while ( it != rec_list.end() )
+               {
+                       bool valid_file = false ;
+                       // For every file in /hdd/movie
+                       for (i = 0; i < n; i++)
+                       {
+                               filen = namelist[i]->d_name;
+                               // For every valid file
+                               if (( filen.length() >= 3 ) &&
+                               ( filen.substr(filen.length()-3, 3).compare(".ts") == 0 ) &&
+                                       (it->service.path.length() >= 11) &&
+                                       !it->service.path.substr(11,it->service.path.length()-11).compare( filen ) )
+                               {
+                                       valid_file = true ;
+                                       break ;
+                               }
+                       }
+
+                       (it_next = it)++ ;
+                       if ( !valid_file )
+                               rec_list.erase(it) ;
+                       else
                        {
-                               eString filen = namelist[i]->d_name;
-                               if ((filen.find(".ts") != eString::npos) && (filen.find(".ts.") == eString::npos))
+                               // Trim descr
+                               if ( it->service.descr.find_last_not_of( ' ' ) != eString::npos )
+                                       it->service.descr = it->service.descr.substr( 0, it->service.descr.find_last_not_of( ' ' ) + 1 ) ;
+                       }
+                       it = it_next ;
+               }
+
+               // Pass 2
+               for (i = 0; i < n; i++)
+               {
+                       filen = namelist[i]->d_name;
+                       // For every .ts file
+                       if ( ( filen.length() >= 3 ) &&
+                               ( filen.substr(filen.length()-3, 3).compare(".ts") == 0 ) )
+                       {
+                               // Check if file is in the list.
+                               bool file_in_list = false ;
+                               for (std::list<ePlaylistEntry>::iterator it(rec_list.begin()); it != rec_list.end(); ++it)
                                {
-                                       fprintf(rec, "#SERVICE: 1:0:1:0:0:0:000000:0:0:0:/hdd/movie/%s\n", filen.c_str());
-                                       fprintf(rec, "#DESCRIPTION: %s\n", getLeft(filen, '.').c_str());
-                                       fprintf(rec, "#TYPE 16385\n");
-                                       fprintf(rec, "/hdd/movie/%s\n", filen.c_str());
+                                       if ( (it->service.path.length() >= 11) &&
+                                               !it->service.path.substr(11,it->service.path.length()-11).compare( filen ) )
+                                       {
+                                               file_in_list = true ;
+                                               break ;
+                                       }
+                               }
+                               if ( !file_in_list )    // Add file to list.
+                               {
+                                       eServicePath path( "1:0:1:0:0:0:000000:0:0:0:/hdd/movie/" + filen ) ;
+                                       rec_list.push_back( path ) ;
+                                       rec_list.back().type = 16385 ;
+                                       rec_list.back().service.descr = getDesc( filen ) ;
+                                       rec_list.back().service.path = "/hdd/movie/" + filen ;

                                }
-                               free(namelist[i]);
                        }
-                       free(namelist);
-                       result = true;
+                       free( namelist[i] ) ;
                }
-               fclose(rec);
-               eZapMain::getInstance()->loadRecordings();
+               rec_list.sort() ;
+               result = true ;
        }
-       return result;
+
+       recordings->save();
+       free( namelist ) ;
+
+       return result ;
 }

 static eString recoverRecordings(eString request, eString dirpath, eString opt, eHTTPConnection *content)