get youtube download link [ 4k , 1080px ] use API v3 - youtube

I try To get youtube Video link from
http://www.youtube.com/get_video_info?video_id=XXXXXXXX
But 1080 px and 4k is not in the list So how i can get links for this resolution
api v3 not allow to get url

This function could done the job
<?php
function get_youtube($id)
{
$data = file_get_contents('http://youtube.com/get_video_info?video_id=' . $id . '&el=vevo&fmt=18&asv=2&hd=1');
parse_str($data , $details);
$my_formats_array = explode(',' , $details['adaptive_fmts']);
$avail_formats[] = '';
$i = 0;
$ipbits = $ip = $itag = $sig = $quality_label = '';
$expire = time();
foreach ($my_formats_array as $format) {
parse_str($format);
$avail_formats[$i]['itag'] = $itag;
$avail_formats[$i]['quality'] = $quality_label;
$type = explode(';', $type);
$avail_formats[$i]['type'] = $type[0];
$avail_formats[$i]['url'] = urldecode($url) . '&signature=' . $sig;
parse_str(urldecode($url));
$avail_formats[$i]['expires'] = date("G:i:s T", $expire);
$avail_formats[$i]['ipbits'] = $ipbits;
$avail_formats[$i]['ip'] = $ip;
$i++;
}
return $avail_formats;
}
$qualitys = get_youtube($_GET['id']);
foreach($qualitys as $video)
{
//echo "<a href='" . $video['url'] . "'>" . $video['quality'] . "-" . $video['type'] . "</a></br>"; //print all resolution
// for getting 1080p only
if($video['quality']=='1080p' && $video['type']=='video/mp4'){
echo "<a href='" . $video['url'] . "'>" . $video['quality'] . "-" . $video['type'] . "</a></br>";
}
}

Related

PhpSpreadsheet Notice: Undefined offset: 4

I have been struggling with finding a way to read excel files in a directory, copy the worksheet called "Division" into a new file, then number the new worksheets increment by one - Division1, Division2, etc...
The following is my code, which I am receiving a warning for undefined index, which is not a big deal, but it only creates a new excel file with only four worksheets, when there should be over 240 worksheets.
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
$exportedFiles = scandir('PhpSpreadsheet/Export');
$inputFileNames = [];
$sheetnames = [];
$outfile = 'all-together-now.xlsx';
foreach($exportedFiles as $key=> $value) {
if ($value == '.' || $value == '..') {
} else {
array_push($inputFileNames, 'PhpSpreadsheet/Export/' . $value);
array_push($sheetnames, 'Division');
}
}
$inputFileType = 'Xlsx';
$reader = IOFactory::createReader($inputFileType);
$reader->setLoadSheetsOnly($sheetnames);
$contador = 1;
foreach ($inputFileNames as $book => $inputFileName) {
echo ('$inputFileName: ' . $inputFileName) . '</br>';
$reader = IOFactory::createReader("Xlsx");
$spreadsheet = $reader->load($inputFileName);
$clonedWorksheet = clone $spreadsheet->getSheetByName('Division');
$clonedWorksheet->setTitle('Division' . $contador);
$spreadsheetMain = $reader->load($outfile);
$spreadsheetMain->addSheet($clonedWorksheet);
$writer = IOFactory::createWriter($spreadsheetMain, "Xlsx");
$writer->save($outfile);
$contador++;
}
The following are the warning notices:
Notice: Undefined offset: 4 in
PhpOffice\PhpSpreadsheet\Writer\Xlsx->save( )
PhpOffice\PhpSpreadsheet\Spreadsheet->garbageCollect( )
As usual, thanks in advance
Part of the solution was bumping up the memory and the other was to use addSheet()
The following is the code that works:
ini_set('memory_limit','32768M');
use PhpOffice\PhpSpreadsheet\IOFactory;
require_once 'PhpSpreadsheet/src/Bootstrap.php';
$exportedFiles = scandir('PhpSpreadsheet/Export');
$inputFileNames = [];
$sheetnames = [];
$outfile = 'all-together-now.xlsx';
foreach($exportedFiles as $key=> $value) {
if ($value == '.' || $value == '..') {
} else {
array_push($inputFileNames, 'PhpSpreadsheet/Export/' . $value);
array_push($sheetnames, 'Division');
}
}
$inputFileType = 'Xlsx';
$reader = IOFactory::createReader($inputFileType);
$reader->setLoadSheetsOnly($sheetnames);
$contador = 1;
foreach ($inputFileNames as $book => $inputFileName) {
echo ('$inputFileName: ' . $inputFileName) . '</br>';
$reader = IOFactory::createReader("Xlsx");
$spreadsheet = $reader->load($inputFileName);
$spreadsheet->getSheetByName('Division')->getStyle('Division');
$clonedWorksheet = clone $spreadsheet->getSheetByName('Division');
$clonedWorksheet->setTitle('Division' . $contador);
/* open new file for writing spread sheets to it */
$spreadsheetMain = $reader->load($outfile);
$spreadsheetMain->addSheet($clonedWorksheet);
$writer = IOFactory::createWriter($spreadsheetMain, "Xlsx");
$writer->save($outfile);
$contador++;
}
$spreadsheet->disconnectWorksheets();
echo "The process has completed";
die();
The aforementioned script created an excel workbook with 247 worksheets from the 247 excel files

WebClient.Downloadfile API is not working in powershell

(new-object System.Net.WebClient).Downloadfile("https://www.dropbox.com/sh/tsyz48qg0rq3smz/QAstBLgPgN/version.txt", "C:\Users\Brangle\Desktop\version.txt") API download invalid data.
version.txt file need to download. But actually it is downloading some xml file contains in version.txt on destination location
Thanks in advance
You are trying to download the dropbox page which presents your file in a nice dropbox-themed html. You need to extract the real url and can do so using the following code:
$wc = New-Object system.net.webclient;
$s = $wc.downloadString("https://www.dropbox.com/sh/tsyz48qg0rq3smz/QAstBLgPgN/version.txt");
$r = [regex]::matches($s, "https://.*token_hash.*(?=`")");
$realURL = $r[$r.count-1].Value;
$wc.Downloadfile($realURL, "U:\version.txt");
The regex part looks for a url starting https://, has a string token_hash in the middle and ends one character before double quotes character ". The line in question is:
FilePreview.init_text("https://dl.dropboxusercontent.com/sh/tsyz48qg0rq3smz/QAstBLgPgN/version.txt?token_hash=AAEGxMpsE-T4xodBPd3A6uPTCr0uqh7h4B2YUSmTDJHmjg", 0, null, 0)
Hope this helps.
Here is the function:
function download-dropbox($Url, $FilePath) {
$wc = New-Object system.net.webclient
$req = [System.Net.HttpWebRequest]::Create($Url)
$req.CookieContainer = New-Object System.Net.CookieContainer
$res = $req.GetResponse()
$cookies = $res.Cookies | % { $_.ToString()}
$cookies = $cookies -join '; '
$wc.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookies)
$newurl = $url + '?dl=1'
mkdir (Split-Path $FilePath) -force -ea 0 | out-null
$wc.downloadFile($newurl, $tempFile)
}
Re: LogMeIn - theyuse a cookie base authentication so you can't use the previous code. Try this, it gets a cookie from the first response and then uses that to download using webclient:
$url = "https://secure.logmein.com/fileshare.asp?ticket=01_L5vwmOrmsS3mnxPO01f5FRbWUwVKlfheJ5HsfpTV"
$wc = New-Object system.net.webclient
$req = [System.Net.HttpWebRequest]::Create($url)
$req.CookieContainer = New-Object System.Net.CookieContainer
$res = $req.GetResponse()
$cookie = $res.Cookies.Name + "=" + $res.Cookies.Value
$wc.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookie)
$newurl = $url + "`&download=1"
$wc.downloadFile($newurl, "c:\temp\temp.zip")

Jquery Mobile data-autodividers

Is there a way to have the auto-dividers sort by last name?
I don't think it should have anything to do with the php code, but I thought I would include it for a reference below:
$result = mysql_query("SELECT * FROM `patients` WHERE `company_id` = " . $user_data['company_id'] . " ORDER BY `patient_lastname`");
while($row = mysql_fetch_array($result)) {
echo '<li>' . $row['patient_firstname'] . ' ' . $row['patient_lastname'] . '<span class="ui-li-count">DOB: ' . $row['patient_dob'] . '</span></li>';
}
Appreciate any help!
You can do the sorting in the front-end by selecting the list items and sorting them afterward. In the example below, instead of selecting the text content of the list items, you can select the last-name value.
var listContentArray = listViewInstance.find('li').not('.ui-li-divider').get();
listContentArray.sort(function (a, b) {
var first = $(a).text(),
second = $(b).text();
if (first < second) {
return -1;
}
if (first > second) {
return 1;
}
return 0;
});
Then you can destroy the content of the listViewInstance, re-append the elements in the listContentArray, and finally refresh the listView component.
You can download a fully functional example that does all of this at:
http://appcropolis.com/page-templates/autodividers/
Couldn't find a way to display Firstname then Lastname and autodivide by Lastname, so I just replaced the code with:
' . $row['patient_lastname'] . ', ' . $row['patient_firstname'] . '
which displays: "Lastname, Firstname" and autodivides by Lastname. It'll have to work for now.

How to call value of selected List from Jquery

I want to call the value of selected li with jquery . Here is my ul list,get data from Database and
<ul id="scroller1">
<?php
$globalregion_result = mysql_query("SELECT * FROM GlobalRegion");
$i = 0;
while($globalregion_row = mysql_fetch_array($globalregion_result)){
echo "<li id='scroller1_" . $i . "' value='" . $globalregion_row["GlobalRegionID"] . "'>" . $globalregion_row["GlobalRegionName"] . "</li>";
$i++;
}
?>
</ul>
Here is my jquery call for list
var scroll1SCell = null;
var scroll1SVal = $("#scroller1 .active-item").attr("value");
It show "undefined" at console.
The li's id is something like: id='scroller1_" . $i . "'. Which means you'll have to use that specific selector to find the element:
var index = // get the index of the li you need.
$("#scroller1_"+index).attr("value");
As #rgthree pointed out you're using li's incorrectly. These elements are meant to just be lists of text or other elements, but not select boxes. The value attribute is not a valid attribute. Instead you might want to use this code:
HTML:
<select id="scroller1">
<?php
$globalregion_result = mysql_query("SELECT * FROM GlobalRegion");
$i = 0;
while($globalregion_row = mysql_fetch_array($globalregion_result)){
echo "<option value='" . $globalregion_row["GlobalRegionID"] . "'>" . $globalregion_row["GlobalRegionName"] . "</option>";
$i++;
}
?>
</select>
JS:
var value = $("#scroller1").val();
This will work:
$("#scroller1").val();
var scroll1SVal = $("#scroller1 option:selected").val();

jQuery UI Autocomplete: return only strings that use input as prefix

I am using jQuery Autocomplete 1.8. Every time it returns every string that contains the input as a substring. How can I make it return only the strings that contains the input as a prefix?
I'm doing it in the sql. I'm using php to generate the json
<?php
set_include_path(get_include_path() . ':' . '/home/lms/library/php');
set_include_path(get_include_path() . ':' . '/home/lms/systems/ORM');
require_once("Configuration.php");
require_once("DALI_Class.php");
//$unitID = $_POST['unitID'];
$unitID = $_GET["term"];
$return_array=array();
$row_array=array();
$lmsAdminSysDB = DALI::connect(LMS_MIDDLEWARE_DATABASE);
$selectUnit = "SELECT " .
"UnitID, " .
"Title " .
"FROM UnitTBL " .
"WHERE UnitID LIKE '".$unitID."%' " .
"ORDER BY UnitID " .
"";
$resultUnit = $lmsAdminSysDB->Execute($selectUnit);
while($row = $resultUnit->FetchRow()) {
$row_array['label'] = $row['UnitID']." - ".$row['Title'];
$row_array['value'] = $row['UnitID'];
$row_array['title'] = $row['Title'];
array_push($return_array,$row_array);
}
unset($resultUnit);
//header('Content-type: application/json');
//echo json_encode($result);
DALI::disconnect($lmsAdminSysDB);
echo json_encode($return_array);
?>

Resources