Improve info extractor
This commit is contained in:
parent
27d0c98469
commit
b37b4440ac
5
comp
5
comp
|
@ -25,7 +25,7 @@ from configparser import ConfigParser
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from gettext import bindtextdomain, gettext as _, textdomain
|
from gettext import bindtextdomain, gettext as _, textdomain
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
from os.path import abspath, dirname, expanduser, isfile
|
from os.path import abspath, dirname, expanduser
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from mpv import MPV
|
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"))
|
help=_("video format/quality to be passed to youtube-dl"))
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
entries = extract_info(args.file, args.extractor)
|
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 ''
|
json_file = args.file if args.extractor == 'json' else ''
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read(args.config)
|
config.read(args.config)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
import json
|
import json
|
||||||
from os.path import abspath, expanduser, expandvars, isfile
|
from os.path import abspath, expanduser, expandvars, isfile
|
||||||
from time import gmtime, sleep, strftime
|
from time import gmtime, sleep, strftime
|
||||||
|
from urllib.request import urlretrieve
|
||||||
|
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
from mpv import MPV
|
from mpv import MPV
|
||||||
|
@ -34,6 +35,8 @@ def json_extract_info(filename):
|
||||||
error occur during the extraction, return None.
|
error occur during the extraction, return None.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
if not isfile(filename):
|
||||||
|
filename = urlretrieve(filename)[0]
|
||||||
with open(filename) as f: raw_info, info = json.load(f), []
|
with open(filename) as f: raw_info, info = json.load(f), []
|
||||||
for i in raw_info:
|
for i in raw_info:
|
||||||
e = DEFAULT_ENTRY.copy()
|
e = DEFAULT_ENTRY.copy()
|
||||||
|
@ -75,8 +78,8 @@ def ytdl_extract_info(filename):
|
||||||
for i in info:
|
for i in info:
|
||||||
if 'webpage_url' in i:
|
if 'webpage_url' in i:
|
||||||
i['filename'] = i['webpage_url']
|
i['filename'] = i['webpage_url']
|
||||||
elif (i['ie_key'] == 'Youtube'
|
elif (i.get('ie_key') == 'Youtube'
|
||||||
or i['extractor'] == 'youtube'):
|
or i.get('extractor') == 'youtube'):
|
||||||
i['filename'] = 'https://youtu.be/' + i['id']
|
i['filename'] = 'https://youtu.be/' + i['id']
|
||||||
else:
|
else:
|
||||||
i['filename'] = i['url']
|
i['filename'] = i['url']
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -10,7 +10,7 @@ with open('README.rst') as f:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='comp',
|
name='comp',
|
||||||
version='0.3.3',
|
version='0.3.4',
|
||||||
description=('Curses Omni Media Player'),
|
description=('Curses Omni Media Player'),
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
url='https://github.com/McSinyx/comp',
|
url='https://github.com/McSinyx/comp',
|
||||||
|
|
Loading…
Reference in a new issue