Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
youtube-dl downloads as .ogg and ffmpeg does not convert correctly #6204
Comments
|
Post the steps you follow so that we can reproduce the problem, including the youtube-dl command (with the output you get with the |
|
Well I use youtube-dl in a tool I helped developing and it stopped working recently. I'll try and go in full detail so bare with me.
(1) Is the command I use to call youtube-dl When I specify
(1) The command used for calling youtube-dl I just noticed that in the first example (without the I understand if this is possibly not very helpful or clear. Please let me know if I can do anything to make this more clear. |
|
This is the python file that does most of the work. It calls some utilities that are in a seperate file. If any of these need explanation, please let me know. # -*- coding: utf-8 -*-
# Import dependencies.
from __future__ import division
import os
import os.path
import string
import os.path
import urllib2 as urllib
from os.path import expanduser
from utils import Utils
from playlist import Playlist
from mutagen.mp4 import MP4, MP4Cover
from distutils.spawn import find_executable
# Youtube instance that downloads playlists from Youtube.com.
class Youtube():
# Create new instance of Youtube with forced boolean.
def __init__(self, forced):
self.forced = forced
# Generate search query from a given track.
@staticmethod
def query(track):
GLOBAL_QUERY = 'Audio'
enc = (track['title'], track['artist'], GLOBAL_QUERY)
q = ' '.join(enc)
return Utils.clean_string(q, False)
# Download the given track to the given download path.
def download_track(self, track, path):
path = Utils.clean_string(Utils.full_path(track, path, 'm4a'), False)
path = filter(lambda x: x in string.printable, path)
path = path.replace('~', expanduser('~'))
if self.forced:
if os.path.exists(path):
os.system('rm "' + path + '"')
query = Utils.clean_string(Youtube.query(track), False)
youtubedlpath = find_executable('youtube-dl')
enc = (youtubedlpath, ' -x --audio-format m4a --verbose -o "', path, '" ytsearch:"', query, '"')
command = ''.join(enc)
command = filter(lambda x: x in string.printable, command)
print command
os.system(command.encode('utf-8'))
# Download the given playlist to the given download path.
def download(self, playlist, path):
if playlist.length() == 0:
print 'Invalid playlist.'
os._exit(1)
playlist.reset()
#Utils.progress(0)
total = playlist.length()
current = 0
while playlist.has_next():
playlist.next()
track = playlist.current_track()
self.download_track(track, path)
Youtube.tag(track, path)
current += 1
progress = (current / total) * 100
#Utils.progress(progress)
# Set the ID3 tags of the given track to the file at the given path.
@staticmethod
def tag(track, path):
path = Utils.full_path(track, path, 'm4a')
path = filter(lambda x: x in string.printable, path)
path = path.replace('~', expanduser('~'))
if not os.path.exists(path):
return;
audio = MP4(path)
print track
if track['album_type'] == 'single':
track['album_name'] += ' - Single'
audio['\xa9nam'] = track['title'].encode('utf-8')
audio['\xa9ART'] = track['artist'].encode('utf-8')
audio['\xa9alb'] = track['album_name'].encode('utf-8')
audio['aART'] = track['album_artist'].encode('utf-8')
audio['cprt'] = track['copyright'].encode('utf-8')
audio['disk'] = [(1, 1)]
audio['trkn'] = [(int(track['track']), int(track['maxtracks']))]
audio['\xa9day'] = track['year']
if track['explicit']:
audio['rtng'] = [(str(4))]
cover = track['album_url'].encode('utf-8')
fd = urllib.urlopen(cover)
covr = MP4Cover(fd.read(), getattr(MP4Cover,'FORMAT_PNG' if cover.endswith('png') else 'FORMAT_JPEG'))
fd.close()
audio['covr'] = [covr]
audio.save() |
|
Ok, the problem is that you specify the extension in the output template: Since you seem to only be interested in getting the audio in If this still fails, I'll try to inspect the rest of your code. |
|
This worked! Thank you very much! |
I'm trying to download some videos and extract audtio and it seems to me that if the video is .webm (which I believe is a HTML5 youtube video) youtube-dl downloads the audio as .ogg. When I specify
--audio-format m4ait downloads the songs and converts it. However, when I try setting the tags with mutagen in Python it raises the error that it's not a .m4a (mpeg-4) file and thus can not set the tags. Is this an issue related to youtube-dl or do I have to search the problem elsewhere (e.g. with ffmpeg or mutagen)