Sign up here and you can log into the forum!

my next crazy idea - trailers

General WDTVExt forum

Re: my next crazy idea - trailers   

Postby KAD » Sun Feb 12, 2012 10:44 am

ok, so here's the string

Code: Select all
   var meta = ("<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"><item id=" + Trailer + "\" parentID=" + Trailer + "\" restricted=\"0\"><dc:title>" + Title + "</dc:title><dc:date></dc:date><upnp:class>object.item.videoItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo=\"file-get:*:*::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000\" protection=\"\" tokenType=\"0\" bitrate=\"0\" duration=\"\" size=\"\" colorDepth=\"0\" ifoFileURI=\"\" resolution=\"\">" + Trailer + "</res></item></DIDL-Lite>");


so I tried double quote the whole thing, then single quote
Code: Select all
   var meta = ("'<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"><item id=" + Trailer + "\" parentID=" + Trailer + "\" restricted=\"0\"><dc:title>" + Title + "</dc:title><dc:date></dc:date><upnp:class>object.item.videoItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo=\"file-get:*:*::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000\" protection=\"\" tokenType=\"0\" bitrate=\"0\" duration=\"\" size=\"\" colorDepth=\"0\" ifoFileURI=\"\" resolution=\"\">" + Trailer + "</res></item></DIDL-Lite>'");

does not play

then replace the double quote with single quote
Code: Select all
   var meta = ('<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"><item id=" + Trailer + "\" parentID=" + Trailer + "\" restricted=\"0\"><dc:title>" + Title + "</dc:title><dc:date></dc:date><upnp:class>object.item.videoItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo=\"file-get:*:*::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000\" protection=\"\" tokenType=\"0\" bitrate=\"0\" duration=\"\" size=\"\" colorDepth=\"0\" ifoFileURI=\"\" resolution=\"\">" + Trailer + "</res></item></DIDL-Lite>');


plays but system actually interprets the single quote and logs double quotes in the meta, also I loose veriables this way, such as Trailer because part of the string

tried single quote then double quote
which had the same effect

I'm sure mad_ady is right that there's something with additional escape level's needed

KAD
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4011
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: my next crazy idea - trailers   

Postby mad_ady » Sun Feb 12, 2012 11:04 am

Try something like:
Code: Select all
var meta = '<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item id="'.Trailer.'" parentID="'.Trailer.'" restricted="0"><dc:title>'.title.'</dc:title><dc:date></dc:date>upnp:class>object.item.videoItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo="file-get:*:*::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000" protection="" tokenType="0" bitrate="0" duration="" size="" colorDepth="0" ifoFileURI="" resolution="">'.Trailer.'</res></item></DIDL-Lite>';
var cmd = 'upnp-cmd SetAVTransportURI "'.Trailer.'" '."'".meta.'"';


I know it's a cacofony of quotes, but the trick you need to remember is - double quotes interpret and expand variables within (in shell), while single quotes don't. Next, you need to use string concatenation (represented by dot above, although I think it's "+" in javascript) to build the string you want.

Use an editor with syntax highlighting to make the mess more clear.
User avatar
mad_ady
Developer
 
Posts: 2999
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: my next crazy idea - trailers   

Postby KAD » Sun Feb 12, 2012 12:53 pm

still no go :(

I tried
Code: Select all
   var meta = ('<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"><item id="' + Trailer + '" parentID="' + Trailer + '" restricted=\"0\"><dc:title>"' + Title + '"</dc:title><dc:date></dc:date><upnp:class>object.item.videoItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo=\"file-get:*:*::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000\" protection=\"\" tokenType=\"0\" bitrate=\"0\" duration=\"\" size=\"\" colorDepth=\"0\" ifoFileURI=\"\" resolution=\"\">"' + Trailer + '"</res></item></DIDL-Lite>');


which produced this
Code: Select all
Lib: [executeCmd]  cmd: upnp-cmd SetAVTransportURI "http://video-http.media-imdb.com/MV5BMTQ5Nzc4MjM0NV5BMTFeQW1wNF5BbWU3MDUwMDkzMzM@.mp4?Expires=1329111776&Signature=qQxgxY5YRG40k3RwdYTCoRbXPIw2gdkrM8EOatD2KzSL7VCpGTC~TPghG9JcN51F5nZd9m5IblB-Udq4OVTXHiHmi9akbtAoYGSX4fV78sVN7y-N5Uw9z2yyPekgBqzxGHWBIZaf1Ql3EZQ6zdHjQm0v~VXqhn60mMo812JWRdE_&Key-Pair-Id=APKAILW5I44IHKUN2DYA&hint=flv" "<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item id="http://video-http.media-imdb.com/MV5BMTQ5Nzc4MjM0NV5BMTFeQW1wNF5BbWU3MDUwMDkzMzM@.mp4?Expires=1329111776&amp;Signature=qQxgxY5YRG40k3RwdYTCoRbXPIw2gdkrM8EOatD2KzSL7VCpGTC~TPghG9JcN51F5nZd9m5IblB-Udq4OVTXHiHmi9akbtAoYGSX4fV78sVN7y-N5Uw9z2yyPekgBqzxGHWBIZaf1Ql3EZQ6zdHjQm0v~VXqhn60mMo812JWRdE_&amp;Key-Pair-Id=APKAILW5I44IHKUN2DYA&amp;hint=flv" parentID="http://video-http.media-imdb.com/MV5BMTQ5Nzc4MjM0NV5BMTFeQW1wNF5BbWU3MDUwMDkzMzM@.mp4?Expires=1329111776&amp;Signature=qQxgxY5YRG40k3RwdYTCoRbXPIw2gdkrM8EOatD2KzSL7VCpGTC~TPghG9JcN51F5nZd9m5IblB-Udq4OVTXHiHmi9akbtAoYGSX4fV78sVN7y-N5Uw9z2yyPekgBqzxGHWBIZaf1Ql3EZQ6zdHjQm0v~VXqhn60mMo812JWRdE_&amp;Key-Pair-Id=APKAILW5I44IHKUN2DYA&amp;hint=flv" restricted="0"><dc:title>"10,000 BC"</dc:title><dc:date></dc:date><upnp:class>object.item.videoItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo="file-get:*:*::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000" protection="" tokenType="0" bitrate="0" duration="" size="" colorDepth="0" ifoFileURI="" resolution="">"http://video-http.media-imdb.com/MV5BMTQ5Nzc4MjM0NV5BMTFeQW1wNF5BbWU3MDUwMDkzMzM@.mp4?Expires=1329111776&amp;Signature=qQxgxY5YRG40k3RwdYTCoRbXPIw2gdkrM8EOatD2KzSL7VCpGTC~TPghG9JcN51F5nZd9m5IblB-Udq4OVTXHiHmi9akbtAoYGSX4fV78sVN7y-N5Uw9z2yyPekgBqzxGHWBIZaf1Ql3EZQ6zdHjQm0v~VXqhn60mMo812JWRdE_&amp;Key-Pair-Id=APKAILW5I44IHKUN2DYA&amp;hint=flv"</res></item></DIDL-Lite>"


notice how the single quote ' at the beginning and end of string gets interpreted as a double quote " and so of coarse does not resolve the issue

oh and yes, I'm using notepad++ without syntax highlighting this would be nearly impossible LOL
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4011
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: my next crazy idea - trailers   

Postby mad_ady » Sun Feb 12, 2012 11:12 pm

meta looks fine, but when you are sending the command you are enclosing the meta string inside double quotes instead of single quotes and you run into the original problem again.

Execute the command with meta inside single quotes
Code: Select all
bla bla + " '" + meta + "' "


so the quoting is double quotes, single quote, double quotes, concatenated with meta and etc.
User avatar
mad_ady
Developer
 
Posts: 2999
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: my next crazy idea - trailers   

Postby KAD » Mon Feb 13, 2012 8:38 am

doh, :oops:

ok, now I realize, it keep weaking the section where I generate meta
but it's the line using the meta that needs to be adjusted
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4011
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: my next crazy idea - trailers   

Postby KAD » Mon Feb 13, 2012 6:53 pm

took a while to get it through my thick head, but here's the solution

Code: Select all
var meta = ("<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"><item id=\"" + Trailer + "\" parentID=\"" + Trailer + "\" restricted=\"0\"><dc:title>" + Title + "</dc:title><dc:date></dc:date><upnp:class>object.item.imageItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo=\"file-get:*:*::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000\" protection=\"\" tokenType=\"0\" bitrate=\"0\" duration=\"\" size=\"\" colorDepth=\"0\" ifoFileURI=\"\" resolution=\"\">" + Trailer + "</res></item></DIDL-Lite>");
   var meta1 = meta.replace(/&/g, "&amp;");
   res1 = executeCmd("upnp-cmd SetAVTransportURI \"" + Trailer + "\" " + "\'" + meta1 + "\'",2);
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4011
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: my next crazy idea - trailers   

Postby mad_ady » Mon Feb 13, 2012 10:26 pm

Congrats. Although there is no need to escape the single quote, but it is easier to read.
User avatar
mad_ady
Developer
 
Posts: 2999
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: my next crazy idea - trailers   

Postby KAD » Wed Feb 15, 2012 8:24 pm

so do you guys ever get tired of answering my questions :P

I've got a couple of them tonight

1. I'm trying to get an additional image to show up and just can't seem to do it
the idea is after initiating playback sometimes you wait 5 or 10 seconds for playback to begin, sitting wondering if anything is going to happen
the image would be an indication the the trailer is being loaded

Still some additional onpagecreated items to do, but the above image listed is done

2. any idea how to ensure this does not run when browsing photo's or music
on the + side, I found out this works inside network shares as well
edit: I guess maybe an on menuselect to disable/enable
select video - enable
select music or photo - disable
Solved

3. once the above is fixed, I'll look at a download option, you'll see I have a few lines in the code already, but they are more like notes at this point, but if you've got any feedback on it download works but still needs some polish

besides that 25 downloads on that functional beta with no complaints, I guess that means it was actually working better than I originally thought

here's the code as it sits
there's been a lot of fixes

Code: Select all
// Trailer Plugin WDTVExt plugin by KAD (2012)
//
//
/*
# meta-name="Trailer"
# meta-desc="WDTVExt Trailer"
# meta-author="KAD"
# meta-date="2012-02-12"
# meta-version="1.0.0"
# meta-type="wdtvext"
# meta-url="http://forum.wdlxtv.com"
# meta-filename="Trailer.plugin.js"
*/
traceln("Start loading Trailer Plugin");

function TrailerPlugin(path) {
   this.rootPath = path;
   this.debug = new Debug();
   this.debug.Enable = true;
   this.debug.Prefix = "Trailer:";
   var dLevel = getConfigSetting("Trailer_DEBUG",this.debug.Lib);
   this.debug.Level = (dLevel === "") ? 0 : dLevel;
   this.debug.Level = 5;
   this.debug.Lib = (this.debug.Level > 2) ? this.debug.Level - 2 : 0;
   this.debug.Log(" path: " + this.rootPath, 1);
   this.SearchName = "SearchName";
   this.SearchStream = "IMDBID";
   this.trailerid = "TrailerID";
   this.currentTrailer = "Trailer"
   this.Format = getConfigSetting("TRAILER_RESOLUTION",this.debug.Lib);
   this.Path = getConfigSetting("TRAILER_DOWNLOAD_PATH",this.debug.Lib);
   this.showICON = "Icon";
   this.Title = "Title";
   var LoadingScreen = ( this.rootPath + "osd/Loading.jpg" );
   this.LoadingScreen = "LoadingScreen";
   this.TrailerIcon = "Trailer_Icon";
   this.NowLoading = false;
   
   result1 = executeCmd("ln -s " + this.rootPath + "var/www/addons/config/plugins/TRAILER_wec.php /tmp/config-plugins/TRAILER_wec.php");
}

TrailerPlugin.prototype = new Plugin()
TrailerPlugin.prototype.constructor = TrailerPlugin;

TrailerPlugin.prototype.onPageCreated = function(page) {
   this.debug.Log("[ onPageCreated ]")
   if ((page.markupFileName === "basic_browse.xml") ||
      (page.markupFileName === "basic_browse_thumb_video.xml") ||
      (page.markupFileName === "basic_browse_thumb.xml")) {
      if (this.NowLoading === false) {
         if (!page.extraContent) {
            page.extraContent = ""
         }
         var extraContent = <wrapper disable="@@my_Trailer_Icon_disable">
            <image image="@@Trailer_Icon" x="40" y="40" w="200" h="250" scale="100" bg="0" disable="@@my_Trailer_Icon_disable" />
         </wrapper>;
      }
      if (this.NowLoading === true) {
         var extraContent = <wrapper disable="@@Loading_Icon_disable">
            <image image="@@LoadingScreen" x="0" y="0" w="1280" h="720" bg="0" disable="@@Loading_Icon_disable" />
         </wrapper>;
      }
      addExtraContent(page, extraContent, this.LibDebug)
      this.debug.Log("[onPageCreated] added extra content.", 2);
   }
}

TrailerPlugin.prototype.onPageKey = function(page, key) {
   this.debug.Log("[onPageKey] page: " + page.markupFileName + "   key: " + key, 2);
   if (page.isMediaListPage) {
      if ((page.markupFileName === "basic_browse.xml") ||
      (page.markupFileName === "basic_browse_thumb_video.xml") ||
      (page.markupFileName === "basic_browse_thumb.xml")) {
      this.debug.Log("[ onPageKey ] (isMediaListPage) key: " + key, 1);
      this.setSearchName(page);
      this.setTrailerICON(page);
      if (key == 53)
         this.playTrailer();
      if (key == 64 || key == 32 || key == 33 || key ==29 || key == 28)
         this.selectionFix(page);
      }
   }
}

TrailerPlugin.prototype.onPageEnter = function (page) {
    if (page.isMediaListPage) {
   if ((page.markupFileName === "basic_browse.xml") ||
      (page.markupFileName === "basic_browse_thumb_video.xml") ||
      (page.markupFileName === "basic_browse_thumb.xml")) {      
   this.debug.Log("[ onPageEnter ] (isMediaListPage) page: " + page.markupFileName,1);
      this.selectionFix(page);
      }
   }
}

TrailerPlugin.prototype.selectionFix = function() {
    this.debug.Log("[ selectionFix ]", 2);
    system("oneDelaySelectionFix");
}

TrailerPlugin.prototype.onPageLeave = function(page) {
   this.debug.Log("[onPageLeave] page: " + page.markupFileName, 3);
   if (page.markupFileName === "video_ex_playing.xml") {
      Page.Top.setParam("Loading_Icon_disable", "1")
      this.NowLoading = false;
   }
}

TrailerPlugin.prototype.TrailerDownload = function() {
   this.debug.Log("[ TrailerDownload]: ", 3);
   if ( this.Path == "" ) {
      var Path = (Path);
   } else {
      var Path = this.Path;
   }
   Download = executeCmd("wget -O -P" + Path + "\"" + Trailer + " --output-document=" + Title + "_Trailer.mp4");
}

TrailerPlugin.prototype.setTrailerICON = function(page) {
   this.debug.Log("[setTrailerICON] ", 2);
   var Trailer_Icon = (this.rootPath + "osd/icon.png");
   this.TrailerIcon = Trailer_Icon;
   if (this.currentTrailer != "") {
      Page.Top.setParam("Trailer_Icon", this.TrailerIcon);
      Page.Top.setParam("my_Trailer_Icon_disable", "0")
      this.debug.Log("[setTrailerICON] enabled " + this.TrailerIcon,1);
   } else {
      Page.Top.setParam("Trailer_Icon", "");
      Page.Top.setParam("my_Trailer_Icon_disable", "1")
      this.debug.Log("[setTrailerICON] disabled",1);
   }
}

TrailerPlugin.prototype.playTrailer = function() {
   this.NowLoading = true;
   Page.Top.setParam("LoadingScreen", this.LoadingScreen);
   Page.Top.setParam("Loading_Icon_disable", "0")
   Page.Top.redraw(true);
   this.debug.Log("[setLoadingImage] enabled ",1);
   var Trailer = this.currentTrailer;
   var Title = this.Title;
   var meta = ("<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"><item id=\"" + Trailer + "\" parentID=\"" + Trailer + "\" restricted=\"0\"><dc:title>" + Title + "</dc:title><dc:date></dc:date><upnp:class>object.item.imageItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo=\"file-get:*:*::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000\" protection=\"\" tokenType=\"0\" bitrate=\"0\" duration=\"\" size=\"\" colorDepth=\"0\" ifoFileURI=\"\" resolution=\"\">" + Trailer + "</res></item></DIDL-Lite>");
   var meta1 = meta.replace(/&/g, "&amp;");
   res1 = executeCmd("upnp-cmd SetAVTransportURI \"" + Trailer + "\" " + "\'" + meta1 + "\'",2);
   res2 = executeCmd("upnp-cmd Play", 3);
   this.debug.Log("  playTrailer: " + Trailer, 3);
}

TrailerPlugin.prototype.setSearchName = function(page) {
   this.debug.Log("[ setSearchName starting]", 1);
   Page.Top.setParam("SearchName", "");
   Page.Top.setParam("Trailer_Icon", "");
   Page.Top.setParam("Trailer", "");
   var Trailer = "";
   this.currentTrailer = Trailer;
   var media = page.selectedMedia;
   if (!media || media == "") {
      return;
   }
   var SearchName = "";
   if (media) {
      if (media.path.lastIndexOf('/') === media.path.length-1) { 
         var Path = (media.path);
         this.debug.Log("[ metafile folder Path]" + Path, 1);
         var metafile = executeCmd("find '" + media.path + "' -maxdepth 1 -name '" + media.name + ".*.tgmd'",this.debug.Lib); 
         this.debug.Log("[ metafile folder tgmd name]" + metafile, 1);
         var IMDBID = executeCmd("sed -n -e 's/.*<id>\\(.*\\)<\\/id>.*/\\1/p' \"" + metafile + "\"",this.debug.Lib);
         this.debug.Log("[ metafile folder tgmd ID]" + IMDBID, 1);
         this.SearchStream = IMDBID;
         Page.Top.setParam("IMDBID", this.SearchStream);
         if (this.SearchStream == "") { 
            var metafile = executeCmd("find '" + media.path + "' -maxdepth 1 -name '" + "*.nfo'",this.debug.Lib); 
            this.debug.Log("[ metafile folder nfo name]" + metafile, 1);
            var IMDBID = executeCmd("sed -n -e 's/.*<id>\\(.*\\)<\\/id>.*/\\1/p' \"" + metafile + "\"",this.debug.Lib);
            this.debug.Log("[ metafile folder nfo ID]" + IMDBID, 1);
            this.SearchStream = IMDBID;
            Page.Top.setParam("IMDBID", this.SearchStream);
         }
         if (this.SearchStream == "") { 
            SearchName = (media.name);
            this.debug.Log("[ setSearchName folder name]" + SearchName, 1);
            Page.Top.setParam("SearchName", SearchName);
            this.SearchName = SearchName;
            this.debug.Log("[ setSearchName folder path]" + media.path, 1);
            var NameSearchURL = ("http://app.imdb.com/find?q=" + SearchName);
            this.debug.Log("[ SearchName folder curl ]" + NameSearchURL, 2);
            var curl = new CurlEasy(NameSearchURL);
            if (curl.perform()) {
               var content = eval("(" + curl.responseText + ")");
               var result = content.data.results[0];
               var lists = result.list[0];
               if ( lists.tconst == null ) {
                  var Trailer = "";
                  this.currentTrailer = Trailer;
                  return;
               } else {
               var IMDBID = lists.tconst;
               this.debug.Log("[ SearchName folder IMDBID]" + IMDBID, 2);
               this.SearchStream = IMDBID;
               Page.Top.setParam("IMDBID", this.SearchStream);
               }
            }
         }
      } else {
         MediaPath = (media.path);
         var Path = MediaPath.substr(0, MediaPath.lastIndexOf('/')); 
         this.debug.Log("[ metafile file Path]" + Path, 1);
         var metafile = (media.path + ".tgmd"); 
         this.debug.Log("[ metafile file tgmd name]" + metafile, 1) 
         var IMDBID = executeCmd("sed -n -e 's/.*<id>\\(.*\\)<\\/id>.*/\\1/p' \"" + metafile + "\"",this.debug.Lib); 
         this.debug.Log("[ metafile file tgmd ID]" + IMDBID, 1);
         this.SearchStream = IMDBID;
         Page.Top.setParam("IMDBID", this.SearchStream);
         if (this.SearchStream == "" ) {
            var path = (media.path);
            var nfo1 = path.substr(0, path.lastIndexOf('.'));
            var metafile = (nfo1 + ".nfo");
            this.debug.Log("[ metafile file nfo name]" + metafile, 1)
            var IMDBID = executeCmd("sed -n -e 's/.*<id>\\(.*\\)<\\/id>.*/\\1/p' \"" + metafile + "\"",this.debug.Lib);
            this.SearchStream = IMDBID;
            Page.Top.setParam("IMDBID", this.SearchStream);
         }
         if (this.SearchStream == "" ) {
            file = (media.name);
            SearchName = file.substr(0, file.lastIndexOf('.'));
            this.debug.Log("[ setSearchName file name]" + SearchName, 1);
            Page.Top.setParam("SearchName", SearchName);
            this.SearchName = SearchName;
            var NameSearchURL = ("http://app.imdb.com/find?q=" + SearchName);
            this.debug.Log("[ SearchName file curl ]" + NameSearchURL, 2);
            var curl = new CurlEasy(NameSearchURL);
            if (curl.perform()) {
               var content = eval("(" + curl.responseText + ")");
               var result = content.data.results[0];
               this.debug.Log("[ SearchName folder IMDBID]" + result, 2);
               var lists = result.list[0];
               if ( lists.tconst == null ) {
                  var Trailer = "";
                  this.currentTrailer = Trailer;
                  return;
               } else {
               var IMDBID = lists.tconst;
               this.debug.Log("[ SearchName file IMDBID]" + IMDBID, 2);
               this.SearchStream = IMDBID;
               Page.Top.setParam("IMDBID", this.SearchStream);
               }
            }
         }
      }
   }
   
   var SearchID = ("http://app.imdb.com/title/maindetails?tconst=" + IMDBID);
   this.debug.Log("[ get video id curl ]" + SearchID, 2);
   var curl2 = new CurlEasy(SearchID);
   if (curl2.perform()) {
      var content2 = eval("(" + curl2.responseText + ")");
      var Title = content2.data.title;
      this.Title = Title;
      Page.Top.setParam("Title", this.Title);
      if ( content2.data.trailer == null ) {
      var Trailer = "";
      this.currentTrailer = Trailer;
         return;
      } else {
      var TrailerID = content2.data.trailer.id;
      this.debug.Log("[ get video id] " + TrailerID, 2);   
      }
   }
   this.trailerid = TrailerID;
   Page.Top.setParam("TrailerID", this.trailerid);
   
   if (this.Format == "") {
      this.Format = "240p";
   }
   
   var URL = ("http://www.imdb.com/video/imdb/" + this.trailerid + "/html5?format=" + this.Format);
   this.debug.Log("[ get real URL ]" + URL, 2);
   this.URL = URL;
   var curl3 = new CurlEasy(URL);
   if (curl3.perform()) {
      var StreamHTML = curl3.responseText;
      StreamHTML.match(/mp4_h264\s+:\s+\'([^\']+)\'/);
      var Trailer = RegExp.$1;
      this.currentTrailer = Trailer;
      this.debug.Log("[ Real URL ]" + Trailer, 2);
   }
}

TrailerPlugin.instance = new TrailerPlugin(scriptPath);
Plugin.registerPlugin(TrailerPlugin.instance);
traceln("End loading Trailer Plugin");
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4011
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: my next crazy idea - trailers   

Postby KAD » Sat Feb 18, 2012 12:57 am

ok, here's a real stumper

this chunk of code has 2 sections, 1 for folders and 1 for files
folders
Code: Select all
if (this.Path != "") {
      var Path = this.Path;
      if (media.path.lastIndexOf('/') === media.path.length-1) {
         var LocalTrailer = executeCmd("find '" + Path + "' -maxdepth 1 -name '." + media.name + "_Trailer.mp4'",this.debug.Lib);
         var Trailer = LocalTrailer;
         var Title = media.name;
         this.Title = Title;
         this.currentTrailer = Trailer;
         if (this.currentTrailer != "") {
            this.PlayLocal = true;
            return;
         }

this works correctly
if file exist it returns and runs other items
if file does not exist it simply continues to the next code as it should

for files
Code: Select all
} else {
         var file = media.name;
         var SearchName = file.substr(0, file.lastIndexOf('.'));
         var LocalTrailer = executeCmd("find '" + Path + "' -maxdepth 1 -name '." + SearchName + "_Trailer.mp4'",this.debug.Lib);
         var Trailer = LocalTrailer;
         this.Title = SearchName;
         this.currentTrailer = Trailer;
         if (this.currentTrailer != "") {
            this.PlayLocal = true;
            return;
         }
      }
   }

this works if file exist
if file does not exist the code just stops at this line
Code: Select all
if (this.currentTrailer != "") {

instead of continuing

KAD
If you like my work please consider a Donation. Donate
Please read the appropriate documentation before posting questions! READ ME FAQ WIKI
User avatar
KAD
Global Moderator
 
Posts: 4011
Joined: Mon Apr 12, 2010 4:59 pm
Location: Seattle, WA USA

Re: my next crazy idea - trailers   

Postby recliq » Sat Feb 18, 2012 1:39 am

hm, try this
Code: Select all
if (this.currentTrailer) {
  if (this.currentTrailer != "") {
    this.PlayLocal = true;
    return;
  }
}
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5022
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

PreviousNext

Return to WDTVExt discussion

Who is online

Users browsing this forum: No registered users and 0 guests