File size: 4,396 Bytes
4691839
b62586b
72aa956
12c8076
 
4691839
12c8076
 
 
81ba6f6
12c8076
4691839
 
 
 
 
 
 
 
 
 
 
 
 
 
e07bd3d
 
 
4691839
e07bd3d
 
 
4691839
e07bd3d
 
 
4691839
 
 
e07bd3d
 
 
 
 
 
 
 
 
 
 
4691839
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e07bd3d
a12586d
005f3ed
81ba6f6
 
3260469
81ba6f6
 
 
 
3260469
 
81ba6f6
 
 
 
3260469
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
from bs4 import BeautifulSoup
import json, os
from others import *
import cloudscraper
scraper = cloudscraper.create_scraper()

def get_info_rule34(link):

    response = scraper.get(link)
    soup = BeautifulSoup(response.text, 'html.parser')

    # Mencari judul video di elemen dengan class title_video
    title = soup.find(class_="title_video")
    if title:
        video_title = title.text.strip().replace('/', ' -')
        idx = video_title.find(']')
        if idx != -1 and idx + 1 < len(video_title) and video_title[idx + 1].isalpha():
            video_title = video_title[:idx + 1] + ' ' + video_title[idx + 1:]

        video_title = video_title.title()
        print(f"Judul Video: {video_title}")
    else:
        print("Judul Video tidak ditemukan")

    # Mencari nama artist di elemen dengan class col
    cols = soup.find_all(class_="col")  # Menggunakan find_all untuk mendapatkan semua elemen dengan class col
    artists = []

    if cols:
        for col in cols:  # Melakukan iterasi untuk setiap elemen col
            # Mencari elemen dengan class label yang memiliki teks yang cocok dengan "Artist"
            label = col.find(class_="label", string="Artist")
            if label:
                # Mencari semua elemen dengan class item btn_link yang merupakan saudara dari label
                items = label.find_next_siblings(class_="item btn_link")
                for item in items:
                    # Mencari elemen dengan class name yang merupakan anak dari item
                    name = item.find(class_="name")
                    if name:
                        if "VA" not in name.text.strip():
                            artists.append(name.text.strip())
                break  # Keluar dari loop jika sudah menemukan label artist

        if artists:
            artists.sort()  # Mengurutkan nama-nama artist
            artist_string = ", ".join(artists)  # Menggabungkan nama-nama artist dengan koma
            print(f"Nama Artist: {artist_string}")
        else:
            artist_string = "Unknown Artist"
            print("Nama Artist tidak ditemukan")
    else:
        print("Elemen col tidak ditemukan")

    # Mencari thumbnailUrl di script type="application/ld+json"
    script = soup.find("script", type="application/ld+json")
    if script:
        data = json.loads(script.string)
        if "thumbnailUrl" in data:
            thumbnail_url = data['thumbnailUrl']
            print(f"Thumbnail URL: {thumbnail_url}")
        else:
            print("Tidak ditemukan thumbnail URL")
    else:
        print("Tidak ditemukan elemen script dengan type application/ld+json")

    # Mencari resolusi yang tersedia
    resolutions = []
    for a in soup.find_all('a'):
        if 'MP4' in a.text and 'p' in a.text:
            resolutions.append(a.text.split()[1])
    if resolutions:
        print("Resolusi yang tersedia: " + ", ".join(resolutions))
    else:
        print("Tidak ditemukan resolusi yang tersedia")

    # Mencari kualitas video 720p atau 480p
    video_quality_elements = soup.find_all("a", class_="tag_item")
    video_quality_720p = None
    video_quality_480p = None
    for element in video_quality_elements:
        if "720p" in element.text:
            video_quality_720p = element['href']
        elif "480p" in element.text:
            video_quality_480p = element['href']

    if video_quality_720p:
        print(f"Video kualitas 720p: {video_quality_720p}")
        video_url = video_quality_720p
    elif video_quality_480p:
        print(f"Video kualitas 480p: {video_quality_480p}")
        video_url = video_quality_480p
    else:
        print("Tidak ditemukan video kualitas 720p atau 480p")
        video_url = None

    return video_title, artist_string, video_url, thumbnail_url

def rule34(link):
    video_info = ""
    video_title, artist, video_url, thumbnail_url = get_info_rule34(link)
    judul = f"{artist} - {video_title}" 
    directory = f"/home/user/app/Hasil Download/Rule34/{artist}"
    if not os.path.exists(directory):
        os.makedirs(directory)
    # Menentukan nama file thumbnail
    thumbnail_file = download_file(thumbnail_url, judul, directory)
    video_file = download_file(video_url, judul, directory)

    video_info = f"Nama Channel: {artist}\n"
    video_info += f"Judul Video: {video_title}\n"
    
    return video_file, judul, video_info, thumbnail_file