I am trying to download Youtube captions by pytube.
Everything was fine and I managed to download the video and its caption by xml_captions.
However, when I tried to covert it into .srt format, I got a key error.
---> 83 start = float(child.attrib["start"])
KeyError: 'start'
I wonder what was wrong.
My code is
pip install pytube
from pytube import YouTube
# misc``
import os
import shutil
import math
import datetime
video=YouTube('https://www.youtube.com/watch?v=xxydY73V9bQ')
caption = video.captions['a.en']
caption.xml_captions
srt_format = caption.xml_caption_to_srt(caption.xml_captions)
If sill relevant: tt appears that YouTube has changed the way captions are handled. Here's a discussion with possible solutions.
Related
Unable to download video using pytube
import customtkinter
from pytube import YouTube
def startDownload():
try:
ytLink = link.get()
YouTube(ytLink).streams.get_highest_resolution().download()
except:
print("YouTube link is invalid")
print("Download Complete!")
#Link input
url_var = tkinter.StringVar()
link = customtkinter.CTkEntry(app, width=400, height=40, textvariable=url_var)
link.pack()
#Download button
download = customtkinter.CTkButton(app, text="Download", command=startDownload)
download.pack(padx=10, pady=10)
error in Line number 6. input take but download function not work
output - YouTube link is invalid
Download Complete!
from pytube import Youtube
That's because you are downloading the first one of the available streams which is usually 720p. To download a 360p resolution stream, you can do:
YouTube('https://youtu.be/2lAe1cqCOXo').streams.filter(res="360p").first().download()
Note: this is YouTube, not Youtube.
Short explanation: You need to use filter() to choose a specific resolution you want to download. For example, if you call:
yt = YouTube('https://youtu.be/2lAe1cqCOXo')
it returns the available stream to yt. You can view all the streams by typing:
yt.streams
You can filter which type of filter you want. To filter only 360p streams you can write:
yt.streams.filter(res="360p")
To filter only 360p streams and download the first one type this:
yt.streams.filter(res="360p").first().download()
I'm trying to open several google pages through python webbrowser, and I've gotten it to work, but after opening all the pages, google simply closes unless I manually click it. Why is this happening? Help is appreciated, and thank in advance.
import pyautogui as py
import keyboard as key
import time
chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
webbrowser.register('chrome',None, webbrowser.BackgroundBrowser(chrome_path))
def n_t():
py.hotkey('ctrl', 't')
def m_t():
py.hotkey('ctrl', 'tab')
def gogle():
webbrowser.get('chrome').open('gmail.com')
py.press('enter')
time.sleep(5)
n_t()
py.write('www.youtube.com')
py.press('enter')
n_t()
py.write('hangouts.google.com/authuser=2')
py.press('enter')
n_t()
py.write('stackoverflow.com')
py.press('enter')
m_t()
gogle()
Use this:
import webbrowser
webbrowser.open('https://google.com')
webbrowser.open('https://gmail.com')
webbrowser.open('https://youtube.com')
webbrowser.open('https://stackoverflow.com')
and you're good to go.
import pytube
def video_downloader():
vid_url=str(input("Enter Video URL: "))
print('Connecting, Please wait...')
video=pytube.YouTube(vid_url)
Streams=video.streams
File_name=input('File Name:')
Format=input('Audio Or Video :')
if Format=='Audio':
Filter=Streams.get_audio_only(subtype='mp4')
if Format=='Video':
Filter=Streams.get_highest_resolution()
print('Now downloading:',video.title)
sizer=round(Filter.filesize/1000000)
print('Size:',sizer,'MB')
Filter.download(filename=str(File_name))
print('Done!')
video_downloader()
This is a script I've made recently to download video and audio files from youtube using pytube, but I'm having a hard time trying to add a function or something that could show the user the progress of the download.
i.e: 1%complete 2%complete etc
Any help would be appreciated :)
This is my First Time Answering, apologizes for mistakes.
Reading Pytube Documentation, one may notice that pytube have this option already implemented as a Progress Bar, You will need to call on_progress_callback in your YouTube Object.
from pytube.cli import on_progress
from pytube import YouTube
yt = YouTube(video_url, on_progress_callback=on_progress)
yt.download()
pytubeenter code herefrom pytube.cli import on_progress
from pytube import YouTube as YT
yt =YT ("https://",on_progress_callback=on_progress)
yt.streams.get_highest_resolution().download(output_path="/Users/")
↳ |██████████████████ | 17.
i want to publish an update on bufferapp.com with python.
I installed the python buffer modul: https://github.com/bufferapp/buffer-python
I managed to connect to their api with python3.
But if i use the update.publish() command it gives me the following error:
nameerror: "update" is not defined.
Im using this code:
from pprint import pprint as pp
from colorama import Fore
from buffpy.models.update import Update
from buffpy.managers.profiles import Profiles
from buffpy.managers.updates import Updates
from buffpy.api import API
token = 'awesome_token'
api = API(client_id='client_id',
client_secret='client_secret',
access_token=token)
# publish now
update.publish()
What am i doing wrong?
Thank you for your help.
I am trying to assign a picture to a song, and I have some code that works on mac, but not on PC.
from mutagen.easyid3 import EasyID3
from mutagen.id3 import ID3, APIC, error
from mutagen.mp3 import MP3
def image_assigner(self):
song = MP3(self.file, ID3=ID3)
# add ID3 tag if it doesn't exist
try:
song.add_tags()
except error:
print "we got an image error"
pass
song.tags.add(
APIC(
encoding=3,
mime='image/jpeg',
type=2,
desc=u'Cover',
data=open('example.JPG', 'rb').read()
)
)
song.save()
So on Mac, this code works, but when I try it on my PC, it won't. Any help would be appreciated. Thanks!
Edit
So, after doing some more research, I figured out that this code does save the album artwork to the mp3 file on Mac as well as Windows, but it saves it in ID3v2.4, which Mac can read, but Windows can't read, so it appeared like it didn't save it on Windows. It appears that using the v1=2 option in the mutagen save function should save the tags in ID3v1 (see the Oct. 4th post on this page). It seems to work if I update the tags for album, artist, title, etc., but when I do it for album artwork, it still doesn't show up in Windows explorer. Does anybody have experience in this area and could shed some light on this? Thanks.
Yeah unfortunately Windows doesn't support that version. Instead of just saving it in ID3v1 try saving it in ID3v3 and ID3v1. I use this in my programs and it works great in Windows 8 and OSX.
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error, TRCK, TIT2, TPE1, TALB, TDRC, TCON
audio = MP3([PATH_TO_FILE], ID3=ID3)
audio.tags.delete([PATH_TO_FILE], delete_v1=True, delete_v2=True)
audio.tags.add(
APIC(
encoding=3,
mime='image/jpeg',
type=3,
desc=u'Cover',
data=open([PATH_TO_COVER_IMAGE], 'rb').read()
)
)
audio.save([PATH_TO_FILE], v2_version=3, v1=2)