jerrrycans commited on
Commit
e3f4af7
·
verified ·
1 Parent(s): f9a9ad9

Update ccc.py

Browse files
Files changed (1) hide show
  1. ccc.py +9 -33
ccc.py CHANGED
@@ -15,9 +15,9 @@ BASE_URL = "https://tidal.com/browse/track/"
15
 
16
  # Configuration - Edit these values as needed
17
  START_TRACK_ID = 20753858 # Change this to your desired starting track ID
18
- TRACK_CHECK_INTERVAL = 0.01 # Reduced interval for faster checking
19
- WEBHOOK_INTERVAL = 5 # Reduced interval for faster updates
20
- MAX_CONCURRENT_DOWNLOADS = 100 # Increased concurrent downloads
21
 
22
  # Queue to store messages to be sent to webhook
23
  webhook_queue = deque()
@@ -69,7 +69,7 @@ async def check_tidal_track(track_id):
69
  }
70
 
71
  async with aiohttp.ClientSession() as session:
72
- async with session.get(url, headers=headers, timeout=3) as response:
73
  # Check status code first - 200 means it exists, 404 means it doesn't
74
  if response.status == 200:
75
  content = await response.text()
@@ -108,7 +108,7 @@ async def tidal_downloader(track_id, song_name, artist_name):
108
 
109
  try:
110
  async with aiohttp.ClientSession() as session:
111
- async with session.post(api_url, json=payload, timeout=5) as response:
112
  if response.status == 200:
113
  data = await response.json()
114
 
@@ -132,8 +132,7 @@ async def tidal_downloader(track_id, song_name, artist_name):
132
 
133
  async def download_file(url):
134
  try:
135
- timeout = aiohttp.ClientTimeout(total=15) # 15 second timeout for downloads
136
- async with aiohttp.ClientSession(timeout=timeout) as session:
137
  async with session.get(url) as response:
138
  if response.status == 200:
139
  # Read the file content directly into memory
@@ -150,8 +149,7 @@ async def upload_to_service(file_content, song_name, artist_name):
150
  try:
151
  upload_url = "https://jerrrycans-wholemusic.hf.space/upload"
152
 
153
- timeout = aiohttp.ClientTimeout(total=30) # 30 second timeout for uploads
154
- async with aiohttp.ClientSession(timeout=timeout) as session:
155
  # Create form data with the correct file name
156
  form = aiohttp.FormData()
157
  form.add_field('file',
@@ -164,7 +162,7 @@ async def upload_to_service(file_content, song_name, artist_name):
164
  form.add_field('artist', artist_name)
165
 
166
  # Send the POST request with a timeout
167
- async with session.post(upload_url, data=form) as response:
168
  if response.status == 200:
169
  result = await response.json()
170
  print(f"Upload successful: {result}")
@@ -228,17 +226,13 @@ async def main():
228
  # Tasks list to manage concurrent jobs
229
  tasks = []
230
 
231
- # Create connection pool with higher limits
232
- connector = aiohttp.TCPConnector(limit=0, force_close=True)
233
- session = aiohttp.ClientSession(connector=connector)
234
-
235
  try:
236
  while True:
237
  # Cleanup completed tasks
238
  tasks = [t for t in tasks if not t.done()]
239
 
240
  # Create new tasks up to the maximum allowed concurrency
241
- while len(tasks) < MAX_CONCURRENT_DOWNLOADS * 3: # Allow more tasks in queue to maximize throughput
242
  task = asyncio.create_task(process_track(current_track_id, semaphore))
243
  tasks.append(task)
244
  current_track_id += 1
@@ -254,24 +248,6 @@ async def main():
254
  # Wait for all tasks to complete
255
  if tasks:
256
  await asyncio.gather(*tasks, return_exceptions=True)
257
-
258
- # Close the session
259
- await session.close()
260
 
261
  if __name__ == "__main__":
262
- # Configure to use a higher limit of open files if on Linux
263
- try:
264
- import resource
265
- resource.setrlimit(resource.RLIMIT_NOFILE, (65536, 65536))
266
- except Exception:
267
- pass
268
-
269
- # Use uvloop if available for better performance
270
- try:
271
- import uvloop
272
- uvloop.install()
273
- print("Using uvloop for better performance")
274
- except ImportError:
275
- pass
276
-
277
  asyncio.run(main())
 
15
 
16
  # Configuration - Edit these values as needed
17
  START_TRACK_ID = 20753858 # Change this to your desired starting track ID
18
+ TRACK_CHECK_INTERVAL = 0.5 # Speed of checking in seconds (lower = faster)
19
+ WEBHOOK_INTERVAL = 10 # Send webhook messages every 10 seconds
20
+ MAX_CONCURRENT_DOWNLOADS = 30 # Maximum number of concurrent downloads
21
 
22
  # Queue to store messages to be sent to webhook
23
  webhook_queue = deque()
 
69
  }
70
 
71
  async with aiohttp.ClientSession() as session:
72
+ async with session.get(url, headers=headers, timeout=5) as response:
73
  # Check status code first - 200 means it exists, 404 means it doesn't
74
  if response.status == 200:
75
  content = await response.text()
 
108
 
109
  try:
110
  async with aiohttp.ClientSession() as session:
111
+ async with session.post(api_url, json=payload) as response:
112
  if response.status == 200:
113
  data = await response.json()
114
 
 
132
 
133
  async def download_file(url):
134
  try:
135
+ async with aiohttp.ClientSession() as session:
 
136
  async with session.get(url) as response:
137
  if response.status == 200:
138
  # Read the file content directly into memory
 
149
  try:
150
  upload_url = "https://jerrrycans-wholemusic.hf.space/upload"
151
 
152
+ async with aiohttp.ClientSession() as session:
 
153
  # Create form data with the correct file name
154
  form = aiohttp.FormData()
155
  form.add_field('file',
 
162
  form.add_field('artist', artist_name)
163
 
164
  # Send the POST request with a timeout
165
+ async with session.post(upload_url, data=form, timeout=60) as response:
166
  if response.status == 200:
167
  result = await response.json()
168
  print(f"Upload successful: {result}")
 
226
  # Tasks list to manage concurrent jobs
227
  tasks = []
228
 
 
 
 
 
229
  try:
230
  while True:
231
  # Cleanup completed tasks
232
  tasks = [t for t in tasks if not t.done()]
233
 
234
  # Create new tasks up to the maximum allowed concurrency
235
+ while len(tasks) < MAX_CONCURRENT_DOWNLOADS * 2: # Allow more tasks in queue than concurrent downloads
236
  task = asyncio.create_task(process_track(current_track_id, semaphore))
237
  tasks.append(task)
238
  current_track_id += 1
 
248
  # Wait for all tasks to complete
249
  if tasks:
250
  await asyncio.gather(*tasks, return_exceptions=True)
 
 
 
251
 
252
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  asyncio.run(main())