-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
115 lines (104 loc) · 3.29 KB
/
index.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
<?php
include __DIR__ . '/API/yt_clientAPI.php';
$servername = "192.168.64.2";
$username = "cloudbreakr";
$password = "cloudbreakr";
$myDB = "youtubeDB";
try {
$conn = new PDO("mysql:host=$servername;dbname=$myDB", $username, $password);
// set PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Get channelID
$youtubeID = readline("Enter YouTube Channel ID: ");
$data = getUser($youtubeID);
// $videos = getVideos ($youtubeID);
// insert data to sql table
$sql = $conn->prepare("INSERT INTO yt_user
(
`ytId`,
`channelName`,
`yt_desc`,
`profilePic`,
`videoCount`,
`subscriberCount`,
`viewCount`,
`createdAt`,
`country`,
`uploadPlaylistId`,
`topicIds`,
`topicCategories`
)
VALUES
(
'" . $data[0] . "',
'" . $data[1] . "',
:bio,
'" . $data[3] . "',
'" . $data[4] . "',
'" . $data[5] . "',
'" . $data[6] . "',
'" . $data[7] . "',
'" . $data[8] . "',
'" . $data[9] . "',
'" . $data[10] . "',
'" . $data[11] . "'
)
");
$sql->execute(array(
':bio' => $data[2]
));
//$video_list is an array with key 'id' and value = all the uploaded videoId of $youtubeId seperated by ','
$video_list = getVideoId($data[9]);
// $result is a 2D array, it contains x amount of videos and each $result[x] has data of the video
$result = getVideo($video_list);
//save last insert Id
$db_ytId = $conn->lastInsertId();
for ($i = 0; $i<count($result); ++$i)
{
$vid = $conn->prepare("INSERT INTO yt_video
(
`ytId`,
`yt_videoId`,
`videoTitle`,
`content`,
`pictureUrl`,
`postDate`,
`viewCount`,
`likeCount`,
`dislikeCount`,
`commentCount`,
`videoDuration`,
`tags`,
`categId`
)
VALUES
(
'" . $db_ytId . "',
'" . $result[$i]['videoId'] . "',
:title,
:descr,
'" . $result[$i]['pictureUrl'] . "',
'" . $result[$i]['postDate'] . "',
'" . $result[$i]['viewCount'] . "',
'" . $result[$i]['likeCount'] . "',
'" . $result[$i]['dislikeCount'] . "',
'" . $result[$i]['commentCount'] . "',
'" . $result[$i]['videoDuration'] . "',
:tag,
'" . $result[$i]['categId'] . "'
)
");
$vid->execute(array
(
':title' => $result[$i]['videoTitle'],
':descr' => $result[$i]['description'],
':tag' => $result[$i]['tags']
)
);
}
echo "Success\n";
} catch (PDOException $e) {
echo "Failed: " . $e->getMessage() . "\n";
}
$conn = null;
?>