Spaces:
Paused
Paused
Update ccc.py
Browse files
ccc.py
CHANGED
|
@@ -3,11 +3,15 @@ import requests
|
|
| 3 |
import random
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
import os
|
|
|
|
| 6 |
|
|
|
|
| 7 |
WEBHOOK_URL = os.environ['web']
|
| 8 |
BASE_URL = "https://tidal.com/browse/track/"
|
| 9 |
-
TRACK_CHECK_INTERVAL = 1
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def send_webhook_message(track_link, track_info):
|
| 13 |
data = {
|
|
@@ -16,7 +20,7 @@ def send_webhook_message(track_link, track_info):
|
|
| 16 |
response = requests.post(WEBHOOK_URL, json=data)
|
| 17 |
|
| 18 |
if response.status_code != 204:
|
| 19 |
-
print(f"
|
| 20 |
|
| 21 |
def check_tidal_track(track_id):
|
| 22 |
try:
|
|
@@ -24,7 +28,7 @@ def check_tidal_track(track_id):
|
|
| 24 |
headers = {
|
| 25 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
| 26 |
}
|
| 27 |
-
response = requests.get(url, headers=headers)
|
| 28 |
|
| 29 |
if response.status_code == 200:
|
| 30 |
soup = BeautifulSoup(response.content, 'html.parser')
|
|
@@ -35,7 +39,7 @@ def check_tidal_track(track_id):
|
|
| 35 |
if title_element:
|
| 36 |
# Try to find artist information
|
| 37 |
artist_element = soup.find('a', class_="artist-link")
|
| 38 |
-
artist_name = artist_element.text if artist_element else "
|
| 39 |
|
| 40 |
track_info = f"{title_element.text}\n{artist_name}"
|
| 41 |
return True, track_info
|
|
@@ -48,6 +52,8 @@ def check_tidal_track(track_id):
|
|
| 48 |
def main():
|
| 49 |
current_track_id = START_TRACK_ID
|
| 50 |
|
|
|
|
|
|
|
| 51 |
while True:
|
| 52 |
try:
|
| 53 |
track_exists, track_info = check_tidal_track(current_track_id)
|
|
|
|
| 3 |
import random
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
import os
|
| 6 |
+
import sys
|
| 7 |
|
| 8 |
+
# Get webhook URL from environment variable
|
| 9 |
WEBHOOK_URL = os.environ['web']
|
| 10 |
BASE_URL = "https://tidal.com/browse/track/"
|
| 11 |
+
TRACK_CHECK_INTERVAL = 0.1 # Reduced to 0.1 seconds for much faster checking
|
| 12 |
+
|
| 13 |
+
# Get starting track ID from command line argument, default to 0 if not provided
|
| 14 |
+
START_TRACK_ID = int(sys.argv[1]) if len(sys.argv) > 1 else 0
|
| 15 |
|
| 16 |
def send_webhook_message(track_link, track_info):
|
| 17 |
data = {
|
|
|
|
| 20 |
response = requests.post(WEBHOOK_URL, json=data)
|
| 21 |
|
| 22 |
if response.status_code != 204:
|
| 23 |
+
print(f"Failed to send webhook: {response.status_code}")
|
| 24 |
|
| 25 |
def check_tidal_track(track_id):
|
| 26 |
try:
|
|
|
|
| 28 |
headers = {
|
| 29 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
| 30 |
}
|
| 31 |
+
response = requests.get(url, headers=headers, timeout=5)
|
| 32 |
|
| 33 |
if response.status_code == 200:
|
| 34 |
soup = BeautifulSoup(response.content, 'html.parser')
|
|
|
|
| 39 |
if title_element:
|
| 40 |
# Try to find artist information
|
| 41 |
artist_element = soup.find('a', class_="artist-link")
|
| 42 |
+
artist_name = artist_element.text if artist_element else " Artist"
|
| 43 |
|
| 44 |
track_info = f"{title_element.text}\n{artist_name}"
|
| 45 |
return True, track_info
|
|
|
|
| 52 |
def main():
|
| 53 |
current_track_id = START_TRACK_ID
|
| 54 |
|
| 55 |
+
print(f"Starting from track ID: {current_track_id}")
|
| 56 |
+
|
| 57 |
while True:
|
| 58 |
try:
|
| 59 |
track_exists, track_info = check_tidal_track(current_track_id)
|