cache movie filelengths in .meta file, by luke_s
authorFelix Domke <tmbinc@elitedvb.net>
Wed, 14 Jan 2009 23:49:09 +0000 (00:49 +0100)
committerFelix Domke <tmbinc@elitedvb.net>
Wed, 14 Jan 2009 23:49:09 +0000 (00:49 +0100)
lib/dvb/metaparser.cpp
lib/dvb/metaparser.h
lib/service/servicedvb.cpp

index 3e3f9a79143df6cde1b7b50f6e8af02168f35fcd..175c7cdb055af9a97289cdf71049d56550db6add 100644 (file)
@@ -6,6 +6,8 @@ eDVBMetaParser::eDVBMetaParser()
 {
        m_time_create = 0;
        m_data_ok = 0;
 {
        m_time_create = 0;
        m_data_ok = 0;
+       m_length = 0;
+       m_filesize = 0;
 }
 
 int eDVBMetaParser::parseFile(const std::string &basename)
 }
 
 int eDVBMetaParser::parseFile(const std::string &basename)
@@ -59,6 +61,12 @@ int eDVBMetaParser::parseMeta(const std::string &tsname)
                case 4:
                        m_tags = line;
                        break;
                case 4:
                        m_tags = line;
                        break;
+               case 5:
+                       m_length = atoi(line);  //movielength in pts
+                       break;
+               case 6:
+                       m_filesize = atoll(line);
+                       break;
                default:
                        break;
                }
                default:
                        break;
                }
@@ -105,17 +113,19 @@ int eDVBMetaParser::parseRecordings(const std::string &filename)
                        ref = eServiceReferenceDVB(line + 10);
                if (!strncmp(line, "#DESCRIPTION: ", 14))
                        description = line + 14;
                        ref = eServiceReferenceDVB(line + 10);
                if (!strncmp(line, "#DESCRIPTION: ", 14))
                        description = line + 14;
-
-               if ((line[0] == '/') && (ref.path == filename))
+               if ((line[0] == '/') && (ref.path.substr(ref.path.find_last_of('/')) == filename.substr(filename.find_last_of('/'))))
                {
 //                     eDebug("hit! ref %s descr %s", m_ref.toString().c_str(), m_name.c_str());
                        m_ref = ref;
                        m_name = description;
                        m_description = "";
                        m_time_create = 0;
                {
 //                     eDebug("hit! ref %s descr %s", m_ref.toString().c_str(), m_name.c_str());
                        m_ref = ref;
                        m_name = description;
                        m_description = "";
                        m_time_create = 0;
-                       
+                       m_length = 0;
+                       m_filesize = 0;
+                                               
                        m_data_ok = 1;
                        fclose(f);
                        m_data_ok = 1;
                        fclose(f);
+                       updateMeta(filename.c_str());
                        return 0;
                }
        }
                        return 0;
                }
        }
@@ -125,14 +135,17 @@ int eDVBMetaParser::parseRecordings(const std::string &filename)
 
 int eDVBMetaParser::updateMeta(const std::string &tsname)
 {
 
 int eDVBMetaParser::updateMeta(const std::string &tsname)
 {
-       if (!m_data_ok) 
+       /* write meta file only if we have valid data. Note that we might convert recordings.epl data to .meta, which is fine. */
+       if (!m_data_ok)
                return -1;
        std::string filename = tsname + ".meta";
                return -1;
        std::string filename = tsname + ".meta";
+       eServiceReference ref = m_ref;
+       ref.path = "";
 
        FILE *f = fopen(filename.c_str(), "w");
        if (!f)
                return -ENOENT;
 
        FILE *f = fopen(filename.c_str(), "w");
        if (!f)
                return -ENOENT;
-       fprintf(f, "%s\n%s\n%s\n%d\n%s\n", m_ref.toString().c_str(), m_name.c_str(), m_description.c_str(), m_time_create, m_tags.c_str());
+       fprintf(f, "%s\n%s\n%s\n%d\n%s\n%d\n%lld\n", ref.toString().c_str(), m_name.c_str(), m_description.c_str(), m_time_create, m_tags.c_str(), m_length, m_filesize );
        fclose(f);
        return 0;
 }
        fclose(f);
        return 0;
 }
index 01fabde892701abd5282009bdb79494e1191d8b6..2ca94d6d97ebb1c3827d157fad336ecc4fd7b6bd 100644 (file)
@@ -18,7 +18,8 @@ public:
        
        eServiceReferenceDVB m_ref;
        std::string m_name, m_description;
        
        eServiceReferenceDVB m_ref;
        std::string m_name, m_description;
-       int m_time_create;
+       int m_time_create, m_length;
+       long long m_filesize;
        
        std::string m_tags;
 };
        
        std::string m_tags;
 };
index 90195d9b13e438a790f077c5974f6f3e8703b1fc..dcd7017c97ab427b3257557d0b4a02690d57caab 100644 (file)
@@ -536,14 +536,25 @@ int eStaticServiceDVBPVRInformation::getLength(const eServiceReference &ref)
        
        eDVBTSTools tstools;
        
        
        eDVBTSTools tstools;
        
+       struct stat s;
+       stat(ref.path.c_str(), &s);
+
        if (tstools.openFile(ref.path.c_str()))
                return 0;
 
        if (tstools.openFile(ref.path.c_str()))
                return 0;
 
+                       /* check if cached data is still valid */
+       if (m_parser.m_data_ok && (s.st_size == m_parser.m_filesize) && (m_parser.m_length))
+               return m_parser.m_length / 90000;
+
+                       /* otherwise, re-calc length and update meta file */
        pts_t len;
        if (tstools.calcLen(len))
                return 0;
 
        pts_t len;
        if (tstools.calcLen(len))
                return 0;
 
-       return len / 90000;
+       m_parser.m_length = len;
+       m_parser.m_filesize = s.st_size;
+       m_parser.updateMeta(ref.path);
+       return m_parser.m_length / 90000;
 }
 
 int eStaticServiceDVBPVRInformation::getInfo(const eServiceReference &ref, int w)
 }
 
 int eStaticServiceDVBPVRInformation::getInfo(const eServiceReference &ref, int w)