2019-11-01 21:05:38 +01:00
|
|
|
#!/bin/env python
|
|
|
|
"""
|
|
|
|
============================================================
|
|
|
|
yt-download - Little script
|
|
|
|
Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
2019-10-27 10:27:06 +01:00
|
|
|
|
2019-11-01 21:05:38 +01:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
============================================================
|
|
|
|
|
|
|
|
|
|
|
|
All settings are directly written in code, nothing else is provided.
|
|
|
|
The video destination can be altered by changing 'outtmpl' field of
|
|
|
|
ydl_opts variable. By default the video is stored in $PWD
|
|
|
|
|
|
|
|
Use at your own risk.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import youtube_dl
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
final_path = ""
|
|
|
|
|
|
|
|
|
|
|
|
class MyLogger(object):
|
|
|
|
def debug(self, msg):
|
|
|
|
global final_path
|
|
|
|
re1 = '.*?' # Non-greedy match on filler
|
|
|
|
re2 = '(ffmpeg)' # Word 1
|
|
|
|
re3 = '.*?' # Non-greedy match on filler
|
|
|
|
re4 = '(".*?")' # Double Quote String 1
|
|
|
|
|
|
|
|
rg = re.compile(re1 + re2 + re3 + re4, re.IGNORECASE | re.DOTALL)
|
|
|
|
m = rg.search(msg)
|
|
|
|
if m:
|
|
|
|
final_path = re.findall(r'"(.*?)"', m.group(2))[0]
|
|
|
|
else:
|
|
|
|
re1 = '(?<=\[download\] ).*?(?= has already been downloaded and merged)'
|
|
|
|
rg = re.compile(re1, re.IGNORECASE | re.DOTALL)
|
|
|
|
m = rg.search(msg)
|
|
|
|
if m:
|
|
|
|
final_path = m.group(0)
|
|
|
|
|
|
|
|
def warning(self, msg):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def error(self, msg):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
url = sys.argv[1]
|
|
|
|
title = sys.argv[2]
|
|
|
|
|
|
|
|
ydl_opts = {
|
|
|
|
'format': 'bestvideo[ext=mp4][height<1200][fps<=30]+bestaudio[ext=m4a]/bestvideo[ext=webm][height<1200][fps<=30]+bestaudio[ext=webm]/bestvideo[height<1200][fps<=30]+bestaudio/best[height<1200][fps<=30]/best',
|
|
|
|
#'outtmpl': '/<some_path>/%(title)s-%(id)s.%(ext)s',
|
|
|
|
'outtmpl': '%(title)s-%(id)s.%(ext)s',
|
|
|
|
'logger': MyLogger(),
|
|
|
|
'noprogress': True,
|
|
|
|
}
|
|
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
|
|
info_dict = ydl.extract_info(url, download=True)
|
|
|
|
|
|
|
|
if not final_path:
|
|
|
|
final_path = ydl.prepare_filename(info_dict)
|
|
|
|
|
|
|
|
subprocess.run(["mplayer", "-title", title, final_path])
|