[mythtv] [PATCH] Cast, extended plot and isSubbed in MythVideo

zart at phreaker.net zart at phreaker.net
Mon Oct 11 15:09:03 UTC 2004


Mjallo

Here's a patch which adds a "View cast" and "View more plot" button to
the menu in the video browser. If one gets info from imdb using the
videomanager, these two sections will contain appropriate data. Further
more the "genre" portion of imdb.pl has been fixed.

For these to work one needs to make a issue these commands to mysql:
"alter table videometadata add cast text"
"alter table videometadata add moreplot text"
Maybe those should be added to the dbcheck.cpp? (I havn't!)

Besides this I've made a theme object called "subbed" for the video
browser. If it's included in the theme it'll be visible if it's possible
to find subtitle-files for the movie (In same dir or in special
subtitles dir configureable from the setup).

I've put this
      <textarea name="subbed" draworder="4" align="left">
        <area>700, 90,150,35</area>
        <font>labels</font>
        <value>Subbed</value>
      </textarea>
in the "info" container of the Titivillus theme.

This is my first "larger" patch so I would like to get some response as to wether it's total crap or if some find it useful :)

- Zart


-------------- next part --------------
Index: globalsettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/globalsettings.cpp,v
retrieving revision 1.17
diff -u -r1.17 globalsettings.cpp
--- globalsettings.cpp	9 Aug 2004 20:58:43 -0000	1.17
+++ globalsettings.cpp	11 Oct 2004 12:40:28 -0000
@@ -139,6 +139,17 @@
     };
 };
 
+class GetExtraDataCommand: public LineEditSetting, public GlobalSetting {
+public:
+    GetExtraDataCommand():
+        GlobalSetting("MovieExtraDataCommandLine") {
+        setLabel(QObject::tr("Command to extract extra data(more plot) for movies"));
+        setValue(PREFIX "/share/mythtv/mythvideo/scripts/imdb.pl -E");
+        setHelpText(QObject::tr("This command must be "
+                    "executable by the user running MythVideo."));
+    };
+};
+
 
 class VideoStartupDirectory: public LineEditSetting, public GlobalSetting {
 public:
@@ -152,6 +163,16 @@
     };
 };
 
+class VideoSubtitlesDirectory: public LineEditSetting, public GlobalSetting {
+public:
+    VideoSubtitlesDirectory():
+        GlobalSetting("VideoSubtitlesDir") {
+        setLabel(QObject::tr("Directory that holds subtitles for videos"));
+        setValue("/home/mythtv/.mplayer/sub/");
+        setHelpText(QObject::tr("Search for subs will be in this dir + movie dir. User running MythVideo only needs to have read permission "
+                    "to the directory."));
+    };
+};
 
 class VideoArtworkDirectory: public LineEditSetting, public GlobalSetting {
 public:
@@ -227,6 +248,7 @@
     general->setLabel(QObject::tr("General Settings"));
     general->addChild(new VideoStartupDirectory());
     general->addChild(new VideoArtworkDirectory());
+    general->addChild(new VideoSubtitlesDirectory());
     general->addChild(new VideoDefaultParentalLevel());
     general->addChild(new VideoAdminPassword());
     general->addChild(new VideoAggressivePC());
@@ -241,6 +263,7 @@
     vman->addChild(new SearchListingsCommand());
     vman->addChild(new GetPostersCommand());
     vman->addChild(new GetDataCommand());
+    vman->addChild(new GetExtraDataCommand());
     addChild(vman);
 
     VerticalConfigurationGroup * vgal = new VerticalConfigurationGroup(false);
Index: main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/main.cpp,v
retrieving revision 1.35
diff -u -r1.35 main.cpp
--- main.cpp	22 Aug 2004 18:16:32 -0000	1.35
+++ main.cpp	11 Oct 2004 12:40:29 -0000
@@ -396,7 +396,9 @@
 
             myNewFile = new Metadata(name, QObject::tr("No Cover"), "", 
                                      1895, "00000000", QObject::tr("Unknown"), 
-                                     QObject::tr("None"), 0.0, 
+                                     QObject::tr("None"),
+                                     QObject::tr("None"),
+                                     QObject::tr(""),0.0,                                      
                                      QObject::tr("NR"), 0, 0, 1);
             myNewFile->guessTitle();
             myNewFile->dumpToDatabase(db);
Index: metadata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/metadata.cpp,v
retrieving revision 1.19
diff -u -r1.19 metadata.cpp
--- metadata.cpp	19 Sep 2004 13:45:50 -0000	1.19
+++ metadata.cpp	11 Oct 2004 12:40:30 -0000
@@ -28,6 +28,10 @@
         director = data;
     else if (field == "plot")
         plot = data;
+    else if (field == "moreplot")
+        moreplot = data;
+    else if (field == "cast")
+        cast = data;
     else if (field == "rating")
         rating = data;
     else if (field == "year")
@@ -175,7 +179,7 @@
 
     QString thequery = "SELECT title,director,plot,rating,year,userrating,"
                        "length,filename,showlevel,intid,coverfile,inetref,"
-                       "childid, browse, playcommand FROM videometadata WHERE title=\"" + 
+                       "childid, browse, playcommand, moreplot, cast FROM videometadata WHERE title=\"" + 
                         title + "\"";
 
     if (director != "")
@@ -206,6 +210,8 @@
         childID = query.value(12).toUInt();
         browse = query.value(13).toBool();
         playcommand = query.value(14).toString();
+        moreplot = QString::fromUtf8(query.value(15).toString());
+        cast = QString::fromUtf8(query.value(16).toString());
     return true;
     }
     else
@@ -223,7 +229,7 @@
     QString thequery;
     thequery = QString("SELECT title,director,plot,rating,year,userrating,"
                        "length,filename,showlevel,coverfile,inetref,childid,"
-                       "browse,playcommand, videocategory.category "
+                       "browse,playcommand, videocategory.category, moreplot,cast "
                        " FROM videometadata LEFT JOIN videocategory"
                        " ON videometadata.category = videocategory.intid"
                        "  WHERE videometadata.intid=%1;")
@@ -249,6 +255,8 @@
         browse = query.value(12).toBool();
         playcommand = query.value(13).toString();
         category = query.value(14).toString();
+        moreplot = QString::fromUtf8(query.value(15).toString());
+        cast = QString::fromUtf8(query.value(16).toString());
 
     // Genres
         fillGenres(db);
@@ -275,7 +283,7 @@
     thequery = QString("SELECT videometadata.intid,title,director,plot"
                ",rating,year,userrating,length,showlevel,coverfile"
                ",inetref,childid,browse,playcommand"
-               ", videocategory.category "
+               ", videocategory.category, moreplot,cast "
                        " FROM videometadata LEFT JOIN videocategory"
                        " ON videometadata.category = videocategory.intid"
                        "  WHERE videometadata.filename='%1';")
@@ -300,6 +308,8 @@
         browse = query.value(12).toBool();
         playcommand = query.value(13).toString();
         category = query.value(14).toString();
+        moreplot = QString::fromUtf8(query.value(15).toString());
+        cast = QString::fromUtf8(query.value(16).toString());
 
     // Genres
         fillGenres(db);
@@ -323,6 +333,10 @@
         director = QObject::tr("Unknown");
     if (plot == "")
         plot = QObject::tr("None");
+    if (moreplot == "")
+        moreplot = QObject::tr("None");
+    if (cast == "")
+        cast = QObject::tr("Noone,Noone");
     if (rating == "")
         rating = QObject::tr("Unknown Rating");
     if (coverfile == "")
@@ -342,6 +356,8 @@
     title.replace(QRegExp("\""), QString("\\\""));
     director.replace(QRegExp("\""), QString("\\\""));
     plot.replace(QRegExp("\""), QString("\\\""));
+    moreplot.replace(QRegExp("\""), QString("\\\""));
+    cast.replace(QRegExp("\""), QString("\\\""));
     rating.replace(QRegExp("\""), QString("\\\""));
 
     QString sqlfilename = filename;
@@ -351,13 +367,14 @@
     sqlcoverfile.replace(QRegExp("\""), QString("\\\""));
 
     QString thequery;
-    thequery.sprintf("INSERT INTO videometadata (title,director,plot,"
+    thequery.sprintf("INSERT INTO videometadata (title,director,plot,moreplot,cast,"
                      "rating,year,userrating,length,filename,showlevel,"
                      "coverfile,inetref,browse) VALUES "
-                     "(\"%s\",\"%s\",\"%s\",\"%s\",%d,%f,%d,\"%s\",%d,\"%s\","
+                     "(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%d,%f,%d,\"%s\",%d,\"%s\","
                      "\"%s\", %d);",
                      title.utf8().data(), director.utf8().data(),
-                     plot.utf8().data(), rating.utf8().data(), year,
+                     plot.utf8().data(), moreplot.utf8().data(),
+                     cast.utf8().data(), rating.utf8().data(), year,
                      userrating, length, sqlfilename.utf8().data(), showlevel,
                      sqlcoverfile.utf8().data(), inetref.utf8().data(),browse);
     
@@ -457,6 +474,10 @@
         director = QObject::tr("Unknown");
     if (plot == "")
         plot = QObject::tr("None");
+    if (moreplot == "")
+        moreplot = QObject::tr("None");
+    if (cast == "")
+        cast = QObject::tr("Noone,Noone");
     if (rating == "")
         rating = QObject::tr("Unknown Rating");
     if (coverfile == "")
@@ -467,6 +488,8 @@
     title.replace(QRegExp("\""), QString("\\\""));
     director.replace(QRegExp("\""), QString("\\\""));
     plot.replace(QRegExp("\""), QString("\\\""));
+    moreplot.replace(QRegExp("\""), QString("\\\""));
+    cast.replace(QRegExp("\""), QString("\\\""));
     rating.replace(QRegExp("\""), QString("\\\""));
     playcommand.replace(QRegExp("\""), QString("\\\""));
     QString sqlfilename = filename;
@@ -479,13 +502,14 @@
 
     QString thequery;
     thequery.sprintf("UPDATE videometadata SET title=\"%s\",director=\"%s\","
-                     "plot=\"%s\",rating=\"%s\",year=%d,userrating=%f,"
+                     "plot=\"%s\",moreplot=\"%s\",cast=\"%s\",rating=\"%s\",year=%d,userrating=%f,"
                      "length=%d,filename=\"%s\",showlevel=%d,coverfile=\"%s\","
                      "inetref=\"%s\",browse=%d,playcommand=\"%s\",childid=%d,"
                      "category=%d"
                      " WHERE intid=%d",
                      title.utf8().data(), director.utf8().data(),
-                     plot.utf8().data(), rating.utf8().data(), year,
+                     plot.utf8().data(), moreplot.utf8().data(),
+                     cast.utf8().data(), rating.utf8().data(), year,
                      userrating, length, sqlfilename.utf8().data(), showlevel,
                      sqlcoverfile.utf8().data(), inetref.utf8().data(), browse,
                      playcommand.utf8().data(), childID, idCategory, id);
@@ -736,3 +760,22 @@
     }
     return coverPixmap;
 }
+
+bool Metadata::isSubbed()
+{
+   QString filename2;
+   int pos = filename.findRev("\\");
+   int pos2 = filename.findRev("/");
+   if (pos2>pos)
+       pos = pos2;
+   if (pos > -1) {
+       pos2 = filename.findRev(".");
+       if (pos2 < pos || pos2 == -1)
+           pos2 = filename.length();
+       filename2 = filename.mid(pos+1, pos2-pos-1);
+       filename2 = gContext->GetSetting("VideoSubtitlesDir") + filename2;
+       return QFile::exists(filename2 + ".sub") ||
+              QFile::exists(filename2 + ".srt");
+   }
+   return false;
+}
Index: metadata.h
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/metadata.h,v
retrieving revision 1.14
diff -u -r1.14 metadata.h
--- metadata.h	9 Sep 2004 14:48:03 -0000	1.14
+++ metadata.h	11 Oct 2004 12:40:31 -0000
@@ -15,7 +15,8 @@
   public:
     Metadata(QString lfilename = "", QString lcoverfile = "", 
              QString ltitle = "", int lyear = 0, QString linetref = "", 
-             QString ldirector = "", QString lplot = "", 
+             QString ldirector = "", QString lplot = "", QString lmoreplot =
+             "", QString lcast = "",
              float luserrating = 0.0, QString lrating = "", int llength = 0, 
              int lid = 0, int lshowlevel = 1, int lchildID = -1,
              bool lbrowse = true, QString lplaycommand = "",
@@ -32,6 +33,8 @@
         inetref = linetref;
         director = ldirector;
         plot = lplot;
+        moreplot = lmoreplot;
+        cast = lcast;
         luserrating = luserrating;
         rating = lrating;
         length = llength;
@@ -56,6 +59,8 @@
         inetref = other.inetref;
         director = other.director;
         plot = other.plot;
+        moreplot = other.moreplot;
+        cast = other.cast;
         userrating = other.userrating;
         rating = other.rating;
         length = other.length;
@@ -81,6 +86,8 @@
         inetref = "";
         director = "";
         plot = "";
+        moreplot = "";
+        cast = "";
         userrating = 0;
         rating = "";
         length = 0;
@@ -114,6 +121,12 @@
     QString Plot() { return plot; }
     void setPlot(const QString &lplot) { plot = lplot; }
 
+    QString MorePlot() { return moreplot; }
+    void setMorePlot(const QString &lmoreplot) { moreplot = lmoreplot; }
+
+    QString Cast() { return cast; }
+    void setCast(const QString &lcast) { cast = lcast; }
+    
     float UserRating() { return userrating; }
     void setUserRating(float luserrating) { userrating = luserrating; }
  
@@ -171,6 +184,7 @@
     QPixmap* getCoverPixmap();
     void setCoverPixmap(QPixmap* pix) { coverPixmap = pix; }
     bool haveCoverPixmap() const { return (coverPixmap != NULL); }
+    bool Metadata::isSubbed();
   private:
     void fillCategory(QSqlDatabase *db);
     void fillCountries(QSqlDatabase *db);
@@ -184,6 +198,8 @@
     QString inetref;
     QString director;
     QString plot;
+    QString moreplot;
+    QString cast;
     QString rating;
     int childID;
     int year;
Index: videobrowser.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videobrowser.cpp,v
retrieving revision 1.39
diff -u -r1.39 videobrowser.cpp
--- videobrowser.cpp	22 Aug 2004 18:16:32 -0000	1.39
+++ videobrowser.cpp	11 Oct 2004 12:40:33 -0000
@@ -121,6 +121,8 @@
         {
             focusButton = popup->addButton(tr("Watch This Video"), this, SLOT(slotWatchVideo())); 
             popup->addButton(tr("View Full Plot"), this, SLOT(slotViewPlot()));
+            popup->addButton(tr("View More Plot"), this, SLOT(slotViewMorePlot()));
+            popup->addButton(tr("View Full Cast"), this, SLOT(slotViewCast()));
         }
         else
         {
@@ -318,6 +320,7 @@
     {
        QString title = curitem->Title();
        QString filename = curitem->Filename();
+       bool subs = curitem->isSubbed();
        QString director = curitem->Director();
        QString year = QString("%1").arg(curitem->Year());
        if (year == "1895") 
@@ -396,6 +399,17 @@
            type = (UITextType *)container->GetType("level");
            if (type)
                type->SetText(level);
+           
+           
+           type = (UITextType *)container->GetType("subbed");
+           if (type)
+               if (subs) {
+                   if (type->isHidden())
+                       type->show();
+               } else {
+                   if (type->isShown())
+                       type->hide();
+               } 
   
            container->Draw(&tmp, 1, 0); 
            container->Draw(&tmp, 2, 0);
Index: videodlg.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videodlg.cpp,v
retrieving revision 1.4
diff -u -r1.4 videodlg.cpp
--- videodlg.cpp	19 Sep 2004 13:45:50 -0000	1.4
+++ videodlg.cpp	11 Oct 2004 12:40:33 -0000
@@ -19,6 +19,7 @@
     myType = _myType;
     curitem = NULL;    
     popup = NULL;
+    popupNextNr = 0;
     
     //
     //  Load the theme. Crap out if we can't find it.
@@ -68,9 +69,10 @@
 
 void VideoDialog::slotDoCancel(void)
 {
+    popupNextNr = 0;
     if (!expectingPopup)
         return;
-
+    
     cancelPopup();
 }
 
@@ -162,6 +164,84 @@
     }
 }
 
+void VideoDialog::popupNextOk(QString s, const char *slot)
+{
+    cancelPopup();
+    popup = new MythPopupBox(gContext->GetMainWindow(), "video popup");
+    expectingPopup = true;
+
+    allowPaint = false;
+    QLabel *sLabel = popup->addLabel(s,MythPopupBox::Small,true);
+    sLabel->setAlignment(Qt::AlignJustify | Qt::WordBreak);
+    
+    QButton * okButton = popup->addButton(tr("Ok"), this, SLOT(slotDoCancel()));
+    popup->addButton(tr("Next"), this, slot); 
+
+    okButton->setFocus();
+    popupNextNr++;
+    
+    popup->ShowPopup(this, SLOT(slotDoCancel()));
+}
+
+void VideoDialog::slotViewMorePlot()
+{
+    if (curitem) {
+        QStringList plots = QStringList::split(QRegExp("[\\s\n\\-]*Summary\\swritten\\sby[^\n]*\n*" ), 
+                                        curitem->MorePlot());
+        QStringList writers = QStringList::split("\n", curitem->MorePlot()).grep(QRegExp(".*Summary\\swritten\\sby.*" ));
+
+        if (plots.size() <= popupNextNr) {
+            slotDoCancel();
+            return;
+        }
+        if (plots.size() == 0) {
+            plots.push_back("None");
+            writers.push_back("");
+        }
+
+        popupNextOk(plots[popupNextNr] + writers[popupNextNr], SLOT(slotViewMorePlot()));
+    }
+    else
+    {
+        cerr << "no Item to view" << endl;
+        slotDoCancel();
+    }
+   
+}
+
+void VideoDialog::slotViewCast()
+{
+    if(curitem) {
+        QStringList cast = QStringList::split(",", curitem->Cast());
+        if (cast.size() % 2) {
+            cerr << "error in cast: " << curitem->Cast() << endl;
+            slotDoCancel();
+            return;
+        }
+        if (cast.size() < popupNextNr*20) {
+            slotDoCancel();
+            return;
+        }
+            
+        QString actors = "";
+        QStringList::Iterator it = cast.at(popupNextNr*20);
+        for (int i = 0; i < 10 && it !=cast.end(); i++)
+        {
+            QString p = *it;
+            it++;
+            QString r = *it;
+            it++;
+            actors+=p + " ... " + r + "\n";
+        }
+
+        popupNextOk(actors, SLOT(slotViewCast()));
+    }
+    else
+    {
+        cerr << "no Item to view" << endl;
+        slotDoCancel();
+    }
+}
 
 void VideoDialog::slotWatchVideo()
 {
Index: videodlg.h
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videodlg.h,v
retrieving revision 1.3
diff -u -r1.3 videodlg.h
--- videodlg.h	22 Aug 2004 18:16:32 -0000	1.3
+++ videodlg.h	11 Oct 2004 12:40:34 -0000
@@ -38,6 +38,9 @@
         void slotVideoGallery();
         void slotVideoBrowser();
         void slotViewPlot();
+        void popupNextOk(QString s, const char *slot);
+        void slotViewMorePlot();
+        void slotViewCast();
         void slotDoFilter();
         void exitWin();
         virtual void slotParentalLevelChanged() {cerr << "VideoDialog::parseContainer" << endl;}
@@ -66,7 +69,8 @@
         DialogType myType;
         
         bool allowPaint;
-        
+        unsigned int popupNextNr;
+       
         XMLParse *theme;
         QDomElement xmldata;
         
Index: videomanager.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videomanager.cpp,v
retrieving revision 1.38
diff -u -r1.38 videomanager.cpp
--- videomanager.cpp	19 Sep 2004 13:45:51 -0000	1.38
+++ videomanager.cpp	11 Oct 2004 12:40:38 -0000
@@ -349,6 +349,32 @@
     return localfile;
 }
 
+void VideoManager::GetMovieExtraInfo(QString movieNum) {
+    if (movieNum == "Local")
+      return;
+                
+    QStringList args = QStringList::split(' ',
+              gContext->GetSetting("MovieExtraDataCommandLine", 
+              "/usr/local/share/mythtv/mythvideo/scripts/imdb.pl -E"));
+    
+    args += movieNum;
+
+    // execute external command to obtain list of possible movie matches 
+    QString results = executeExternal(args, "Movie Extra Data Query");
+
+    // parse results
+    QStringList lines = QStringList::split('\n', results);
+    QString moreplot = "";
+    if (lines.size() > 0) {
+        for (QStringList::Iterator it = lines.begin();it != lines.end(); ++it) {
+            if ( (*it).at(0) == '#')  // treat lines beg w/ # as a comment
+                continue;
+            moreplot+="\n"+*it;
+        }
+    }
+    curitem->setMorePlot(moreplot);
+}
+
 void VideoManager::copyFinished(QNetworkOperation* op) {
    QString state, operation;
    switch(op->operation()) {
@@ -412,6 +438,7 @@
         curitem->setYear(data["Year"].toInt());
         curitem->setDirector(data["Director"]);
         curitem->setPlot(data["Plot"]);
+        curitem->setCast(data["Cast"]);
         curitem->setUserRating(data["UserRating"].toFloat());
         curitem->setRating(data["MovieRating"]);
         curitem->setLength(data["Runtime"].toInt());
@@ -458,6 +485,8 @@
     } else {
         ResetCurrentItem();
     }
+    
+    GetMovieExtraInfo(movieNum);
 
     curitem->updateDatabase(db);
     RefreshMovieList();
@@ -1399,6 +1428,8 @@
     curitem->setInetRef("00000000");
     curitem->setDirector(tr("Unknown"));
     curitem->setPlot(tr("None"));
+    curitem->setMorePlot(tr("None"));
+    curitem->setCast(tr(""));
     curitem->setUserRating(0.0);
     curitem->setRating(tr("NR"));
     curitem->setLength(0);
Index: videomanager.h
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videomanager.h,v
retrieving revision 1.13
diff -u -r1.13 videomanager.h
--- videomanager.h	9 May 2004 22:53:26 -0000	1.13
+++ videomanager.h	11 Oct 2004 12:40:38 -0000
@@ -96,6 +96,7 @@
     void RefreshMovieList();
     QString ratingCountry;
     void GetMovieData(QString);
+    void GetMovieExtraInfo(QString);
     int GetMovieListing(QString);
     QString GetMoviePoster(QString);
     QStringList movieList;
Index: scripts/imdb.pl
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/scripts/imdb.pl,v
retrieving revision 1.3
diff -u -r1.3 imdb.pl
--- scripts/imdb.pl	7 Sep 2004 01:15:25 -0000	1.3
+++ scripts/imdb.pl	11 Oct 2004 12:40:39 -0000
@@ -19,7 +19,7 @@
 use XML::Simple;
 
 
-use vars qw($opt_h $opt_r $opt_d $opt_i $opt_v $opt_D $opt_M $opt_P);
+use vars qw($opt_h $opt_r $opt_d $opt_i $opt_v $opt_D $opt_E $opt_M $opt_P);
 use Getopt::Std; 
 
 $title = "IMDB Query"; 
@@ -45,6 +45,7 @@
    print "               Note: multiple options must be separated by ';'\n";
    print "       -P <movieid>  get movie poster\n";
    print "       -D <movieid>  get movie data\n";
+   print "       -E <movieid>  get movie plot(extra)\n";
    exit(-1);
 }
 
@@ -142,17 +143,28 @@
    if ($data) {
       my $beg = "/\">"; 
       my $end = "</a>";
+      my $beg2 = "\"top\">";
+      my $end2 = "</td>";
       my $start = index($data, $beg);
       my $finish = index($data, $end, $start);
       my $actor;
       while ($start != -1) {
          $start += length($beg);
          $actor = substr($data, $start, $finish - $start);
+         $actor =~ s/,/./; # avoid fucking up list.
          # add to array
          $actors[$count++] = $actor;
 
          # advance data to next movie
          $data = substr($data, - (length($data) - $finish));
+         $start = index($data, $beg2);
+         $finish = index($data, $end2, $start + 1);
+         $start += length($beg2);
+         $actor = substr($data, $start, $finish - $start);
+         $actor =~ s/,/./; # avoid fucking up list.
+         $actors[$count++] = $actor;
+         $data = substr($data, - (length($data) - $finish));
+         
          $start = index($data, $beg);
          $finish = index($data, $end, $start + 1); 
       }
@@ -164,7 +176,7 @@
    my @genres;
    my $lgenres = "";
    $count = 0;
-   $data = parseBetween($response, "<b class=\"ch\">Genre:</b>","<a href=\"keywords\">(more)</a>"); 
+   $data = parseBetween($response, "<b class=\"ch\">Genre:</b>","<a href=\"/rg/title-tease/keywords/title/tt$movieid/keywords\">(more)</a>"); 
    if ($data) {
       my $beg = "/\">"; 
       my $end = "</a>";
@@ -224,6 +236,48 @@
    print "Countries: $lcountries\n";
 }
 
+sub parseBetween2 {
+   my ($data, $beg, $end)=@_; # grab parameters
+   my $ldata = lc($data);
+
+   my $start = index($ldata, lc($beg)) + length($beg);
+   my $finish = index($ldata, lc($end), $start);
+   if ($start != (length($beg) -1) && $finish != -1) {
+      my $result = substr($data, $start, $finish - $start);
+      # return w/ decoded numeric character references
+      # (see http://www.w3.org/TR/html4/charset.html#h-5.3.1)
+      decode_entities($result);
+      return (substr($data, $finish, length($data)), $result);
+   }
+   return ($data,"");
+}
+
+sub getMovieMorePlot {
+   my ($movieid)=@_; # grab movieid parameter
+   if (defined $opt_d) { printf("# looking for plot for movie id: '%s'\n", $movieid);}
+
+   # get the search results  page
+   my $request = "http://www.imdb.com/title/tt" . $movieid . "/plotsummary";
+   if (defined $opt_d) { printf("# request: '%s'\n", $request); }
+   my $response = get $request;
+   if (defined $opt_r) { printf("%s", $response); }
+
+   my $plot = "";
+   $plot2 = "";
+   $sumwriter = "";
+   ($response, $plot2) = parseBetween2($response, "<p class=\"plotpar\">", "</p>");
+   while (length($plot2) >= 1) {
+       ($response, $sumwriter) = parseBetween2($response, "<p align=\"center\">", "</a></p>");
+       $sumwriter =~ s/\<a.*\>//;
+       $plot = "$plot$plot2 \n  -  $sumwriter \n\n";
+       ($response, $plot2) = parseBetween2($response, "<p class=\"plotpar\">", "</p>");
+   }
+     
+   print "$plot\n";
+}
+
+
+
 # dump Movie Poster
 sub getMoviePoster {
    my ($movieid)=@_; # grab movieid parameter
@@ -540,7 +594,7 @@
 #
 
 # parse command line arguments 
-getopts('ohrdivDMP');
+getopts('ohrdivEDMP');
 
 # print out info 
 if (defined $opt_v) { version(); exit 1; }
@@ -555,6 +609,12 @@
    getMovieData($movieid);
 }
 
+elsif (defined $opt_E) {
+   # take movieid from cmdline arg
+   $movieid = shift || die "Usage : $0 -E <movieid>\n";
+   getMovieMorePlot($movieid);
+}
+
 elsif (defined $opt_P) {
    # take movieid from cmdline arg
    $movieid = shift || die "Usage : $0 -P <movieid>\n";


More information about the mythtv-dev mailing list