0 Byte file downlaod while running on docker with cobalt #594

Closed
opened 2025-11-09 09:53:34 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @hextor1 on GitHub (Nov 27, 2024).

problem description

When I try to click on the download button, the file downloads with 0 bytes. I don't know what the issue is. I am running Cobalt with Docker, and after the issue in Oauth, I am using a proxy in my Cobalt docker-compose.yml file. My website is based on pythong django I am not using innertube for search the thumbnail details. i am using youtube_search for fetch the youtube data.

Is it necessary use proxies on this code to fetch the data from youtube? can anybody help me??

Here are the code
from django.http import HttpResponse,JsonResponse,FileResponse
from pytube.exceptions import VideoUnavailable
from django.shortcuts import redirect
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.csrf import ensure_csrf_cookie
from django.conf import settings
from youtube_search import YoutubeSearch
from pytube import YouTube
import io
import json
import re
from urllib.request import urlopen,Request
import os
import json
from django.conf import settings
import threading
import time
import os
import jwt
import datetime
import openai
from dotenv import load_dotenv
load_dotenv()
from .youtube_info import YouTubeVideoInfo

proxieNumber = 0

def search_video(request):
global proxieNumber
if request.method == "POST":
try:
format = request.POST.get("format")
url_type = request.POST.get("type")

        if url_type == "search":
            keyword = request.POST.get("keyword")
            if not keyword:
                return JsonResponse({"error": "Keyword is required for search."}, status=400)
            # print(keyword)
            try:
                results = []
                for i in YoutubeSearch(keyword, max_results=10).to_dict():
                    record = {
                        "id":i["id"],
                        "title":i["title"],
                        "thumbnail":i["thumbnails"][0],
                        "duration":i["duration"],
                        "channel":i["channel"],
                        "format":format,
                        "type":url_type,
                        "download_url":""
                    }
                    print(record)
                    # print(generate_token(record))
                    # print("=========================================")
                    record["url"] = generate_token(record)
                    results.append(record)
                return JsonResponse(results, safe=False, status=200)
            except Exception as e:
                return JsonResponse({"error": f"Error during search: {str(e)}"}, status=500)

        else:
            url = request.POST.get("keyword")
            if not url:
                return JsonResponse({"error": "URL is required."}, status=400)

            try:
                yt_info = YouTubeVideoInfo(url=url)
                if not yt_info.is_valid_url():
                    return JsonResponse({"error": "Invalid YouTube URL."}, status=400)

                # if yt_info.is_valid_url():
                #     print("Video ID:", yt_info.get_id())
                #     print("Title:", yt_info.get_title())                    
                #     print("Thumbnail:", yt_info.get_thumbnail())
                # else:
                #     print("Invalid YouTube URL")

                record = {
                    "id": yt_info.get_id(),
                    "title": " ",
                    "thumbnail": yt_info.get_thumbnail() or "",
                    "duration": "2",
                    "channel": " ",
                    "format": format,
                    "type": url_type,
                    "download_url": ""
                }
                record["url"] = generate_token(record)
                return JsonResponse(record, safe=False, status=200)
            except Exception as e:
                return JsonResponse({"error": f"Error processing URL: {str(e)}"}, status=500)

    except Exception as e:
        return JsonResponse({"error": f"An unexpected error occurred: {str(e)}"}, status=500)
else:
    return JsonResponse({"error": f"{request.method} method not allowed."}, status=405)

your instance configuration

services:
    cobalt-api:
        image: ghcr.io/imputnet/cobalt:7
        restart: unless-stopped
        container_name: cobalt-api
        init: true
        ports:
            - 9000:9000/tcp
        environment:
            API_URL: "https://abc.com"
            API_NAME: "eu-es"
            
            RATELIMIT_MAX: 200000
            API_EXTERNAL_PROXY: http://username:password@ip:port
Originally created by @hextor1 on GitHub (Nov 27, 2024). ### problem description When I try to click on the download button, the file downloads with 0 bytes. I don't know what the issue is. I am running Cobalt with Docker, and after the issue in Oauth, I am using a proxy in my Cobalt docker-compose.yml file. My website is based on pythong django I am not using innertube for search the thumbnail details. i am using youtube_search for fetch the youtube data. Is it necessary use proxies on this code to fetch the data from youtube? can anybody help me?? Here are the code from django.http import HttpResponse,JsonResponse,FileResponse from pytube.exceptions import VideoUnavailable from django.shortcuts import redirect from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import ensure_csrf_cookie from django.conf import settings from youtube_search import YoutubeSearch from pytube import YouTube import io import json import re from urllib.request import urlopen,Request import os import json from django.conf import settings import threading import time import os import jwt import datetime import openai from dotenv import load_dotenv load_dotenv() from .youtube_info import YouTubeVideoInfo proxieNumber = 0 def search_video(request): global proxieNumber if request.method == "POST": try: format = request.POST.get("format") url_type = request.POST.get("type") if url_type == "search": keyword = request.POST.get("keyword") if not keyword: return JsonResponse({"error": "Keyword is required for search."}, status=400) # print(keyword) try: results = [] for i in YoutubeSearch(keyword, max_results=10).to_dict(): record = { "id":i["id"], "title":i["title"], "thumbnail":i["thumbnails"][0], "duration":i["duration"], "channel":i["channel"], "format":format, "type":url_type, "download_url":"" } print(record) # print(generate_token(record)) # print("=========================================") record["url"] = generate_token(record) results.append(record) return JsonResponse(results, safe=False, status=200) except Exception as e: return JsonResponse({"error": f"Error during search: {str(e)}"}, status=500) else: url = request.POST.get("keyword") if not url: return JsonResponse({"error": "URL is required."}, status=400) try: yt_info = YouTubeVideoInfo(url=url) if not yt_info.is_valid_url(): return JsonResponse({"error": "Invalid YouTube URL."}, status=400) # if yt_info.is_valid_url(): # print("Video ID:", yt_info.get_id()) # print("Title:", yt_info.get_title()) # print("Thumbnail:", yt_info.get_thumbnail()) # else: # print("Invalid YouTube URL") record = { "id": yt_info.get_id(), "title": " ", "thumbnail": yt_info.get_thumbnail() or "", "duration": "2", "channel": " ", "format": format, "type": url_type, "download_url": "" } record["url"] = generate_token(record) return JsonResponse(record, safe=False, status=200) except Exception as e: return JsonResponse({"error": f"Error processing URL: {str(e)}"}, status=500) except Exception as e: return JsonResponse({"error": f"An unexpected error occurred: {str(e)}"}, status=500) else: return JsonResponse({"error": f"{request.method} method not allowed."}, status=405) ### your instance configuration ```shell services: cobalt-api: image: ghcr.io/imputnet/cobalt:7 restart: unless-stopped container_name: cobalt-api init: true ports: - 9000:9000/tcp environment: API_URL: "https://abc.com" API_NAME: "eu-es" RATELIMIT_MAX: 200000 API_EXTERNAL_PROXY: http://username:password@ip:port ```
GiteaMirror added the instance hosting help label 2025-11-09 09:53:34 -06:00
Author
Owner

@wukko commented on GitHub (Nov 28, 2024):

your proxy's ip address might be blocked by googlevideo, we can't help you with that unfortunately

@wukko commented on GitHub (Nov 28, 2024): your proxy's ip address might be blocked by googlevideo, we can't help you with that unfortunately
Sign in to join this conversation.