Commit db63150c authored by Vincent A's avatar Vincent A Committed by Florent Fourcot

introduce which uses youtube-dl

The youtube-dl tool can be used to fetch video url and misc info.
parent e1a1dcd7
......@@ -183,7 +183,8 @@ class MediaPlayer(object):
p1 = Popen(rtmp.split(), stdout=PIPE)
Popen(player_name + args, stdin=p1.stdout, stderr=PIPE)
def _find_in_path(self, path, filename):
def _find_in_path(cls, path, filename):
for i in path.split(':'):
if os.path.exists('/'.join([i, filename])):
return True
# -*- coding: utf-8 -*-
# Copyright(C) 2017 Vincent A
# This file is part of weboob.
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <>.
import os
import subprocess
from weboob.capabilities.base import NotAvailable
from weboob.capabilities.image import Thumbnail
from import BaseVideo
from import parse_date
from import json
from import MediaPlayer
__all__ = ('video_info',)
def video_info(url):
"""Fetch info about a video using youtube-dl
:param url: URL of the web page containing the video
:rtype: :class:``
if not MediaPlayer._find_in_path(os.environ['PATH'], 'youtube-dl'):
raise Exception('Please install youtube-dl')
j = json.loads(subprocess.check_output(['youtube-dl', '-f', 'best', '-J', url]))
except subprocess.CalledProcessError:
v = BaseVideo(id=url)
v.title = j.get('title') or NotAvailable
v.ext = j.get('ext') or NotAvailable
v.description = j.get('description') or NotAvailable
v.url = j['url']
v.duration = j.get('duration') or NotAvailable = j.get('uploader') or NotAvailable
v.rating = j.get('average_rating') or NotAvailable
if j.get('thumbnail'):
v.thumbnail = Thumbnail(j['thumbnail'])
d = j.get('upload_date', j.get('release_date'))
if d: = parse_date(d)
return v
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment