Improve info extractor

This commit is contained in:
Nguyễn Gia Phong 2017-06-14 12:21:54 +07:00
parent 27d0c98469
commit b37b4440ac
3 changed files with 10 additions and 4 deletions

5
comp
View File

@ -25,7 +25,7 @@ from configparser import ConfigParser
from functools import reduce
from gettext import bindtextdomain, gettext as _, textdomain
from os import makedirs
from os.path import abspath, dirname, expanduser, isfile
from os.path import abspath, dirname, expanduser
from threading import Thread
from mpv import MPV
@ -338,6 +338,9 @@ parser.add_argument('-f', '--format', required=False, metavar='YTDL_FORMAT',
help=_("video format/quality to be passed to youtube-dl"))
args = parser.parse_args()
entries = extract_info(args.file, args.extractor)
if entries is None:
print(_("'{}': Can't extract playlist").format(args.file))
exit()
json_file = args.file if args.extractor == 'json' else ''
config = ConfigParser()
config.read(args.config)

View File

@ -19,6 +19,7 @@
import json
from os.path import abspath, expanduser, expandvars, isfile
from time import gmtime, sleep, strftime
from urllib.request import urlretrieve
from youtube_dl import YoutubeDL
from mpv import MPV
@ -34,6 +35,8 @@ def json_extract_info(filename):
error occur during the extraction, return None.
"""
try:
if not isfile(filename):
filename = urlretrieve(filename)[0]
with open(filename) as f: raw_info, info = json.load(f), []
for i in raw_info:
e = DEFAULT_ENTRY.copy()
@ -75,8 +78,8 @@ def ytdl_extract_info(filename):
for i in info:
if 'webpage_url' in i:
i['filename'] = i['webpage_url']
elif (i['ie_key'] == 'Youtube'
or i['extractor'] == 'youtube'):
elif (i.get('ie_key') == 'Youtube'
or i.get('extractor') == 'youtube'):
i['filename'] = 'https://youtu.be/' + i['id']
else:
i['filename'] = i['url']

View File

@ -10,7 +10,7 @@ with open('README.rst') as f:
setup(
name='comp',
version='0.3.3',
version='0.3.4',
description=('Curses Omni Media Player'),
long_description=long_description,
url='https://github.com/McSinyx/comp',