Ver Mensaje Individual
  #10 (permalink)  
Antiguo 26/01/2014, 10:01
Avatar de jja
jja
 
Fecha de Ingreso: diciembre-2010
Ubicación: BCN
Mensajes: 47
Antigüedad: 13 años, 4 meses
Puntos: 0
Pregunta Respuesta: Descargar transcripción de videos de youtube

He estado estudiando el código JAVA de la única aplicacion que me ha funcionado con todos los videos que he probado, en cualquier idioma, que es GOOGLE2SRT. Y he visto estas dos funciones donde parece que está la miga:

Código Java:
Ver original
  1. public static String getListURL(Method method, HashMap<String, String> otherparams) throws UnsupportedEncodingException {
  2.         String s;
  3.         switch (method) {
  4.             case Google:
  5.                 s = "http://video.google.com/videotranscript?frame=c&type=list&docid=" + otherparams.get("docid"); //+ id;
  6.                 System.out.println("(DEBUG) List URL: " + s);
  7.                 return s;
  8.             // Subtitles only (until v0.5.6)
  9.             //    s = "http://video.google.com/timedtext?type=list&v=" + id;
  10.             //    System.out.println("(DEBUG) Tracks list URL: " + s);
  11.             //    return s;
  12.             case YouTubeLegacy: // Subtitles and translations (from v0.6) using "legacy method"
  13.                 s = "http://video.google.com/timedtext?type=list&tlangs=1&v=" + otherparams.get("v");
  14.                 System.out.println("(DEBUG) Tracks with targets list URL (Legacy): " + s);
  15.                 return s;
  16.             case YouTubeSignature:
  17.                 /* ORIGINAL "Magic" URL example
  18.                 * http://www.youtube.com/api/timedtext?
  19.                 *      key=yttt1&
  20.                 *      hl=en_US&
  21.                 *      expire=1372005633&
  22.                 *      sparams=asr_langs,caps,v,expire&
  23.                 *      signature=4FE7A8E1FAAE338EAB840B58F3E05D1963F5550D.CE40D0149565FE4035DD4E914C144E864CE28302&
  24.                 *      caps=asr&
  25.                 *      v=L1hIAF5YvN0&
  26.                 *      asr_langs=ko,de,ja,pt,en,it,nl,es,ru,fr
  27.                 *
  28.                 * REQUIRED URL result
  29.                 * http://www.youtube.com/api/timedtext?
  30.                 *      key=yttt1&
  31.                 *      expire=1372005633&
  32.                 *      sparams=asr_langs,caps,v,expire&
  33.                 *      signature=4FE7A8E1FAAE338EAB840B58F3E05D1963F5550D.CE40D0149565FE4035DD4E914C144E864CE28302&
  34.                 *      caps=asr&
  35.                 *      v=L1hIAF5YvN0&
  36.                 *      asr_langs=ko,de,ja,pt,en,it,nl,es,ru,fr&
  37.                 *
  38.                 *      asrs=1&
  39.                 *      tlangs=1&
  40.                 *      type=list
  41.                 *
  42.                */        
  43.                 s = "https://www.youtube.com/api/timedtext" +
  44.                        "?key=" + otherparams.get("key") +
  45.                        "&expire=" + otherparams.get("expire") +
  46.                        "&sparams=" + otherparams.get("sparams") +
  47.                        "&signature=" + otherparams.get("signature") +
  48.                        "&caps=" + otherparams.get("caps") +
  49.                        "&v=" + otherparams.get("v") +
  50.                        "&asr_langs=" + otherparams.get("asr_langs") +                      
  51.                        "&asrs=1&type=list&tlangs=1";
  52.             System.out.println("(DEBUG) ASR/tracks with targets list URL (Signature): " + s);
  53.             return s;
  54.         }
  55.         return null;
  56.     }
  57.    
  58.     public static String getMagicURL(String YouTubeWebSource) throws UnsupportedEncodingException {
  59.         String result, s;
  60.         String[] strings;
  61.        
  62.         // "ttsurl": "http:\/\/www.youtube.com\/api\/timedtext?key=yttt1\u0026hl=en_US\u0026expire=1372005633\u0026sparams=asr_langs%2Ccaps%2Cv%2Cexpire\u0026signature=4FE7A8E1FAAE338EAB840B58F3E05D1963F5550D.CE40D0149565FE4035DD4E914C144E864CE28302\u0026caps=asr\u0026v=L1hIAF5YvN0\u0026asr_langs=ko%2Cde%2Cja%2Cpt%2Cen%2Cit%2Cnl%2Ces%2Cru%2Cfr",
  63.         strings = YouTubeWebSource.split("ttsurl");
  64.         s = strings[1];
  65.         strings = s.split(",");
  66.         s = strings[0];
  67.         strings = s.split("\"");
  68.         s = strings[2];
  69.        
  70.         s = s.replace("\\/", "/");
  71.         s = s.replace("\\u0026", "&");
  72.        
  73.         result = URLDecoder.decode(s, "UTF-8");
  74.        
  75.         return result;
  76.     }

Al parecer prueba varias técnicas para descargar los videos, con la misma URL base pero con distintos parámetros.

No acabo de entender exactamente como funciona, pero el caso es que la aplicacion tira bien, asi que el truco va a ser ese...
__________________
El supremo arte de la guerra es someter al enemigo sin luchar.

Sun Tzu