GilangAlRusliadi commited on
Commit
6c1239c
·
1 Parent(s): fe87b6d
Files changed (2) hide show
  1. others.py +18 -3
  2. trailer.py +9 -54
others.py CHANGED
@@ -137,7 +137,9 @@ def get_video_resolution(input_file):
137
  print(f'Error getting video resolution: {result.stderr}')
138
  return None
139
 
140
- def get_video_info(soup: BeautifulSoup):
 
 
141
  # Mencari judul video di elemen meta dengan name="twitter:title"
142
  title = soup.find("meta", attrs={"name": "twitter:title"})
143
  if title:
@@ -164,7 +166,20 @@ def get_video_info(soup: BeautifulSoup):
164
 
165
  print(f"Artis: {actress} dan Series: {series}")
166
 
167
- return actress, series, title, video_title
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
  def get_digits(series: str, thumbnail_url: str):
170
  if series == 'Cospuri':
@@ -219,7 +234,7 @@ def get_video_resolution(input_file):
219
 
220
  def convert_videos(height, filename):
221
  download_folder = os.path.dirname(filename)
222
- konversi_folder = f'{download_folder}/Hasil Konversi'
223
  if not os.path.exists(konversi_folder):
224
  os.makedirs(konversi_folder)
225
 
 
137
  print(f'Error getting video resolution: {result.stderr}')
138
  return None
139
 
140
+ def get_video_info(url):
141
+ response = requests.get(url)
142
+ soup = BeautifulSoup(response.text, 'html.parser')
143
  # Mencari judul video di elemen meta dengan name="twitter:title"
144
  title = soup.find("meta", attrs={"name": "twitter:title"})
145
  if title:
 
166
 
167
  print(f"Artis: {actress} dan Series: {series}")
168
 
169
+ # Mencari ThumbnailUrl di elemen meta dengan name="twitter:image"
170
+ thumbnail = soup.find("meta", attrs={"name": "twitter:image"})
171
+ if thumbnail:
172
+ thumbnail_url = thumbnail['content']
173
+
174
+ # Mencari VideoUrl
175
+ script_tag = soup.find('script', type='application/ld+json')
176
+ data = json.loads(script_tag.string)
177
+ selected_video_url = None
178
+ for item in data['@graph']:
179
+ if item['@type'] == 'VideoObject':
180
+ selected_video_url = item['contentURL']
181
+
182
+ return actress, series, title, selected_video_url, thumbnail_url
183
 
184
  def get_digits(series: str, thumbnail_url: str):
185
  if series == 'Cospuri':
 
234
 
235
  def convert_videos(height, filename):
236
  download_folder = os.path.dirname(filename)
237
+ konversi_folder = '/home/user/app/Hasil Konversi'
238
  if not os.path.exists(konversi_folder):
239
  os.makedirs(konversi_folder)
240
 
trailer.py CHANGED
@@ -1,7 +1,6 @@
1
  from bs4 import BeautifulSoup
2
  import requests
3
  import os
4
- import json
5
  from others import *
6
 
7
  def trailer(url):
@@ -18,63 +17,19 @@ def trailer(url):
18
  soup = BeautifulSoup(response.text, 'html.parser')
19
 
20
  # Dapatkan variabel artis dan seri
21
- actress, series, title, video_title = get_video_info(soup)
22
-
23
- # Mencari thumbnailUrl di elemen meta dengan name="twitter:image"
24
- thumbnail = soup.find("meta", attrs={"name": "twitter:image"})
25
- if thumbnail:
26
- thumbnail_url = thumbnail['content']
27
- print(f"Thumbnail URL: {thumbnail_url}")
28
- else:
29
- print("Tidak ditemukan elemen meta dengan name twitter:image")
30
-
31
- if title and thumbnail and thumbnail_url:
32
- response = requests.get(thumbnail_url)
33
- if response.status_code == 200:
34
-
35
- thumbnail_directory = f"{thumbnail_dir}/{series}"
36
- if not os.path.exists(thumbnail_directory):
37
- os.makedirs(thumbnail_directory)
38
-
39
- # Dapatkan kode Digit
40
- digits = get_digits(series, thumbnail_url)
41
- thumbnail_name = f"{series} {digits} - {actress}.jpg"
42
-
43
- with open(f"{thumbnail_directory}/{thumbnail_name}", 'wb') as f:
44
- f.write(response.content)
45
- print(f"Gambar thumbnail berhasil diunduh dengan nama file {thumbnail_name}")
46
- else:
47
- print(f"Gagal mengunduh gambar thumbnail dari {thumbnail_url}")
48
-
49
- else:
50
- print("Tidak dapat mengunduh gambar thumbnail karena tidak ditemukan thumbnail URL atau judul video")
51
-
52
- # Mencari Video
53
- script_tag = soup.find('script', type='application/ld+json')
54
- data = json.loads(script_tag.string)
55
- selected_video_url = None
56
- for item in data['@graph']:
57
- if item['@type'] == 'VideoObject':
58
- selected_video_url = item['contentURL']
59
- break
60
 
 
 
 
61
  # Membuat judul video
62
- video_name = f"{series} {digits} - {actress}.mp4"
63
-
64
- if selected_video_url:
65
- status = download_file(selected_video_url, video_title, video_dir)
66
- print(f"Video trailer berhasil diunduh dengan nama file {video_name}")
67
-
68
- for filename in os.listdir(video_dir):
69
- if video_title in filename and filename.endswith('.mp4'):
70
- os.rename(os.path.join(video_dir, filename), os.path.join(video_dir, video_name))
71
-
72
- else:
73
- print("Tidak dapat mengunduh video karena tidak ditemukan URL atau judul video")
74
 
75
  print("==================================================================================")
76
  # Mengkonversi video
77
- output_file = convert_videos(720, video_dir)
78
  print("==================================================================================")
79
  # Menggabungkan video
80
  output_file = join_video()
@@ -84,4 +39,4 @@ def trailer(url):
84
  video_info += "Code: {digits}/n"
85
  video_info += "Actress: {actress}/n"
86
 
87
- return output_file, video_name, video_info
 
1
  from bs4 import BeautifulSoup
2
  import requests
3
  import os
 
4
  from others import *
5
 
6
  def trailer(url):
 
17
  soup = BeautifulSoup(response.text, 'html.parser')
18
 
19
  # Dapatkan variabel artis dan seri
20
+ actress, series, title, video_url, thumbnail_url = get_video_info(soup)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ # Dapatkan kode Digit
23
+ digits = get_digits(series, thumbnail_url)
24
+
25
  # Membuat judul video
26
+ judul = f"{series} {digits} - {actress}"
27
+ thumbnail_file = download_file(video_url, judul, thumbnail_dir)
28
+ video_file = download_file(video_url, judul, video_dir)
 
 
 
 
 
 
 
 
 
29
 
30
  print("==================================================================================")
31
  # Mengkonversi video
32
+ output_file = convert_videos(720, video_file)
33
  print("==================================================================================")
34
  # Menggabungkan video
35
  output_file = join_video()
 
39
  video_info += "Code: {digits}/n"
40
  video_info += "Actress: {actress}/n"
41
 
42
+ return output_file, judul, video_info