Import YouTube Views Into PlayTube Script  

Page 1 / 4 Next
  RSS

Disquy
(@disquy)
Member Admin
Joined: 1 year  ago
Posts: 85
October 22, 2018 5:55 pm  

Having a bad to the bone platform does nothing if it doesn't look active. Put yourself in your visitor's shoes, if you went on a website and it had 10 to 20 views per video, would you think it's a popular website? This is my logic, and a reason why I believe Vigeos.net is failing. So here we are looking for a solution that isn't in effect in the core of the platform.

Note: Always backup your db and any files to be modified just to be safe. These types of modifications are not a simple plug and play kind of install. I am not responsible for any loss of data nor does this script come with any guarantee. This script is provided as is.

I have other modifications HERE if you are interested.

I have noticed that after this modification, I'm actually getting more hits from Google than I ever did. Even though this change benefited me, I can not guarantee it will benefit you, so know this going into this modification.

 

UPDATE 11-26-18
Changelog
v1.2

Global
Cron Added
Uses PlayTube config
Skips dead videos
Error logging improved

Webview Only
Admin only access
Slight design change on webview 
Shows updated video count

 

Instructions
Always backup your db and any files to be modified just to be safe. These types of modifications are not a simple plug and play kind of install. I am not responsible for any loss of data nor does this script come with any guarantee. This script is provided as is.

If you choose webview simply upload the view-count.php to your public_html ( or whichever directory you have PlayTube installed to ) and go to yourdomain.com/view-count.php

Try Optimized first, if this doesn't work, your server may not support curl and you will need to use the Normal version.

For Cron same concept, but I also added versions that send emails. Choose if you want only error emails or error and success emails. 

This will be a different install path. You need to one directory before your public_html.

Then go to cPanel -> Cron

Setup a command with the following

php -q -f /home/CPANELUSERNAME/view-count.php

If you for some reason do not know your cPanel username I have added in info.php. Simply add this file to your public_html and go to yourdomain.com/info.php

Search for DOCUMENT_ROOT

For the rest of the cron config
Minute: 0
Hour: 2
Day: *
Month: *
Weekday: *

This will run everyday at 2AM server time.

 

Download
view-count-update-v1.2.zip

 

File Modifications
If you would like to automatically pull in the view counts going forward, you will need to do some PlayTube script core file modifications.

Note: I am using PlayTube 1.4.3. You can find the 1.4.5 - 1.4.5.1 modified file here. Make sure to backup your existing file, and transfer any modifications you have made to the new file.

Find in ajax/submit-imported-video.php

preg_match_all($link_regex, PT_Secure($_POST['description']), $matches);
foreach ($matches[0] as $match) {
$match_url = strip_tags($match);
$syntax = '[a]' . urlencode($match_url) . '[/a]';
$_POST['description'] = str_replace($match, $syntax, $_POST['description']);
}

 

Below Add

// Check YouTube Views
if ($_POST['video-type'] == 'youtube') {
$yt_json = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=" . $_POST['video-id'] . "&key=" . $pt->config->yt_api);
$yt_json_data = json_decode($yt_json);
$youtube_views = $yt_json_data->items[0]->statistics->viewCount;
}
else
{
$youtube_views = '0';
}

 

Find

$data_insert = array(
'video_id' => $video_id,
'user_id' => $user->id,
'title' => PT_Secure($_POST['title']),
'description' => PT_Secure($_POST['description']),
'tags' => PT_Secure($_POST['tags']),
'duration' => $duration,
'category_id' => $category_id,
'thumbnail' => $thumbnail,
'time' => time(),
'registered' => date('Y') . '/' . intval(date('m')),
'type' => $type
);

 

Add a , after 'type' => $type and add the following below

// Import View Count If Youtube
'views' => $youtube_views

 

Final code should look like

$data_insert = array(
'video_id' => $video_id,
'user_id' => $user->id,
'title' => PT_Secure($_POST['title']),
'description' => PT_Secure($_POST['description']),
'tags' => PT_Secure($_POST['tags']),
'duration' => $duration,
'category_id' => $category_id,
'thumbnail' => $thumbnail,
'time' => time(),
'registered' => date('Y') . '/' . intval(date('m')),
'type' => $type,
// Import View Count If Youtube
'views' => $youtube_views
);

 

After updating view count I noticed some of the counts on the PlayTube Script did not automatically add , separators. To do this you will need to make a few template edits:

\ajax\load-related-videos.php
\sources\home\content.php
\sources\watch\content.php
\themes\default\layout\home\categories.html

In the above files find

'VIEWS' => $video->views,
'VIEWS_NUM' => $video->views,

Make sure they look like this

'VIEWS' => number_format($video->views),
'VIEWS_NUM' => number_format($video->views),

Also the featured video view count is cut off if too long. Lets fix that. Find in \themes\default\css\style.css

SKIP THE BELOW PART IF YOU USE YOUPLAY THEME

.pt_featured_video .video-title .video_info { margin-left: auto; text-align: center; max-width: 85px; overflow: hidden; white-space: nowrap; }

Change to

.pt_featured_video .video-title .video_info { margin-left: auto; text-align: center; max-width: 185px; overflow: hidden; white-space: nowrap; }

Then to make sure that the css updates for everyone, find in \themes\default\layout\container.html

<link rel="stylesheet" href="{{CONFIG theme_url}}/css/style.css" id="style-css">

Update to

<link rel="stylesheet" href="{{CONFIG theme_url}}/css/style.css?ver=1.0.1" id="style-css">

 

FAQ

Q: Will this cause me to exceed my YouTube API call limit?
A: Highly unlikely. You have 1,000,000 calls per day that you can make using YouTube API. It will cost you one call per video you have. So unless you have 1,000,000 videos, you won't hit that limit anytime soon.

Q: I get fatal error, max_execution time exceeds 30 seconds.
A: Be sure to set your php settings to PlayTube recommendations via .htaccess or php.ini file. Also if you run the normal version it can use memory more, try to get your host to enable curl and use the Optimized version.

file_uploads = On
post_max_size = 2024M
upload_max_filesize = 2024M
output_buffering = Off
max_execution_time = 4000
max_input_vars = 3000
max_input_time = 5000
memory_limit = 400M
zlib.output_compression = Off

 

Coming Soon

  • Cron Job Queuing
This topic was modified 6 months  ago 14 times by Disquy
This topic was modified 5 months  ago 7 times by Disquy

dinu99 liked
ReplyQuote
vntube
(@vntube)
Trusted Member
Joined: 6 months  ago
Posts: 66
October 22, 2018 7:09 pm  

thank you


ReplyQuote
Disquy
(@disquy)
Member Admin
Joined: 1 year  ago
Posts: 85
October 22, 2018 7:17 pm  
Posted by: vntube

thank you

You're welcome. 🙂


ReplyQuote
vntube
(@vntube)
Trusted Member
Joined: 6 months  ago
Posts: 66
October 22, 2018 7:45 pm  

I do not know anything about code and they all follow your instructions. thank you

vntube.fun


ReplyQuote
Studiomks
(@studiomks)
Active Member
Joined: 6 months  ago
Posts: 7
October 23, 2018 5:15 am  

Thank you, but i am on 1.4.5 and added this code but when i try to add youtube video it hangs and does not add the video. Also can you explain how to add this as an cron job, i do know how to add a cron job, but where to point it at?

Anyway great job on this one 🙂


ReplyQuote
Studiomks
(@studiomks)
Active Member
Joined: 6 months  ago
Posts: 7
October 23, 2018 5:23 am  

Also how to update the current views to old youtube video's?


ReplyQuote
vntube
(@vntube)
Trusted Member
Joined: 6 months  ago
Posts: 66
October 23, 2018 8:58 am  

error please wait

This post was modified 6 months  ago by Disquy

ReplyQuote
Disquy
(@disquy)
Member Admin
Joined: 1 year  ago
Posts: 85
October 23, 2018 6:10 pm  
Posted by: Studiomks

Thank you, but i am on 1.4.5 and added this code but when i try to add youtube video it hangs and does not add the video. Also can you explain how to add this as an cron job, i do know how to add a cron job, but where to point it at?

Anyway great job on this one 🙂

My mistake, I thought I was on the update before the latest. I am on 1.4.3. I'll download the new version and look over it's code to see what the hickup is.

 

Posted by: Studiomks

Also how to update the current views to old youtube video's?

I'm developing the script for this now. I don't have much free time with a full time development job, but I'll upload it today or tomorrow for you.

 

Posted by: vntube

error please wait

This may be due to the newer version. I'll dig into this in a 3-4 hours once I get off from work.

This post was modified 6 months  ago 5 times by Disquy

ReplyQuote
Studiomks
(@studiomks)
Active Member
Joined: 6 months  ago
Posts: 7
October 23, 2018 6:19 pm  

I understand.Thank you, appreciate it.


ReplyQuote
dinu99
(@dinu99)
New Member
Joined: 6 months  ago
Posts: 3
October 25, 2018 1:15 am  

Thanks for sharing this mod.

you may try code highlighter extension like this https://community.mybb.com/mods.php?action=view&pid=843


ReplyQuote
Disquy
(@disquy)
Member Admin
Joined: 1 year  ago
Posts: 85
October 25, 2018 1:48 pm  
Posted by: dinu99

Thanks for sharing this mod.

you may try code highlighter extension like this https://community.mybb.com/mods.php?action=view&pid=843

Thank you for the suggestion. I am using WPForo, I'm thinking of switching to BBPress since it uses WordPress plugins, but I like vBulletin as well and has a better code highlighter. Haven't made a decision yet.

Also @Studiomks, I haven't forgotten about you, my job has me working late on a big project, so I have not had the time to work on this any further. I'll have time over the weekend though.


ReplyQuote
vntube
(@vntube)
Trusted Member
Joined: 6 months  ago
Posts: 66
October 25, 2018 7:52 pm  

I have done it, thank you

This post was modified 6 months  ago by Disquy

ReplyQuote
Studiomks
(@studiomks)
Active Member
Joined: 6 months  ago
Posts: 7
October 26, 2018 5:48 am  

Not a problem, i understand. Take your time. Also please make a paypal donation button on your website, i would like to donate to you, i know these scripts requires time to make in between your job, so i think you should be rewarded in some kind of a way 🙂 


ReplyQuote
Disquy
(@disquy)
Member Admin
Joined: 1 year  ago
Posts: 85
October 27, 2018 3:27 am  
Posted by: Studiomks

Not a problem, i understand. Take your time. Also please make a paypal donation button on your website, i would like to donate to you, i know these scripts requires time to make in between your job, so i think you should be rewarded in some kind of a way 🙂 

It's against Paypal's terms of use to use donation except for non profit, but thank you. I appreciate the thought and support. I am working on your issue now. Digging through the code.

Also I released another modification
https://disquy.com/community/playtube-modifications/add-a-play-button-to-facebook-and-other-social-media-sites-via-playtube

 

Posted by: Studiomks

Not a problem, i understand. Take your time. Also please make a paypal donation button on your website, i would like to donate to you, i know these scripts requires time to make in between your job, so i think you should be rewarded in some kind of a way 🙂 

Ok so the new version had new additional fields added for their privacy functions in their submit-imported-video.php file. Yours should look like this:

'type' => $type,
'privacy' => $video_privacy,
'age_restriction' => $age_restriction

You'll need it to look like this

'type' => $type,
'views' => $youtube_views,
'privacy' => $video_privacy,
'age_restriction' => $age_restriction

I have attached the file to upload, if you use it, make sure you back it up, even if you haven't made modifications to the file. If you have made modification to the core file, be sure to transfer those to the new one in the download. I also looked at their changelog for v1.4.5.1 and it looks like they didn't touch this file, so the modification should work for v1.4.5 and v1.4.5.1. I am working on the mass database update now. Also working to put count delimiter as well

 

Update:
I realize that I want to have the views constantly checking for updated view counts, which made me think you guys and gals may want this as well. I'm just playing around on my development server with different methods for cron, but I worry we may go over API call limits with YouTube. I'll need to do some research, some math, and get some sleep before I dive deeper. I also am trying to figure out the best route to take since the API callbacks are causing longer execution times, which may result in timeouts. This may turn into a bigger project than I originally intended, but it is something that I want to try to see how it will work out. I'll at least post the update script later today until I figure out the best path to take on the cron job.

This post was modified 6 months  ago 11 times by Disquy

ReplyQuote
dinu99
(@dinu99)
New Member
Joined: 6 months  ago
Posts: 3
October 27, 2018 1:02 pm  

Hi, 

How about having both youtube views & playtube default views? I like to have both views

>>> I also am trying to figure out the best route to take since the API callbacks are causing longer execution times, which may result in timeouts. 

Is it possible to get youtube_views during video import option and have cron job script run monthly/bi-weekly once. ? I hope then we might not run out of API call limits

This post was modified 6 months  ago by dinu99

ReplyQuote
Page 1 / 4 Next
Share: