#🔒 i am an absolute newbie in python.

16 messages · Page 1 of 1 (latest)

echo mulch
#

i am creating an app that converts long form video into short form video for tiktok or youtube shorts. but there is a problem. i dont know a lot about python. if u are willing to help me it would be so sweet. I am currently encountering multiple problems. here is the code:

import ffmpeg
from pytube import YouTube
from transformers import pipeline
import os

def download_video(video_url, save_path="C:\\Users\\Alexander\\Downloads\\maxflipking.mp4"):
    try:
        yt = YouTube(video_url)
        yt_stream = yt.streams.get_highest_resolution()
        download_path = yt_stream.download(filename=save_path)
        print(f"Video downloaded at: {download_path}")
        return download_path
    except Exception as e:
        print(f"Error: {e}")
        return None

def extract_audio_from_video(video_path, output_path="extracted_audio.wav"):
    try:
        # Use ffmpeg-python with explicit path to ffmpeg
        ffmpeg.input(video_path).output(output_path, format='wav').run(overwrite_output=True, ffmpeg='C:\\ffmpeg\\bin\\ffmpeg.exe')
        print(f"Audio extracted to: {output_path}")
        return output_path
    except Exception as e:
        print(f"Error extracting audio: {e}")
        return None

def transcribe_audio_huggingface(audio_path):
    try:
        asr = pipeline('automatic-speech-recognition', model='openai/whisper-large')
        transcription = asr(audio_path)["text"]
        print(f"Transcription: {transcription}")
        return transcription
    except Exception as e:
        print(f"Error during transcription: {e}")
        return None

def process_youtube_video(video_url):
    video_path = download_video(video_url)
    if video_path:
        audio_path = extract_audio_from_video(video_path)
        if audio_path:
            transcription = transcribe_audio_huggingface(audio_path)
            return transcription
    return None
barren elbowBOT
#

@echo mulch

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gray junco
#

what problems are you facing

echo mulch
#

when i run the code it does nothing. i tried googling, i tried AI, but i just cant find the solution

gray junco
#

oh you haven't called any functions

echo mulch
#

i ran python <name of the file>

placid glacier
#

I dont think youtube allows automated downloading of videos

gray junco
#

you have defined a series of functions but they are not used anywhere

echo mulch
#

i have video downloaded on my pc

#

then i add the path into the code

#

and yes youtube has it forbiden

#

okay so what could be a fix here

gray junco
#

!ytdl

barren elbowBOT
#
Our youtube-dl, or equivalents, policy

Per Python Discord's Rule 5, we are unable to assist with questions related to youtube-dl, pytube, or other YouTube video downloaders, as their usage violates YouTube's Terms of Service.

For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2021-03-17:

The following restrictions apply to your use of the Service. You are not allowed to:

1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service;  (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;

3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTube’s robots.txt file; (b) with YouTube’s prior written permission; or (c) as permitted by applicable law;

9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
barren elbowBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.