Skip to content

Commit

Permalink
fix: #50 - brought back download audio file
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtalhaasghar committed Jan 26, 2023
1 parent b9e69a8 commit b46dab4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mps_youtube/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def download(dltype, num):
# perform download(s)
# dl_filenames = [args[1]]
# f = _download(*args, **kwargs)
success = pafy.download_video(song.ytid, config.DDIR.get)
success = pafy.download_video(song.ytid, config.DDIR.get, True if dltype.startswith("da") else False)
if success:
g.message = "Saved \'" + song.title + "\' to " + c.g + config.DDIR.get + c.w

Expand Down
9 changes: 8 additions & 1 deletion mps_youtube/pafy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_video_streams(ytid):
info_dict = ydl.extract_info(ytid, download=False)
return [i for i in info_dict['formats'] if i.get('format_note') != 'storyboard']

def download_video(ytid, folder):
def download_video(ytid, folder, audio_only=False):

'''
Given a youtube video id and target folder, this function will download video to that folder
Expand All @@ -47,6 +47,13 @@ def download_video(ytid, folder):
ytdl_format_options = {
'outtmpl': os.path.join(folder, '%(title)s-%(id)s.%(ext)s')
}
if audio_only:
ytdl_format_options['format'] = 'bestaudio/best'
ytdl_format_options['postprocessors'] =[{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}]

with yt_dlp.YoutubeDL(ytdl_format_options) as ydl:
ydl.download('https://www.youtube.com/watch?v=%s' % ytid)
Expand Down

0 comments on commit b46dab4

Please sign in to comment.