Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transcoder based on ffmpeg #83

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LATEST_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2011.01.30
2011.02.22
116 changes: 116 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# youtube-dl

Allows you to download and transcode video from supported sites. Needs ffmpeg for transcoding to work.

## Supported sites

* Youtube
* Metacafe
* Dailymotion
* Google
* Photobucket
* Yahoo
* DepositFiles
* Facebook
* Sites with JW Player

## Installation

$ sudo apt-get install ffmpeg # for Ubuntu
$ sudo wget --no-check-certificate https://github.com/dz0ny/youtube-dl/raw/master/youtube-dl -O /usr/local/bin/youtube-dl && sudo chmod a+x /usr/local/bin/youtube-dl

## Usage

### Example

$ youtube-dl http://www.youtube.com/watch?v=BRHRssf3B6o -T mp4 -C 'sh -c "cp <filepath> <stitle>.mp4 && rm <filepath>"'

Command line options:

$ youtube-dl [options] url...

Options:
-h, --help print this help text and exit
-v, --version print program version and exit
-U, --update update this program to latest stable version
-i, --ignore-errors continue on download errors
-r LIMIT, --rate-limit=LIMIT
download rate limit (e.g. 50k or 44.6m)
-R RETRIES, --retries=RETRIES
number of retries (default is 10)
--playlist-start=NUMBER
playlist video to start at (default is 1)
--playlist-end=NUMBER
playlist video to end at (default is last)
--dump-user-agent display the current browser identification

Authentication Options:
-u USERNAME, --username=USERNAME
account username
-p PASSWORD, --password=PASSWORD
account password
-n, --netrc use .netrc authentication data

Video Format Options:
-f FORMAT, --format=FORMAT
video format code
--all-formats download all available video formats
--max-quality=FORMAT
highest quality format to download

Verbosity / Simulation Options:
-q, --quiet activates quiet mode
-s, --simulate do not download video
-g, --get-url simulate, quiet but print URL
-e, --get-title simulate, quiet but print title
--get-thumbnail simulate, quiet but print thumbnail URL
--get-description simulate, quiet but print video description
--get-filename simulate, quiet but print output filename
--no-progress do not print progress bar
--console-title display progress in console titlebar

Filesystem Options:
-t, --title use title in file name
-l, --literal use literal title in file name
-A, --auto-number number downloaded files starting from 00000
-o TEMPLATE, --output=TEMPLATE
output filename template
-a FILE, --batch-file=FILE
file containing URLs to download ('-' for stdin)
-w, --no-overwrites
do not overwrite files
-c, --continue resume partially downloaded files
--cookies=FILE file to dump cookie jar to
--no-part do not use .part files
--no-mtime do not use the Last-modified header to set the file
modification time

Transcoding Options (uses ffmpeg):
-T FILE_TYPE, --transcode_to=FILE_TYPE
transcode to specific video or audio format (example:
mp3 mp4 mov mkv)
--transcode_extra=ARGS
pass additional parameters to ffmpeg (example: -vcodec
libx264 -vpre slow -vpre ipod640 -b 2048k -acodec
libfaac -ab 96k)

Post download action:
-C COMMAND, --command=COMMAND
command to run after file has been downloaded
(example: 'sh -c "cp <filepath> <stitle>.mp4 && rm <filepath>"' )

# License

Public domain code


# Authors

* Ricardo Garcia Gonzalez
* Danny Colligan
* Benjamin Johnson
* Vasyl' Vavrychuk
* Witold Baryluk
* Paweł Paprota
* Gergely Imreh
* Janez Troha
94 changes: 93 additions & 1 deletion youtube-dl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Author: Witold Baryluk
# Author: Paweł Paprota
# Author: Gergely Imreh
# Author: Janez Troha
# License: Public domain code
import cookielib
import ctypes
Expand All @@ -21,6 +22,7 @@ import netrc
import os
import os.path
import re
import shlex
import socket
import string
import StringIO
Expand Down Expand Up @@ -1765,7 +1767,10 @@ class GenericIE(InfoExtractor):
mobj = re.search(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
if mobj is None:
# Broaden the search a little bit
mobj = re.search(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
mobj = re.search(r'[^A-Za-z0-9]?(?:file|source|video_url)=(http[^\'"&]*)', webpage)
if mobj is None:
# Search in javascript
mobj = re.search(r'video_url.+(http[^\'"&]*)', webpage)
if mobj is None:
self._downloader.trouble(u'ERROR: Invalid URL: %s' % url)
return
Expand Down Expand Up @@ -2609,6 +2614,65 @@ class PostProcessor(object):
"""
return information # by default, do nothing

class Transcode(PostProcessor):
"""Post Processor for file transcoding"""
def __init__(self,file_type, args):
# Check for ffmepg first
try:
subprocess.call(['ffmpeg', '-v'], stdout=(file(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
except (OSError, IOError):
raise PostProcessingError(u'ERROR: "ffmpeg" could not be found')

self.file_type = file_type

if args:
self.args = str(args)
else:
self.args = str("")

PostProcessor.__init__(self, None)

def run(self, information):
self._file_path = str(information["filepath"])
basename, extension = os.path.splitext(self._file_path)
self._new_file_path = self._file_path.replace(extension, "."+self.file_type)
self._downloader.to_screen(u'[transcode] Started transcoding of %s to %s' % ( self._file_path, self._new_file_path) )
stringish_command = 'ffmpeg -y -i "%s" %s "%s"' % (self._file_path, self.args, self._new_file_path)
self.encode(stringish_command)
return information

def encode(self, cmd):
pipe = subprocess.Popen(
shlex.split( cmd ),
stdout=(file(os.path.devnull, 'w')),
stderr=subprocess.STDOUT
)
retval = pipe.wait()
while retval == 2 or retval == 1:
pass
self._downloader.to_screen(u'[transcode] Completed transcoding of %s to %s' % ( self._file_path, self._new_file_path) )

class SimplePostProcessor(PostProcessor):
"""Post Processor for file transcoding"""
def __init__(self,command):
self.command_raw = command
PostProcessor.__init__(self, None)

def run(self, information):
for key, value in information.iteritems():
self.command_raw = self.command_raw.replace("<" + key + ">", value)
self.command = shlex.split( str( self.command_raw ) )
self._downloader.to_screen(u'[PostProcessor] Started command %s' % self.command_raw )
pipe = subprocess.Popen(
( self.command )
)
retval = pipe.wait()
while retval == 2 or retval == 1:
pass
self._downloader.to_screen(u'[PostProcessor] Finnished command %s' % self.command_raw )

return information

### MAIN PROGRAM ###
if __name__ == '__main__':
try:
Expand Down Expand Up @@ -2733,6 +2797,18 @@ if __name__ == '__main__':
help='do not use the Last-modified header to set the file modification time', default=True)
parser.add_option_group(filesystem)

transcode = optparse.OptionGroup(parser, 'Transcoding Options (uses ffmpeg)')
transcode.add_option('-T','--transcode_to',
action='store', dest='transcode_to', metavar='FILE_TYPE', help='transcode to specific video or audio format (example: mp3 mp4 mov mkv)', default=False)
transcode.add_option('--transcode_extra',
action='store', dest='transcode_extra', metavar='ARGS', help='pass additional parameters to ffmpeg (example: -vcodec libx264 -vpre slow -vpre ipod640 -b 2048k -acodec libfaac -ab 96k)', default=False)
parser.add_option_group(transcode)

postprocess = optparse.OptionGroup(parser, 'Post download action')
postprocess.add_option('-C','--command',
action='store', dest='post_download_command', metavar='COMMAND', help='command to run after file has been downloaded (example: "sh -c cp <filepath> /tmp/<title>.tmp && rm <filepath>" )', default=False)
parser.add_option_group(postprocess)

(opts, args) = parser.parse_args()

# Open appropriate CookieJar
Expand Down Expand Up @@ -2876,6 +2952,22 @@ if __name__ == '__main__':
# fallback if none of the others work
fd.add_info_extractor(generic_ie)

# Transcodig parser
if opts.transcode_to:
try:
transcoder = Transcode(opts.transcode_to, opts.transcode_extra)
fd.add_post_processor(transcoder)
except PostProcessingError, err:
sys.exit(err)

# Custom command parser
if opts.post_download_command:
try:
post_download_command = SimplePostProcessor(opts.post_download_command)
fd.add_post_processor(post_download_command)
except PostProcessingError, err:
sys.exit(err)

# Update version
if opts.update_self:
update_self(fd, sys.argv[0])
Expand Down