pytube වලට මොනව වෙලාද ?😟...Help

garfieldzz

Well-known member
  • May 28, 2014
    2,424
    3,043
    113
    ජෝන්ගෙ ගෙදර
    වැඩ නැහැනේ. මට මේක run කරගන්න help (audio_streams = video.streams.filter(only_audio=True) වලින් නතරවෙනවා ෆ්‍රෙන්. pytube3 වලටත් එහෙමමයි එන්නේ. වෙනද කිසි ප්‍රශ්නයක් අවේ නැතුව වැඩ කරා. github එකෙත් තව එවුන් දාල තිබුන වැඩ නෑ කියල.

    Code:
    !pip install pytube
    
    from pytube import YouTube
    import os
    
    url = 'https://www.youtube.com/watch?v=uYDPLGMlKOQ'
    video = YouTube(url)
    
    audio_streams = video.streams.filter(only_audio=True)
    
    audio_stream = next((stream for stream in audio_streams if stream.mime_type == 'audio/webm'), None)
    
    if audio_stream is None:
      audio_stream = next((stream for stream in audio_streams if stream.mime_type == 'audio/mp4'), None)
    
    if audio_stream is None:
      raise ValueError('No audio streams found')
    
    audio_filename = video.title + '.webm'
    audio_stream.download(output_path='/content/drive/MyDrive/Server2/Mp3', filename=audio_filename)
    
    mp3_filename = video.title + '.mp3'
    os.system(f'ffmpeg -i "/content/drive/MyDrive/Server2/Mp3/{audio_filename}" "/content/drive/MyDrive/Server2/Mp3/{mp3_filename}"')
    
    print(f"Downloaded audio file: {audio_filename}")
    print(f"Converted mp3 file: {mp3_filename}")
    
    os.remove(f"/content/drive/MyDrive/Server2/Mp3/{audio_filename}")
    print(f"Deleted webm file: {audio_filename}")

    මෙන්න මේක එන්නේ

    Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
    Requirement already satisfied: pytube in /usr/local/lib/python3.10/dist-packages (12.1.3)

    ---------------------------------------------------------------------------

    KeyError Traceback (most recent call last)

    <ipython-input-2-9c9632ba0d33> in <cell line: 10>()
    8 video = YouTube(url)
    9
    ---> 10 audio_streams = video.streams.filter(only_audio=True)
    11
    12 audio_stream = next((stream for stream in audio_streams if stream.mime_type == 'audio/webm'), None)



    2 frames

    /usr/local/lib/python3.10/dist-packages/pytube/__main__.py in streaming_data(self)
    159 else:
    160 self.bypass_age_gate()
    --> 161 return self.vid_info['streamingData']
    162
    163 @property


    KeyError: 'streamingData'
     
    • Like
    Reactions: kinkon and NRTG

    Bruh656

    Well-known member
  • Jan 5, 2023
    302
    284
    63
    Kaluthara
    pytube update eken kela wela atihi natthan youtube ek ukala ati ekatat. Discord eke botsla ekekwat nah dan. ithin em wena eke okatat kel wena ek samanyai

    official api ek try krl balanna nattan package ekak uberma hdpm

    mek wada krnwd kiyl blpm



    Python:
    import youtube_dl
    
    url = "https://www.youtube.com/watch?v=uYDPLGMlKOQ"
    
    ydl_opts = {
        'format': 'bestaudio/best',
        'outtmpl': '/content/drive/MyDrive/Server2/Mp3/%(title)s.%(ext)s',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
    }
    
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])
    ------ Post added on Apr 30, 2023 at 7:20 PM
     
    • Like
    Reactions: NRTG and garfieldzz

    garfieldzz

    Well-known member
  • May 28, 2014
    2,424
    3,043
    113
    ජෝන්ගෙ ගෙදර
    yt-dlp kiyala aluth ekak tiye youtube-dl eka wenuwata
    Thanks මචන්. වැඩේ ගොඩ:love2:

    Code:
    !pip install pydub yt-dlp
    
    from pydub import AudioSegment
    import os
    import yt_dlp
    
    url = 'https://www.youtube.com/watch?v=uYDPLGMlKOQ'
    output_dir = '/content/drive/MyDrive/Server2/Mp3'
    config = {
        'format': 'bestaudio/best',
        'outtmpl': f'{output_dir}/%(title)s.%(ext)s',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }]
    }
    
    with yt_dlp.YoutubeDL(config) as ydl:
        info_dict = ydl.extract_info(url, download=True)
        title = info_dict['title']
        mp3_file = ydl.prepare_filename(info_dict)
    
    audio = AudioSegment.from_file(mp3_file, format='mp3')
    audio.export(os.path.join(output_dir, f"{title}.mp3"), format='mp3')
    
    print(f"Downloaded audio file: {title}.mp3")
     
    Last edited:
    • Like
    Reactions: B.Chat

    Honey Bunch

    Well-known member
  • Nov 24, 2018
    17,259
    26,717
    113
    Kandy
    බැක්ටිරියා ආසාදනයක් වෙන්න ප්ලුවන් candid B cream eka hodai