Skip to content

Commit

Permalink
tumblr_backup: add option --cookiefile for youtube-dl
Browse files Browse the repository at this point in the history
Fixes #132
  • Loading branch information
bbolli committed Jul 4, 2019
1 parent 73e5130 commit 4961a2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tumblr_backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ You can see an example of its output [on my home page](http://drbeat.li/tumblr).
There are two optional dependencies that enable additional features:

1. To backup audio and video, install [youtube-dl](https://rg3.github.io/youtube-dl/).
If you need HTTP cookies to download, use an appropriate browser plugin to
extract the cookie(s) into a file and use option `--cookiefile=file`. See
[issue 132](https://github.com/bbolli/tumblr-utils/issues/132).
2. To enable EXIF tagging, install [pyexiv2](https://github.com/escaped/pyexiv2).

The fastest option to install these packages is via the package manager of
Expand Down Expand Up @@ -54,6 +57,7 @@ feasible, download, build and install from the links above.
--save-video save all video files
--save-video-tumblr save only Tumblr video files
--save-audio save audio files
--cookiefile=FILE cookie file for youtube-dl
-b, --blosxom save the posts in blosxom format
-r, --reverse-month reverse the post order in the monthly archives
-R, --reverse-index reverse the index file order
Expand Down
8 changes: 6 additions & 2 deletions tumblr_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def append_try(elt, fmt=u'%s'):
def get_youtube_url(self, youtube_url):
# determine the media file name
filetmpl = u'%(id)s_%(uploader_id)s_%(title)s.%(ext)s'
ydl = youtube_dl.YoutubeDL({
ydl_options = {
'outtmpl': join(self.media_folder, filetmpl),
'quiet': True,
'restrictfilenames': True,
Expand All @@ -794,7 +794,10 @@ def get_youtube_url(self, youtube_url):
'retries': 3000,
'fragment_retries': 3000,
'ignoreerrors': True
})
}
if options.cookiefile:
ydl_options['cookiefile'] = options.cookiefile
ydl = youtube_dl.YoutubeDL(ydl_options)
ydl.add_default_info_extractors()
try:
result = ydl.extract_info(youtube_url, download=False)
Expand Down Expand Up @@ -1129,6 +1132,7 @@ def request_callback(option, opt, value, parser):
parser.add_option('--save-video', action='store_true', help="save all video files")
parser.add_option('--save-video-tumblr', action='store_true', help="save only Tumblr video files")
parser.add_option('--save-audio', action='store_true', help="save audio files")
parser.add_option('--cookiefile', help="cookie file for youtube-dl")
parser.add_option('-j', '--json', action='store_true',
help="save the original JSON source"
)
Expand Down

0 comments on commit 4961a2f

Please sign in to comment.