-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.py
107 lines (94 loc) · 3.03 KB
/
database.py
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
import sqlite3
import os
# Connect to SQLite database (or create it if it doesn't exist)
database_path = os.path.join('./output/database', 'youtube.db')
conn = sqlite3.connect(database_path)
cursor = conn.cursor()
# Create video_table
cursor.execute('''
CREATE TABLE IF NOT EXISTS video_table (
id INTEGER PRIMARY KEY AUTOINCREMENT,
video_title TEXT NOT NULL,
video_url TEXT NOT NULL,
video_description TEXT
)
''')
# Create subtitle_language_table
cursor.execute('''
CREATE TABLE IF NOT EXISTS subtitle_language_table (
id INTEGER PRIMARY KEY AUTOINCREMENT,
language TEXT DEFAULT NULL
)
''')
# Insert languages into subtitle_language_table
cursor.execute('INSERT INTO subtitle_language_table (language) VALUES ("English")')
cursor.execute('INSERT INTO subtitle_language_table (language) VALUES ("Hindi")')
cursor.execute('INSERT INTO subtitle_language_table (language) VALUES ("German")')
# Create playlist_table
cursor.execute('''
CREATE TABLE IF NOT EXISTS playlist_table (
id INTEGER PRIMARY KEY AUTOINCREMENT,
playlist_name TEXT DEFAULT 'None'
)
''')
# Create status_table
cursor.execute('''
CREATE TABLE IF NOT EXISTS status_table (
id INTEGER PRIMARY KEY AUTOINCREMENT,
status TEXT NOT NULL
)
''')
# Insert statuses into status_table
statuses = ['Planning', 'Scripting', 'Recording', 'Editing', 'Private', 'Public', 'Unlisted']
for status in statuses:
cursor.execute('INSERT INTO status_table (status) VALUES (?)', (status,))
# Create video_status
cursor.execute('''
CREATE TABLE IF NOT EXISTS video_status (
video_id INTEGER,
status_id INTEGER,
FOREIGN KEY (video_id) REFERENCES video_table(id),
FOREIGN KEY (status_id) REFERENCES status_table(id)
)
''')
# Create playlist_status
cursor.execute('''
CREATE TABLE IF NOT EXISTS playlist_status (
playlist_id INTEGER,
status_id INTEGER,
FOREIGN KEY (playlist_id) REFERENCES playlist_table(id),
FOREIGN KEY (status_id) REFERENCES status_table(id)
)
''')
# Create video_playlist_table
cursor.execute('''
CREATE TABLE IF NOT EXISTS video_playlist_table (
video_id INTEGER,
playlist_id INTEGER,
FOREIGN KEY (video_id) REFERENCES video_table(id),
FOREIGN KEY (playlist_id) REFERENCES playlist_table(id)
)
''')
# Create videoLanguage_table
cursor.execute('''
CREATE TABLE IF NOT EXISTS videoLanguage_table (
video_id INTEGER,
subtitle_id INTEGER,
FOREIGN KEY (video_id) REFERENCES video_table(id),
FOREIGN KEY (subtitle_id) REFERENCES subtitle_language_table(id)
)
''')
# Create end_video_table
cursor.execute('''
CREATE TABLE IF NOT EXISTS end_video_table (
video_id INTEGER NOT NULL,
end_video_1_id INTEGER DEFAULT NULL,
end_video_2_id INTEGER DEFAULT NULL,
FOREIGN KEY (video_id) REFERENCES video_table(id),
FOREIGN KEY (end_video_1_id) REFERENCES video_table(id),
FOREIGN KEY (end_video_2_id) REFERENCES video_table(id)
)
''')
# Commit changes and close the connection
conn.commit()
conn.close()