How to subscribe tube archivist to your subscribed youtube channels
Let's say you want tube archivist to subscribe to all the youtube channels you're actually subscribed to. This script will take in a list of youtube channel urls and subscribe you to each one
you'll need to create a list of the urls of the youtube channels you want to subscribe to - I know there's solutions out there but any llm should be able to write you the script easily.
then create a file wiht those urls, and feed it into this script. A lot faster than manually doing so if you're subscribe to over 400 channels like me
#!/usr/bin/env python3
"""
Script to bulk import YouTube channels into TubeArchivist from a text file.
"""
import sys
import time
import subprocess
def subscribe_to_channel(channel_identifier):
"""Subscribe to a channel in TubeArchivist using the identifier (URL, handle, or ID)."""
try:
# Clean up the identifier
channel = channel_identifier.strip()
# Format the identifier based on the debug info we observed
# If it's a URL with a handle, extract just the handle
if '@' in channel and ('youtube.com' in channel or 'youtu.be' in channel):
parts = channel.split('@')
channel = '@' + parts[1].split('/')[0]
# If it's a standard channel ID URL, extract the ID
elif '/channel/' in channel:
channel = channel.split('/channel/')[1].split('/')[0].strip()
# Use the subscribe_to function with the identifier
cmd = ['docker', 'exec', 'tube-archivist', 'bash', '-c',
f'cd /app && python manage.py shell -c "from task.tasks import subscribe_to; subscribe_to.delay(\\"{channel}\\")"']
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
return True
else:
print(f"Error output: {result.stderr}")
return False
except Exception as e:
print(f"Error subscribing to channel {channel_identifier}: {e}")
return False
def main():
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} channels_file.txt")
sys.exit(1)
channels_file = sys.argv[1]
try:
with open(channels_file, 'r') as f:
channels = f.readlines()
except Exception as e:
print(f"Error reading file: {e}")
sys.exit(1)
# Clean up channel identifiers
channels = [channel.strip() for channel in channels if channel.strip()]
successful = 0
failed = 0
# Process each channel
for i, channel in enumerate(channels):
print(f"Processing {i+1}/{len(channels)}: {channel}")
if subscribe_to_channel(channel):
successful += 1
print(f" Success!")
else:
failed += 1
print(f" Failed to subscribe.")
# Sleep briefly to avoid overwhelming the system
time.sleep(1)
print(f"Finished processing {len(channels)} channels")
print(f"Successfully subscribed to {successful} channels")
print(f"Failed to subscribe to {failed} channels")
if __name__ == "__main__":
main()
Posted Jun 23, 2025, 4:11 AM UTC
25