Apologies for the vague title of my question. I'm just trying to figure out why a Youtube video stream on a friend's Wordpress site suddenly broke.
I'm trying to decipher it now, but I thought I'd post here to see if anyone could point me in the correct direction while I make heads or tails of this.
Thank you.
Page in question: http://www.advocatedaily.com/advocatetv/
Error on page:
Warning: main() [function.main]: Node no longer exists in /home/advocate/public_html/wp-content/themes/process/advocate-tv.php on line 45
Warning: main() [function.main]: Node no longer exists in /home/advocate/public_html/wp-content/themes/process/advocate-tv.php on line 45
Fatal error: Call to a member function attributes() on a non-object in /home/advocate/public_html/wp-content/themes/process/advocate-tv.php on line 48
Lines 40 through 55:
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
//get <yt:videoId> node for Video ID
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$playlistVideoID = $yt->videoid;
Full snippet of problem area:
</div>
<div id="mainPlaylist" class="grid_6 omega">
<h3 class="title">Legal Feed with Kate Wheeler</h3>
<ul id="playlists">
<?php
// Loop through each video in each playlist
// read feed into SimpleXML object
// *Moved into header to load main Video as well
$playlistFeedURL = 'http://gdata.youtube.com/feeds/api/playlists/6549D4CA7BB99B16?v=2';
$sxml = simplexml_load_file($playlistFeedURL);
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
//get <yt:videoId> node for Video ID
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$playlistVideoID = $yt->videoid;
// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
?>
<div class="item">
<span class="thumbnail left" rel="<?php echo $entry->id; ?>">
<img src="<?php echo $thumbnail;?>" />
</span>
<?php echo $media->group->title; ?>
<span class="attr">Duration:</span> <?php printf('%0.2f', $length/60); ?> min.
<div class="clear"></div>
</div>
<?php
}
?>
</ul>
</div>
<div class="hr-single grid_16"></div>
</div>
<div class="article grid_10">
<div id="recentUploads">
<h3 class="grid_8">Recent Uploads</h3>
<div class="clear"></div>
<ul>
<?php
// Loop through each video in each playlist
// read feed into SimpleXML object
// *Moved into header to load main Video as well
$playlistFeedURL = 'http://gdata.youtube.com/feeds/api/playlists/755260781A134FFF?v=2';
$sxml = simplexml_load_file($playlistFeedURL);
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
//get <yt:videoId> node for Video ID
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$playlistVideoID = $yt->videoid;
// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
?>
<div class="item">
<div class="thumbnail left" rel="<?php echo $entry->id; ?>">
<img src="<?php echo $thumbnail;?>" />
</div>
<div class="">
<?php echo $media->group->title; ?>
<span class="attr">Duration:</span> <?php printf('%0.2f', $length/60); ?> min.
<p><?php echo $media->group->description; ?></p>
</div>
<div class="clear"></div>
</div>
<?php
}
?>
</ul>
</div>
I think the same thing that happened to me may have happened to you.
As per your code it seems the API isn't correctly finding the playlist
http://gdata.youtube.com/feeds/api/playlists/6549D4CA7BB99B16?v=2
In an attempt to fix my own troubled calls I added the PL to the Playlist ID : *PL*6549D4CA7BB99B16
http://gdata.youtube.com/feeds/api/playlists/PL6549D4CA7BB99B16?v=2
While googling this, I found a blog post referencing something about adding the ability to include the PL to the calls.
apiblog.youtube.com/2012/08/playlists-now-with-more-pl.html
In my quick searches I didn't notice anything about them removing the old way of it sending the playlist ID.
Related
I spent so much time on a very simple thing and had to post here on StackOverflow
I want to get all inner text except the script/style tags
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$html = <<<EOD
<div>
<script>var main=0</script>
<div>
<p>my</p>
<script>var inner=0</script>
</div>
<p>text</p>
only
</div>
EOD;
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
echo $entries = $xpath->query('//*[not(self::script)]')->item(0)->nodeValue;
gives me
var main=0 my var inner=0 text only
and also tried
$entries = $xpath->query('//*[not(self::script)]');
foreach ($entries as $entry) {
if ($entry->tagName == 'style' || $entry->tagName == 'script') {
continue;
}
echo preg_replace('/\s\s+/', ' ', $entry->nodeValue);
}
gives me
var main=0 my var inner=0 text only var main=0 my var inner=0 text only var main=0 my var inner=0 text only my var inner=0mytext
I tried several xpaths but it doesn't work
my desired output is my text only
I am a Scrapy developer and I do that easily in Scrapy, but having a bad time with PHP today
Unfortunately, PHP doesn't support xpath 2.0 (and, IIRC, neither does Scrapy), so the name() method which would have made it easy, isn't available...
The closest thing I can think of is the following, which should get you close enough (note that, because there is no <style> tag in your $html, I only focused on <script>):
$entries = $xpath->query('//*[not(./text()/parent::script)]/text()');
foreach ($entries as $entry) {
echo trim($entry->textContent) . " ";
}
Output:
my text only
I have an TYPO3 extension which shows a list of records. As it are more than 40 pages I would like to provide an additional alphabetic index which enables visitors to jump directly to the beginning of a character.
In general all is working - except the link to the n-th page.
I have the fluid variables cur containing current character (e.g. M) and the necessary page number in pageNumber (e.g. 23).
How can I get the correct url which should look like:
https://mydomain.tld/path/to/list?tx_myextension_myextension[#widget_0][currentPage]=23&cHash=a6193a7eab129df4789343911221584b#jumplabel_M
either
<a class="page-link" href="{f:uri.page(additionalParams:{tx_myextension_myextension{#widget_0:{currentPage:pageNumber}}})}#jmplabel_{cur}">{cur}</a>
nor
<a class="page-link" href="{f:uri.page(additionalParams:{tx_myextension_myextension[#widget_0][currentPage]:pageNumber})}#jmplabel_{cur}">{cur}</a>
call the f:uri.page VH. The result is an unreplaced string in the href-parameter.
<a class="page-link" href="{f:uri.page()}?tx_phonebook_phonebook[#widget_0][currentPage]={pageNumber}#jmplabel_{cur}">{cur}</a>
looks ok, but misses the cHash and therefore results in 404 page not found.
Check how Georg Ringer does it in his News extension. Actually that's a solution for your pagination.
PaginateAdditionalParamsViewHelper.php:
https://github.com/georgringer/news/blob/master/Classes/ViewHelpers/Widget/Ajax/PaginateAdditionalParamsViewHelper.php#L30
public function render()
{
$page = (int)$this->arguments['page'];
if ($page === 0) {
return [];
}
$params = [
'tx_news_pi1' => [
'#widget_0' => [
'currentPage' => $page
]
]
];
return $params;
}
And in some template:
https://github.com/georgringer/news/blob/master/Resources/Private/Templates/Styles/Twb/Templates/ViewHelpers/Widget/Paginate/IndexAjax.html#L56, especially additionalParams key.
<f:widget.link data="{container:recordId,link:'{t:uri.ajaxAction(contextRecord:\'tt_content:{recordId}\', pluginName: \'pi1\',additionalParams:\'{n:widget.ajax.paginateAdditionalParams(page:0)}\')}'}">
<f:translate key="paginate_previous" />
</f:widget.link>
I want to get last 50 videos from www.youtube.com/feeds/videos.xml?playlist_id, Currently I can only retrieve last 15 videos. I have tried max-result parameter, but it failed.
Instead of above method I have found another way to fetch youtube playlist videos, here it is
<?php
$playlistId = 'Playlist Id here';
$maxResults = 50;
$apiKey = 'youtube api key here';
$string = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId='.$playlistId.'&maxResults='.$maxResults.'&key='.$apiKey.''));
//echo '<pre>'; print_r($string);
foreach($string->items as $item) {
$video_id = $item->snippet->resourceId->videoId;
}
?>
I've got some problems with my url on my website. I'm trying to get a link with the given GET parameters, but i'm getting my previous parameter aswell.
My url looks like this:
www.cdwinkel.dev/search-results?genre=Pop&medium=DVD&medium=Single .
It should be:
www.cdwinkel.dev/search-results?genre=Pop&medium=Single .
I'm running the following code:
$data['url'] = createurl();
function createurl(){
$i = 1;
$string = "?";
$keys = array_keys($_GET);
foreach($_GET as $get){
if($get != ""){
$string .= $keys[$i] . "=" . $get ."&";
$i++;
}
}
$string = rtrim($string, "&");
return $string;
}
$i = 1, because my first value in my array is empty.
And my button looks like this:
<a href='".$data['url'].'&medium='.$names[$i]."'>
I guess I should'nt set &medium=.$names[$i] in the href tag,
but I wont get the new $names[$i] in my function, so I won't get a new url if i wont add it in.
I'm looking forward to your responce.
Sincerely,
Kars Takens
At this point i've created an array with the right arraykeys and values.
$url = array_slice($_GET, 1);
This returns the following array:
array (size=2)
'genre' => string 'Pop' (length=3)
'medium' => string 'DVD' (length=3)
After this I decoded this into a new string:
genre=Pop&medium=DVD
I got 6 button which I created in a foreach loop, but i'm getting &medium='VALUE' Twice. This only happens after the first time. So the first time my button works well.
<?php
$names = array_keys($data['tellen']);
$i = 0;
foreach($data['tellen'] as $m){
echo "<li><a href='search-results?".$data['url'].'&medium='.$names[$i]."'>". $names[$i] ." <span class='product-amount'>(". $m[0]->count. ")</span></a></li>";
$i++;
}
Hopefully you can help me further with this information.
I solved my problem by adding this in my forloop:
foreach($data['tellen'] as $m){
if(isset($_GET['medium'])){
unset($_GET['medium']);
$url = array_slice($_GET, 1);
$data['url'] = urldecode(http_build_query($url));
}
echo "<li><a href='search-results?".$data['url'].'&medium='.$names[$i]."'>". $names[$i] ." <span class='product-amount'>(". $m[0]->count. ")</span></a></li>";
$i++;
}
I am useing Zend\Dom\Query to get specific content from a webpage.
This is the html:
<div class="menuName darkGreen leftMenu">
Mouse
</div>
How can I get the value Mouse ??
Thanks
Try this:
$dom = new \Zend\Dom\Query($html);
$results = $dom->execute('div.menuName a');
$doc = $results->current();
var_dump($doc->nodeValue);
Try this:
$doc->getAttribute('src');