You've already forked amazing-ytdlp-archive
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
729b24debb | ||
![]() |
20e5793cd8 | ||
![]() |
282b895170 |
@@ -26,7 +26,15 @@ def create_app(test_config=None):
|
|||||||
config['CELERY']['beat_schedule'] = {}
|
config['CELERY']['beat_schedule'] = {}
|
||||||
config['CELERY']['beat_schedule']['Renew WebSub endpoints'] = {'task': 'ayta.tasks.websub_renew_expiring', 'schedule': 4000}
|
config['CELERY']['beat_schedule']['Renew WebSub endpoints'] = {'task': 'ayta.tasks.websub_renew_expiring', 'schedule': 4000}
|
||||||
config['CELERY']['beat_schedule']['Process WebSub data'] = {'task': 'ayta.tasks.websub_process_data', 'schedule': 100}
|
config['CELERY']['beat_schedule']['Process WebSub data'] = {'task': 'ayta.tasks.websub_process_data', 'schedule': 100}
|
||||||
config['CELERY']['beat_schedule']['Queue up new videos in static channel playlists'] = {'task': 'ayta.tasks.playlist_to_queue', 'schedule': 5000}
|
config['CELERY']['beat_schedule']['Queue up new videos in static channel playlists'] = {'task': 'ayta.tasks.playlist_to_queue', 'schedule': 50000}
|
||||||
|
|
||||||
|
# Celery task routing
|
||||||
|
# Tasks not defined in this configuration will be routed to the default queue "celery"
|
||||||
|
|
||||||
|
config['CELERY']['task_routes'] = {
|
||||||
|
'ayta.tasks.video_download': {'queue': 'download'},
|
||||||
|
'ayta.tasks.video_queue': {'queue': 'download'}
|
||||||
|
}
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_mapping(config)
|
app.config.from_mapping(config)
|
||||||
|
@@ -51,14 +51,14 @@ def channels():
|
|||||||
return redirect(url_for('admin.channel', channelId=channelId))
|
return redirect(url_for('admin.channel', channelId=channelId))
|
||||||
|
|
||||||
elif task == 'playlist-queue':
|
elif task == 'playlist-queue':
|
||||||
task = playlist_to_queue.delay()
|
task = playlist_to_queue.delay()
|
||||||
flash(f'Task playlist-queue has been queued: {task.id}')
|
flash(f'Task playlist-queue has been queued: {task.id}')
|
||||||
|
|
||||||
generic['currentDate'] = datetime.utcnow()
|
generic['currentDate'] = datetime.utcnow()
|
||||||
channelIds = get_nosql().list_all_channels()
|
channelIds = get_nosql().list_all_channels()
|
||||||
|
|
||||||
for channelId in channelIds:
|
for channelId in channelIds:
|
||||||
channels[channelId] = get_nosql().get_channel_info(channelId)
|
channels[channelId] = get_nosql().get_channel_info(channelId, limited=True)
|
||||||
channels[channelId]['video_count'] = get_nosql().get_channel_videos_count(channelId)
|
channels[channelId]['video_count'] = get_nosql().get_channel_videos_count(channelId)
|
||||||
|
|
||||||
return render_template('admin/channels.html', channels=channels, generic=generic)
|
return render_template('admin/channels.html', channels=channels, generic=generic)
|
||||||
|
@@ -11,7 +11,7 @@ def base():
|
|||||||
channelIds = get_nosql().list_all_channels()
|
channelIds = get_nosql().list_all_channels()
|
||||||
|
|
||||||
for channelId in channelIds:
|
for channelId in channelIds:
|
||||||
channel = get_nosql().get_channel_info(channelId)
|
channel = get_nosql().get_channel_info(channelId, limited=True)
|
||||||
channel['video_count'] = get_nosql().get_channel_videos_count(channelId)
|
channel['video_count'] = get_nosql().get_channel_videos_count(channelId)
|
||||||
channels.append(channel)
|
channels.append(channel)
|
||||||
|
|
||||||
|
@@ -168,8 +168,12 @@ class Mango:
|
|||||||
ids.append(video['id'])
|
ids.append(video['id'])
|
||||||
return tuple(ids)
|
return tuple(ids)
|
||||||
|
|
||||||
def get_channel_info(self, channelId):
|
def get_channel_info(self, channelId, limited=False):
|
||||||
return self.channels.find_one({'id': channelId})
|
projection = {}
|
||||||
|
if limited:
|
||||||
|
projection['playlist'] = 0
|
||||||
|
|
||||||
|
return self.channels.find_one({'id': channelId}, projection)
|
||||||
|
|
||||||
|
|
||||||
def update_channel_key(self, channelId, key, value):
|
def update_channel_key(self, channelId, key, value):
|
||||||
@@ -420,8 +424,7 @@ class Mango:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# add to queue
|
# add to queue
|
||||||
self.download_queue.insert_one({'id': videoId, 'endpoint': endpointId, 'created_time': current_time(object=True), 'status': 'queued'}).inserted_id
|
return self.download_queue.insert_one({'id': videoId, 'endpoint': endpointId, 'created_time': current_time(object=True), 'status': 'queued'}).inserted_id
|
||||||
return True
|
|
||||||
|
|
||||||
def queue_deleteQueue(self, videoId):
|
def queue_deleteQueue(self, videoId):
|
||||||
if self.download_queue.delete_one({'id': videoId}):
|
if self.download_queue.delete_one({'id': videoId}):
|
||||||
@@ -445,6 +448,7 @@ class Mango:
|
|||||||
return None
|
return None
|
||||||
elif self.check_exists(queueItem['id']):
|
elif self.check_exists(queueItem['id']):
|
||||||
self.queue_deleteQueue(queueItem['id'])
|
self.queue_deleteQueue(queueItem['id'])
|
||||||
|
continue
|
||||||
self.download_queue.update_one({'id': queueItem['id']}, {'$set': {'status': 'working'}})
|
self.download_queue.update_one({'id': queueItem['id']}, {'$set': {'status': 'working'}})
|
||||||
return queueItem
|
return queueItem
|
||||||
|
|
||||||
|
@@ -165,13 +165,22 @@ def websub_renew_expiring(hours=6):
|
|||||||
break
|
break
|
||||||
|
|
||||||
@shared_task()
|
@shared_task()
|
||||||
def playlist_to_queue(hours=6):
|
def playlist_to_queue():
|
||||||
from .nosql import get_nosql
|
from .nosql import get_nosql
|
||||||
|
import random
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
channels = get_nosql().list_all_channels(active=True)
|
pivot = datetime.utcnow() - timedelta(days=3) # calculates 3 days before now
|
||||||
|
channels = list(get_nosql().list_all_channels(active=True))
|
||||||
|
random.shuffle(channels) # randomize channelId order because otherwise the queue will follow the channel order as well
|
||||||
|
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
info = get_nosql().get_channel_info()
|
info = get_nosql().get_channel_info(channel)
|
||||||
|
|
||||||
|
# if last_run not set or last_run is older than the pivot (indicating it has not been updated)
|
||||||
|
if not info.get('last_run') or info.get('last_run') < pivot:
|
||||||
|
# skip channel
|
||||||
|
continue
|
||||||
|
|
||||||
for item in info['playlist']['entries']:
|
for item in info['playlist']['entries']:
|
||||||
videoId = item['id']
|
videoId = item['id']
|
||||||
|
Reference in New Issue
Block a user