linterna-magica-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linterna-magica-commit] [51] Add support for preferred HD links.


From: Ivaylo Valkov
Subject: [linterna-magica-commit] [51] Add support for preferred HD links.
Date: Thu, 28 Apr 2011 13:32:07 +0000

Revision: 51
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=51
Author:   valkov
Date:     2011-04-28 13:32:07 +0000 (Thu, 28 Apr 2011)
Log Message:
-----------
Add support for preferred HD links. Closes taks #11085.

Modified Paths:
--------------
    trunk/HELP
    trunk/HELP.bg
    trunk/src/lm_config_options.js
    trunk/src/lm_constructors.js
    trunk/src/lm_create_video_object.js
    trunk/src/lm_init_options.js

Added Paths:
-----------
    trunk/src/lm_compute_preferred_hd_link.js

Modified: trunk/HELP
===================================================================
--- trunk/HELP  2011-04-27 10:21:41 UTC (rev 50)
+++ trunk/HELP  2011-04-28 13:32:07 UTC (rev 51)
@@ -17,6 +17,7 @@
     "locale": "auto",
     "cookies": "restore",
     "wait_dm": "off",
+    "quality": "low",
  };
 
 Since version 0.0.10 it is possible to keep your configuration in
@@ -102,6 +103,17 @@
            Don't wait (default)
        <integer>
             Wait for <integer> milliseconds.
+  quality
+      Preferred video quality.
+       low/medium/high
+           Automatically select the link for low/medium/high from the
+           list of links (default low)
+       <number>
+           Start the <number> link from the list. If not available
+           the highest quality. Use "1" for lowest quality.
+       <number>%
+           Start the link that corresponds to <number> percent from
+           the list. Float numbers are allowed - 34.56%, 18,6%.
 
 A note on updates
 

Modified: trunk/HELP.bg
===================================================================
--- trunk/HELP.bg       2011-04-27 10:21:41 UTC (rev 50)
+++ trunk/HELP.bg       2011-04-28 13:32:07 UTC (rev 51)
@@ -16,6 +16,7 @@
     "locale": "auto",
     "cookies": "restore",
     "wait_dm": "off",
+    "quality": "low",
  };
 
 От версия 0.0.10 е възможно да запишете настройките си в отделен
@@ -103,8 +104,20 @@
            Да не се изчаква (стандартно)
        <цяло число>
              Да се изчаква <цяло число> милисекунди.
+  quality
+      Предпочитано качество за видео клиповете
+       low/medium/high
+           Автоматичен избор на връзката за ниско/средно/високо
+           качество (стандартно най-ниско качество – low)
+       <число>
+           Стартиране на връзката с номер <число> (цяло) от списъка с
+           връзки. Най-високо качество, ако липсва. Използвайте „1“
+           за най-ниско.
+       <число>%
+           Стартиране на връзката, която съответства на <число>
+           процента от списъка с връзки. Възможно е да задавате
+           дробни стойности – 34.56%, 18,6%.
 
-
 Бележка относно проверката за нови версии:
 
 Linterna Mágica проверява за обновления всеки път, когато е достигнат

Added: trunk/src/lm_compute_preferred_hd_link.js
===================================================================
--- trunk/src/lm_compute_preferred_hd_link.js                           (rev 0)
+++ trunk/src/lm_compute_preferred_hd_link.js   2011-04-28 13:32:07 UTC (rev 51)
@@ -0,0 +1,62 @@
+//  @licstart The following is the entire license notice for the
+//  JavaScript code in this page (or file).
+//
+//  This file is part of Linterna Mágica
+//
+//  Copyright (C) 2011  Ivaylo Valkov <address@hidden>
+//
+//  The JavaScript code in this page (or file) is free software: you
+//  can redistribute it and/or modify it under the terms of the GNU
+//  General Public License (GNU GPL) as published by the Free Software
+//  Foundation, either version 3 of the License, or (at your option)
+//  any later version.  The code is distributed WITHOUT ANY WARRANTY
+//  without even the implied warranty of MERCHANTABILITY or FITNESS
+//  FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
+//
+//  As additional permission under GNU GPL version 3 section 7, you
+//  may distribute non-source (e.g., minimized or compacted) forms of
+//  that code without the copy of the GNU GPL normally required by
+//  section 4, provided you include this license notice and a URL
+//  through which recipients can access the Corresponding Source.
+//
+//  @licend The above is the entire license notice for the JavaScript
+//  code in this page (or file).
+//
+// @source http://e-valkov.org/linterna-magica
+
+// END OF LICENSE HEADER
+
+// Compute which HD link should be used for playback according to user
+// preferences.
+LinternaMagica.prototype.compute_preferred_hd_link = function(hd_links)
+{
+    var preferred_link_index = null;
+
+    if (this.preferred_hd_quality > 0)
+    {
+       // Link number
+       if (hd_links[this.preferred_hd_quality])
+       {
+           // Exact match
+           preferred_link_index = this.preferred_hd_quality;
+       }
+       else
+       {
+           // Must be higher then the total number of links. Choose
+           // highest.
+           preferred_link_index = hd_links.length;
+       }
+    }
+    else if (this.preferred_hd_quality < 0)
+    {
+       // In Percents
+       // See https://savannah.nongnu.org/task/index.php?11085
+
+       // This is negative on purpose, so it could be detected in
+       // this if block.
+       var quality = Math.abs(this.preferred_hd_quality);
+       preferred_link_index = Math.floor(((hd_links.length)*quality));
+    }
+
+    return Math.abs(hd_links.length-preferred_link_index);
+}

Modified: trunk/src/lm_config_options.js
===================================================================
--- trunk/src/lm_config_options.js      2011-04-27 10:21:41 UTC (rev 50)
+++ trunk/src/lm_config_options.js      2011-04-28 13:32:07 UTC (rev 51)
@@ -221,3 +221,56 @@
 
     this.lang = set_lang_to;
 }
+
+// Set the preferred video quality 
+LinternaMagica.prototype.set_hd_link_quality = function(quality)
+{
+    var set_quality_to = quality ? quality : "low";
+    var err = null;
+    
+    if (!/^(low|medium|high|[0-9]+|[0-9.,]+%)$/i.test(set_quality_to) ||
+       /^low$/i.test(set_quality_to))
+    {
+       // Low
+       set_quality_to = -0.33;
+    }
+    else if (/^medium$/i.test(set_quality_to))
+    {
+       // Medium
+       set_quality_to = -0.66;
+    }
+    else if (/^high$/i.test(set_quality_to))
+    {
+       // High
+       set_quality_to = -1;
+    }
+     else if (/^[0-9]+$/i.test(set_quality_to))
+    {
+       // Set to link number
+       set_quality_to = parseInt(set_quality_to);
+       if (!set_quality_to)
+       {
+           err = 1;
+       }
+    }
+    else if (/^[0-9.,]+%$/i.test(set_quality_to))
+    {
+       // parseFloat accepts only "." for separator.
+       set_quality_to = set_quality_to.replace(/,/g,".");
+
+       // Set to percent
+       set_quality_to = - parseFloat(set_quality_to)/100;
+       if (isNaN(set_quality_to))
+       {
+           err = 1;
+       }
+    }
+
+    if (err) 
+    {
+       // Low
+       set_quality_to = -0.33;
+    }
+
+    this.preferred_hd_quality = set_quality_to;
+}

Modified: trunk/src/lm_constructors.js
===================================================================
--- trunk/src/lm_constructors.js        2011-04-27 10:21:41 UTC (rev 50)
+++ trunk/src/lm_constructors.js        2011-04-28 13:32:07 UTC (rev 51)
@@ -101,6 +101,7 @@
     this.set_cookies(params.cookies);
     this.set_wait_dailymotion(params.wait_dm);
     this.set_check_updates(params.updates);
+    this.set_hd_link_quality(params.quality);
 
     // check_for_updates() MUST be called only if there is video object
     // found. The only place where the user can be informed is in the

Modified: trunk/src/lm_create_video_object.js
===================================================================
--- trunk/src/lm_create_video_object.js 2011-04-27 10:21:41 UTC (rev 50)
+++ trunk/src/lm_create_video_object.js 2011-04-28 13:32:07 UTC (rev 51)
@@ -133,6 +133,16 @@
     // Create HD links
     if (object_data.hd_links)
     {
+       var preferred_link = 
+           this.compute_preferred_hd_link(object_data.hd_links);
+
+       // No link is calculated. Set to lowest.
+       if (preferred_link == null || isNaN(preferred_link))
+       {
+           preferred_link = 
+               object_data.hd_links[object_data.hd_links.length-1];
+       }
+
        var hd_wrapper = document.createElement("div");
        var hd_button = document.createElement("a");
        hd_button.setAttribute("href","#");
@@ -174,10 +184,16 @@
            button.addEventListener("click",
                                    button_click_function , false);
 
-           // Selected link. Default it is the lowest quality.
-           if (link == (object_data.hd_links.length-1))
+           // Preferred link 
+           if (link == preferred_link)
            {
+               // Set the link in the interface
                this.select_hd_link_in_list(button,id);
+
+               // Set the link for the player and download link.
+               object_data.link = object_data.hd_links[link].url;
+               dw_link.setAttribute("href",
+                                    object_data.hd_links[link].url);
            }
 
            li.appendChild(button);
@@ -205,7 +221,7 @@
                                  log_link_click_function, false);
 
        header.appendChild(log_link);
-       // Hide the web log, so it accessible only from interface.
+       // Hide the web log, so it is accessible only from the interface.
        var log = document.getElementById("linterna-magica-web-log");
        log.style.setProperty("display","none", "important");
     }

Modified: trunk/src/lm_init_options.js
===================================================================
--- trunk/src/lm_init_options.js        2011-04-27 10:21:41 UTC (rev 50)
+++ trunk/src/lm_init_options.js        2011-04-28 13:32:07 UTC (rev 51)
@@ -81,6 +81,18 @@
        // off/no/disabled/false/0: Don't wait (defult)
         // <integer>: Wait for <integer> milliseconds.
        "wait_dm": "off",
+       // Preferred video quality.
+       //
+       // low/medium/high: Automatically select the link for
+       // low/medium/high from the list of links (default low)
+       //
+       // <number>: Start the <number> link from the list. If not
+       // available the highest quality. Use "1" for lowest quality.
+       //
+       // <number>%: Start the link that corresponds to <number>
+       // percent from the list. Float numbers are allowed - 34.56%,
+       // 18,6%.
+       "quality": "low",
     };
 
 // NO MINIMISATION ABOVE THIS LINE




reply via email to

[Prev in Thread] Current Thread [Next in Thread]