function soundcloud() { global $web; $client_id = "b45b1aa10f1ac2941910a7f0d10f8e28"; $res = CargaWebCurl('https://api.sndcdn.com/search/sounds?facet=genre&limit=10&offset=0&linked_partitioning=1&client_id=' . $client_id . '&q=' . urlencode($web)); $resultados = array('buscador' => 'soundcloud.com', 'enlaces' => array()); $p1 = 0; for ($i = 0; $i < 10 && ($p1 = strpos($res, '"kind":"track"', $p1)); $i++) { //streamable? $p = strposF($res, '"streamable":', $p1); $f = strpos($res, ',', $p); $streamable = substr($res, $p, $f - $p); if ($streamable == "true") { //url $p = strposF($res, '"id":', $p1); $f = strpos($res, ",", $p); $modoUrl = "stream"; $url = 'http://api.soundcloud.com/tracks/' . substr($res, $p, $f - $p) . '/' . $modoUrl . '?client_id=' . $client_id; //título $p = strposF($res, '"title":"', $p1); $f = strpos($res, '"', $p); $tit = utf8_encode(jsonRemoveUnicodeSequences(substr($res, $p, $f - $p))); //duración $p = strposF($res, '"duration":', $p1); $f = strpos($res, ',', $p); $duracion = (double) substr($res, $p, $f - $p) / 1000; $min = (int) ($duracion / 60); $seg = $duracion - $min * 60; $seg = substr($seg, 0, 2); while (enString($seg, ".")) { $seg = "0" . substr($seg, 0, 1); } $duracion = $min . ":" . $seg; //peso /*$p=strposF($res,'"original_content_size":',$p1); $f=strpos($res,",",$p); $tam=substr($res,$p,$f-$p); $tam=((float)$tam)/1048576; $tam=substr($tam,0,strpos($tam,".")+2);*/ $r = array('url' => $url, 'titulo' => $tit, 'duracion' => $duracion, 'preview' => 1); $resultados['enlaces'][] = $r; } $p1++; } dbug_r($resultados); return $resultados; }
function univisionID($id) { dbug('univisionID'); $ret = 'http://cdn-download.mcm.univision.com/videos_mcm/' . $id . '.js'; dbug('url=' . $ret); $ret = CargaWebCurl($ret); if (enString($ret, "Access Denied")) { setErrorWebIntera("El vídeo de Univisión está bloqueado."); return; } $obtenido = array('enlaces' => array()); //imagen $imagen = entre1y2($ret, '"src_image_url":"', '"'); $imagen = strtr($imagen, array('\\' => '')); dbug('imagen=' . $imagen); //titulo $titulo = entre1y2($ret, '"def_title":"', '"'); $titulo = jsonRemoveUnicodeSequences($titulo); $titulo = limpiaTitulo($titulo); dbug('titulo=' . $titulo); if (!enString($ret, '"published_urls":[]')) { dbug('No aparece "published_urls":[]'); $json = substr($ret, strposF($ret, '(')); $json = substr($json, 0, strrpos($json, ')')); dbug_($json); $json = json_decode($json, true); dbug_r($json); $urls = array(); if (isset($json['published_urls'])) { foreach ($json['published_urls'] as &$url) { if (enString($url['embed_url'], '.mp4')) { $u =& $url['embed_url']; dbug_($u); $p = strrposF($u, '_'); $f = strpos($u, '.', $p); $calidad = substr($u, $p, $f - $p); $urls[] = array($u, $calidad); } } } dbug('urls: ' . count($urls)); //ya tenemos las urls en formato: /120615_2708697_El_Talisman_Capitulo_98_99___Ultimo_capitulo_1339800465_2000.mp4 //ordenar if (count($urls) > 0) { $urls = sortmulti($urls, 1, "123", true); } } if (enString($ret, '"published_urls":[]') || isset($urls) && count($urls) === 0) { dbug('No se pueden encontrar urls. Usando método 2'); // http://vmscdn-download.s3.amazonaws.com/videos_mcm/variant/2912557.m3u8 $m3u8FuenteUrls = 'http://vmscdn-download.s3.amazonaws.com/videos_mcm/variant/' . $id . '.m3u8'; dbug('$m3u8FuenteUrls = ' . $m3u8FuenteUrls); $m3u8FuenteUrls = CargaWebCurl($m3u8FuenteUrls); dbug($m3u8FuenteUrls); preg_match('@http://.*media(.*?)_[0-9]{3,4}.m3u8@', $m3u8FuenteUrls, $matches); dbug_r($matches); $urlBase = $matches[1]; $calidades = array(2000, 1200, 810, 800, 510, 500, 270, 150); $urls = array(); foreach ($calidades as $calidad) { $urlT = 'http://h.univision.com/media' . $urlBase . '_' . $calidad . '.mp4'; $urls[] = array($urlT, $calidad); } //ya tenemos las urls en formato: /120615_2708697_El_Talisman_Capitulo_98_99___Ultimo_capitulo_1339800465_2000.mp4 //ya está ordenado } $urls_length = count($urls); for ($i = 0; $i < $urls_length; $i++) { if ($urls[$i][1] == 2000) { $preContext = array('http' => array('method' => 'HEAD', 'header' => "User-agent: Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0\r\n" . "Connection: close\r\n" . "Accept-Language: es-ES,es;en-US;en\r\n" . "Accept: text/html,application/xhtml+xml,application/xml\r\n", 'timeout' => 5, 'ignore_errors' => '1')); $preContext = stream_context_create($preContext); if (file_get_contents($urls[$i][0], false, $preContext) === false) { dbug('no se puede abrir la url de calidad 2000'); continue; } dbug_r($http_response_header); if (strpos($http_response_header[0], ' 404 ')) { dbug('la url de calidad 2000 da 404'); continue; } } if (esVideoAudioAnon($urls[$i][0])) { $obtenido['enlaces'][] = array('url' => $urls[$i][0], 'url_txt' => 'Calidad: ' . $urls[$i][1] . " Kbps", 'tipo' => 'http'); } } for ($i = 0, $ii = count($json['captions']); $i < $ii; $i++) { if ($json['captions'][$i]['language'] === 'es') { $url = $json['captions'][$i]['url']; $obtenido['enlaces'][] = array('url_txt' => 'Subtítulos en formato ' . substr($url, strrposF($url, '.')), 'url' => $url, 'tipo' => 'srt'); } } $obtenido['titulo'] = $titulo; $obtenido['imagen'] = $imagen; $obtenido['alerta_especifica'] = 'Si no puedes descargar el vídeo necesitas usar proxy.<br/>Descarga el programa ultrasurf (<a href="https://ultrasurf.us/download/u.zip">Descargar ultrasurf</a>), descomprime el archivo, ejecuta el programa y una vez hecho intenta descargar el vídeo de nuevo.<br/>Si 2000kbps da error prueba 1200kbps.'; finalCadena($obtenido, false); }
$doc[] = array($decodeGoogle["results"]["0"]["geometry"]["location"]["lng"], $decodeGoogle["results"]["0"]["geometry"]["location"]["lat"]); $i++; usleep(120); } else { $adresseMapbox = "https://api.mapbox.com/v4/geocode/mapbox.places/{$adressePourUrl}.json?access_token=pk.eyJ1Ijoia2V2aW5zZSIsImEiOiJjaWZpZHhoOWkwMHdndGNseGRxc3A0d3U1In0.N5FbDKd9BQlcYh8bwsLVCA"; $moissonMapbox = get_file_contents_utf8($adresseMapbox); $decodeMapbox = json_decode($moissonMapbox, true); if (isset($decodeMapbox["features"]["0"]["geometry"]["coordinates"][0])) { //echo($i.'m '.$decodeMapbox["features"]["0"]["geometry"]["coordinates"][0].' '.$decodeMapbox["features"]["0"]["geometry"]["coordinates"][0]); //echo('<br>'); $doc[] = array($decodeMapbox["features"]["0"]["geometry"]["coordinates"][0], $decodeMapbox["features"]["0"]["geometry"]["coordinates"][1]); $i++; usleep(120); } else { //echo ('oups'. $address.'<br>'); $success = false; // API failed to transform address (RIP) } } } if ($success != false) { $sauvegardeResultats[] = $doc; } } $renvoi["company"] = $sauvegardeResultats; $fileGeoJSON = "company.geojson"; file_put_contents($fileGeoJSON, jsonRemoveUnicodeSequences($renvoi)); require_once "mapMarkups.php"; ?>
function calcula() { //Hay videos geobloqueados. pocos pero hay. OJO porque no irán /* POST a: es.medici.tv con: json=true&page=%2Fhenri-demarquette-charles-dutoit-royal-philharmonic-orchestra-annecy-classic-festival-2012&timezone_offset=-120 */ //comprobar que la web es correcta o fallar if (!enString($this->web, '#!')) { return; } $obtenido = array('enlaces' => array()); //aparentemente se puede. enviemoslo. $p = strposF($this->web, '#!'); $webFormateada = substr($this->web, $p); $cabecera = array("Host: es.medici.tv", "Content-type: application/x-www-form-urlencoded"); $post = 'json=true&page=' . urlencode($webFormateada) . '&timezone_offset=-120'; $ret = CargaWebCurl('http://es.medici.tv', $post); $ret = jsonRemoveUnicodeSequences($ret); dbug($ret); //imagen: //"main_image": "http:....jpg" $p = strposF($ret, '"main_image"'); $p = strposF($ret, '"', $p); $f = strpos($ret, '"', $p); $imagen = substr($ret, $p, $f - $p); dbug('imagen=' . $imagen); //titulo: //"title": "..." $p = strposF($ret, '"title"'); $p = strposF($ret, '"', $p); $f = strpos($ret, '"', $p); $titulo = substr($ret, $p, $f - $p); $titulo = limpiaTitulo($titulo); dbug('titulo=' . $titulo); //para las URL: //"url_smil": {"1": "http://medias.medici.tv/site/smil/20120822_full_en_1965_def_v2_low.mp4.smil", "3": "http://medias.medici.tv/site/smil/20120822_full_en_1965_def_v2_high.mp4.smil", "2": "http://medias.medici.tv/site/smil/20120822_full_en_1965_def_v2_mid.mp4.smil"} // Para url f4m válido agregar al final (&g=&hdcore=) if (enString($ret, 'manifest.f4m')) { $url_manifest = 'http://medicitvod' . entre1y2($ret, '"http://medicitvod', '"') . '&g=&hdcore='; dbug($url_manifest); $obtenido['enlaces'][] = array('url' => $url_manifest, 'tipo' => 'f4m', 'nombre_archivo' => generaNombreWindowsValido($titulo)); } elseif (enString($ret, 'url_smil')) { $p2 = strpos($ret, '.mp4'); $p1 = $p = 0; while ($p2 > $p1 && $p1 > -1) { $p1 = strpos($ret, '{', $p1 + 1); if ($p1 < $p2) { $p = $p1; } } $f = strpos($ret, '}', $p); $URLs = substr($ret, $p, $f - $p); dbug($URLs); $videos = substr_count($URLs, '":'); dbug('total videos=' . $videos); $calidades = array(3 => 'Calidad Alta', 2 => 'Calidad Media', 1 => 'Calidad Baja'); for ($i = $videos; $i > 0; $i--) { //encontrar la url del archivo smil $p = strpos($URLs, '"' . $i . '"') + strlen('"' . $i . '"'); $p = strposF($URLs, '"', $p); $f = strpos($URLs, '"', $p); $preURL_RTMP = substr($URLs, $p, $f - $p); dbug($URLs); //cambiar de rtmp a http $preURL_HTTP = substr($preURL_RTMP, 0, -1) . "0"; $URL = $preURL_HTTP; $tipo = 'http'; dbug($URL); if ($tipo == 'http') { $obtenido['enlaces'][] = array('url' => $URL, 'tipo' => $tipo, 'url_txt' => $calidades[$i]); } else { $obtenido['enlaces'][] = array('titulo' => $calidades[$i], 'url' => $URL, 'tipo' => $tipo); } } } $obtenido['titulo'] = $titulo; $obtenido['imagen'] = $imagen; finalCadena($obtenido); }
$concatAdresse = trim($stagiaire[9]) . " " . trim($stagiaire[11]); $adressePourUrl = urlencode($concatAdresse); $adresseGoogle = "http://maps.google.com/maps/api/geocode/json?address={$adressePourUrl}&sensor=false"; print_r($stagiaireTraite); if ($i < $limiteTest && count($stagiaireTraite) < 13) { $moissonGoogle = file_get_contents_utf8($adresseGoogle); $decodeGoogle = json_decode($moissonGoogle, true); if ($decodeGoogle[results][0]["geometry"]["location"]["lat"]) { $stagiaireTraite[] = array($decodeGoogle[results][0]["geometry"]["location"]["lng"], $decodeGoogle[results][0]["geometry"]["location"]["lat"]); $i++; usleep(120); } else { $adresseMapbox = "https://api.mapbox.com/v4/geocode/mapbox.places/{$adressePourUrl}.json?access_token=pk.eyJ1Ijoia2V2aW5zZSIsImEiOiJjaWZpZHhoOWkwMHdndGNseGRxc3A0d3U1In0.N5FbDKd9BQlcYh8bwsLVCA"; $moissonMapbox = file_get_contents_utf8($adresseMapbox); $decodeMapbox = json_decode($moissonMapbox, true); if ($decodeMapbox[features][0]["geometry"]) { $stagiaireTraite[] = array($decodeMapbox[features][0]["geometry"]["coordinates"][0], $decodeMapbox[features][0]["geometry"]["coordinates"][1]); $i++; usleep(120); } else { $stagiaireTraite[] = false; // Aucune API n'a réussi à convertir l'adresse (RIP) } } } $sauvegardeResultats[] = $stagiaireTraite; } $renvoi["polyMap"] = $sauvegardeResultats; $fichier = "../files/studentsPolytech2.geojson"; file_put_contents($fichier, jsonRemoveUnicodeSequences($renvoi));
function calcula() { //soundcloud va a base de https, por lo que si alguna url http consigue llegar, toca pasarla a https $this->web = strtr($this->web, array("http://" => "https://")); $retfull = CargaWebCurl($this->web); $obtenido = array('enlaces' => array()); //<img class="waveform" src="http://w1.sndcdn.com/9y15N1tRAubf_m.png" unselectable="on" /> //detectar si hay varios enlaces o solo uno $canciones = substr_count($retfull, '<img class="waveform"'); //dbug('total canciones='.$canciones); $imagen = 'http://www.' . DOMINIO . '/canales/soundcloud.png'; //no sabemos cuantas queremos, pero es del modo nuevo y posiblemente varias. if (enString($retfull, "Next SoundCloud") || true) { dbug('Next SoundCloud'); $client_id = 'b45b1aa10f1ac2941910a7f0d10f8e28'; /* Lista de ids de clientes: Plug.dj => bd7fb07288b526f6f190bfd02b31b25e */ $carga = CargaWebCurl('https://api.sndcdn.com/resolve?url=' . $this->web . '&_status_code_map[302]=200&_status_format=json&client_id=' . $client_id, '', 0, '', array(), false); dbug_($carga); if (enString($carga, 'tracks/')) { //una cancion dbug('Una canción'); //Descargar la web para comprobar título y si tiene descarga gratis $carga = CargaWebCurl(entre1y2($carga, '"location":"', '"')); //comprobar si es stremeable. Si no lo es, fin del programa if (enString($carga, '<streamable type="boolean">false')) { setErrorWebIntera('La descarga de esta canción está bloqueada.'); return; } preg_match('#tracks/([0-9]+)#', $carga, $match); $uri = $match[1]; dbug($uri); $url = 'http://api.soundcloud.com/tracks/' . $uri . '/stream?client_id=' . $client_id; //titulo $titulo = entre1y2($this->web_descargada, '<title>', '</'); if (enString($carga, "<artwork-url>")) { $imagen = entre1y2($carga, '<artwork-url>', '</'); } if (enString($carga, '<downloadable type="boolean">true') || enString($carga, '"downloadable":true')) { $url = 'http://api.soundcloud.com/tracks/' . $uri . '/download?client_id=' . $client_id; } array_push($obtenido['enlaces'], array('url' => $url, 'tipo' => 'http', 'extension' => 'mp3')); dbug($titulo . ' - ' . $url); } else { //varias canciones dbug('Varias canciones'); //titulo generico $titulo = "SoundCloud"; //recortar web para sacar solo la id del user $f = strpos($this->web, '/', 8); $f2 = strpos($this->web, '/', $f + 1); if ($f2 > 0) { $webMod = substr($this->web, 0, $f2); } else { $webMod = $this->web; } //https://api.sndcdn.com/resolve?url=https%3A//soundcloud.com/forestrf&_status_code_map[302]=200&_status_format=json&client_id=b45b1aa10f1ac2941910a7f0d10f8e28 $id = CargaWebCurl('https://api.sndcdn.com/resolve?url=' . $webMod . '&_status_code_map[200]=200&_status_format=json&client_id=' . $client_id); dbug('user info=' . $id); $p = strpos($id, '<id'); $p = strposF($id, '>', $p); $f = strpos($id, '<', $p); $id = substr($id, $p, $f - $p); if (enString($id, '"')) { $id = entre1y2($id, '"id":', ','); } dbug('id=' . $id); $stack = 500; $maxResTotal = 500; //likes //favorites //sounds //sets //playlists if (enString($this->web, 'sets') || enString($this->web, 'playlists')) { $id = CargaWebCurl('https://api.soundcloud.com/resolve?url=' . $this->web . '&_status_code_map[200]=200&_status_format=json&client_id=' . $client_id, "", 0, "", array(), false); $p = strposF($id, 'playlists/'); $f = strpos($id, '?', $p); $id = substr($id, $p, $f - $p); $tipoUrl = 2; } elseif (enString($this->web, 'likes') || enString($this->web, 'favorites')) { $tipoUrl = 0; } else { $tipoUrl = 1; } $mult = 0; $acabado = false; while (!$acabado && $stack * $mult <= $maxResTotal) { $resResD = $stack * $mult; if ($tipoUrl == 0) { $carga = CargaWebCurl('http://api.soundcloud.com/users/' . $id . '/favorites.json?limit=' . $stack . '&offset=' . $resResD . '&client_id=' . $client_id); } elseif ($tipoUrl == 1) { $carga = CargaWebCurl('http://api.soundcloud.com/users/' . $id . '/tracks.json?limit=' . $stack . '&offset=' . $resResD . '&client_id=' . $client_id); } elseif ($tipoUrl == 2) { $carga = CargaWebCurl('http://api.soundcloud.com/playlists/' . $id . '.json?limit=' . $stack . '&offset=' . $resResD . '&client_id=' . $client_id); } if (enString($carga, '[{')) { dbug('mult => ' . $mult); $ronda = $ult = 0; $carga = entre1y2($carga, '[{', '}]'); while (strpos($carga, 'kind":"track"', $ult) > 0 && $ronda < $stack) { $ult = strpos($carga, 'kind":"track"', $ult); if (entre1y2_a($carga, $ult, '"downloadable":', ',') == "true") { $modoUrl = "download"; } else { $modoUrl = "stream"; } $tit = jsonRemoveUnicodeSequences(entre1y2_a($carga, $ult, '"title":"', '"')); $p = strpos($carga, '"uri":"', $ult); $p = strposF($carga, 'tracks/', $p); $f = strpos($carga, '"', $p); $f2 = strpos($carga, '/', $p); if ($f > $f2) { $f = $f2; } $url = 'http://api.soundcloud.com/tracks/' . substr($carga, $p, $f - $p) . '/' . $modoUrl . '?client_id=' . $client_id; dbug($tit . ' - ' . $url); //dbug($ult); array_push($obtenido['enlaces'], array('url' => $url, 'tipo' => 'http', 'extension' => 'mp3', 'url_txt' => $tit)); $ronda++; $ult++; } if ($ronda == $stack) { $mult++; } else { $acabado = true; } } else { $acabado = true; } } } } $obtenido['titulo'] = $titulo; $obtenido['imagen'] = $imagen; finalCadena($obtenido, false); }