-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtubeProcess.php
133 lines (102 loc) · 3.96 KB
/
youtubeProcess.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
// this will parse the urls and the get
// first generate the url
set_time_limit(0);
require_once "simple_html_dom.php";
require_once 'connection.php';
require_once "functions.php";
$results = ex_query("SELECT `Key` FROM ProcessVideos where `processed`='No' LIMIT 0,20");
while($row = mysql_fetch_array($results))
{
$row=$row[0];
$row = ex_query1Row("SELECT *
FROM `ProcessVideos`
WHERE `Key` =$row");
$key = $row["Key"];
$html = file_get_html('http://www.youtube.com' . $row["url"]);
// What do i need
// the imbeded link for the site the link generated by youtube itself
// cant you create that already ?
/// yes i can
//so ?
$youtubeVidID = substr($row["url"], 9);
// link for embed links =
$embeded_Link = "<iframe width=\"940\" height=\"530\" src=\"http://www.youtube.com/v/$youtubeVidID&autoplay=1\" frameborder=\"0\" allowfullscreen></iframe>";
$Username = "";
$description = "";
$videoimage = "http://i2.ytimg.com/vi/" . $youtubeVidID . "/hqdefault.jpg";
$title = "";
//foreach ($html->find('div[id=watch-container]') as $element) {
foreach ($html->find('body') as $element) {
$s = explode('<', $element);
for ($q = 0; $q < count($s); $q++) {
$mainstring = $s[$q];
// Find UserName
if (strlen(strstr($mainstring, "link itemprop=\"url\" href=\"http://www.youtube.com/user/")) > 0) {
$Username = substr($mainstring, 54);
$Username = substr($Username, 0,strlen($Username)-9);
}
if (strlen(strstr($mainstring, "itemprop=\"name\" content=")) > 0) {
$title = substr($mainstring, 30);
$title =substr($title, 0,strlen($title)-7);
}
if (strlen(strstr($mainstring, "meta property=\"og:title\"")) > 0) {
$title = $mainstring;
$title = substr($name, 34, strlen($title) - 41);
}
}
}
foreach ($html->find("p[id=eow-description]") as $element) {
$description = substr($element, 25);
$description = substr($description, 0, strlen($description) - 4);
}
//
// echo "\n<br /> Name of Video is:" . $title;
// echo "\n<br /> Description of Video is:" . $description;
// echo "\n<br /> Embeded link of Video is: " . $embeded_Link;
// echo "\n<br /> image of Video is: " . $videoimage;
// echo "\n<br /> User Upload of Video is: " . $Username;
//
//first create a user if he doesnt exist
// well the link would not work ?
// we can change it later
if(ex_query1RowAns("Select 1 from users where UserName='$Username'")!=1)
{
// seems like i would have to check for a number that does not exist.
$nt = "no";
while ($nt!="Done") {
$random = rand (0 , 10000000000);
if (ex_query1RowAns("Select 1 from users where ID= $random")!="1") {
$nt="Done";
}
}
$query = "insert into users (ID,UserName,fblink) value('".$random."','$Username','/user/infiniteammoinc')";
ex_query($query);
}
$hash = genUhash();
$userid = ex_query1RowAns("Select ID from users where UserName ='$Username'");
if(ex_query1RowAns("Select 1 from video where videoImage ='$videoimage' and UserID='$userid'")!=1)
{
$query = "INSERT INTO video (VideoName ,mp4Path,webMPath ,Hash,videoImage,UserID,dtuploaded,site) VALUES (";
$query .= "'" . $title . "', '" . $embeded_Link . "','" . "" . "','" .$hash . "','" . $videoimage . "','$userid','". to_mysqlDate(time()) . "','Youtube')";
ex_query($query);
}
$videoid = ex_query1RowAns("Select ID from video where videoImage ='$videoimage' and UserID='$userid'");
if(ex_query1RowAns("Select 1 from videodesc where VidID ='$videoid'")!=1)
{
$query = "Insert into videodesc(VidID,txtDesc) Values(" . $videoid . ",'" . $description . "')";
ex_query($query);
$query = "Insert into videocatinfo(hash,Category) Values('" . $hash. "','" . $row['string1'] . "')";
ex_query($query);
$query = "Insert into views(Video_ID,Numwatched) Values('$videoid',0)";
ex_query($query);
}
// now to add description
//now i should look at the videos to the side
// nah
//why not
// well because its a .......
//ok then well lets clean everything up than
ex_query("UPDATE `ProcessVideos` SET `processed` = 'Yes' WHERE `ProcessVideos`.`Key` =$key");
}
?>