1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 21:54:17 +01:00

Move the new metadata based thumbnail download into a reusable class instead of directly in Svtplay (requires that the service extract thumbnail urls during parsing of the video info into the self.output variable and the keys 'showthumbnailurl' and 'episodethumbnailurl'). Change OpenGraphThumbMixin to use the new download_thumbnails which makes correct filenames. Removed the old download_thumbnail.

This commit is contained in:
Harald Gustafsson 2018-07-30 12:52:05 +02:00 committed by Johan Andersson
parent fc71a8d8e4
commit 4388e57112
3 changed files with 18 additions and 26 deletions

View File

@ -7,7 +7,7 @@ import os
from urllib.parse import urlparse
from svtplay_dl.utils.parser import readconfig, setup_defaults, merge
from svtplay_dl.utils.http import download_thumbnail, HTTP
from svtplay_dl.utils.http import download_thumbnails, HTTP
class Service(object):
@ -106,7 +106,21 @@ class OpenGraphThumbMixin(object):
url = opengraph_get(self.get_urldata(), "image")
if url is None:
return
download_thumbnail(options, url)
download_thumbnails(options, [(False, url)])
class MetadataThumbMixin(object):
"""
Mix this into the service class to grab thumbnail from extracted metadata.
"""
def get_thumbnail(self, options):
urls = []
if self.output["showthumbnailurl"] is not None:
urls.append((True, self.output["showthumbnailurl"]))
if self.output["episodethumbnailurl"] is not None:
urls.append((False, self.output["episodethumbnailurl"]))
if urls:
download_thumbnails(self.output, options, urls)
class Generic(Service):

View File

@ -9,19 +9,18 @@ from urllib.parse import urljoin, urlparse, parse_qs
from operator import itemgetter
from svtplay_dl.log import log
from svtplay_dl.service import Service
from svtplay_dl.service import Service, MetadataThumbMixin
from svtplay_dl.utils.text import filenamify
from svtplay_dl.fetcher.hds import hdsparse
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.fetcher.dash import dashparse
from svtplay_dl.subtitle import subtitle
from svtplay_dl.error import ServiceError
from svtplay_dl.utils.http import download_thumbnails
URL_VIDEO_API = "http://api.svt.se/videoplayer-api/video/"
class Svtplay(Service):
class Svtplay(Service, MetadataThumbMixin):
supported_domains = ['svtplay.se', 'svt.se', 'beta.svtplay.se', 'svtflow.se']
def get(self):
@ -299,12 +298,3 @@ class Svtplay(Service):
self.output["episodedescription"] = data["video"]["description"]
except KeyError:
pass
def get_thumbnail(self, options):
urls = []
if self.output["showthumbnailurl"] is not None:
urls.append((True, self.output["showthumbnailurl"]))
if self.output["episodethumbnailurl"] is not None:
urls.append((False, self.output["episodethumbnailurl"]))
if urls:
download_thumbnails(self.output, options, urls)

View File

@ -49,18 +49,6 @@ class HTTP(Session):
return dict(x.split('=') for x in headers.split(';'))
def download_thumbnail(options, url):
data = Session.get(url).content
filename = re.search(r"(.*)\.[a-z0-9]{2,3}$", options.output)
tbn = "%s.tbn" % filename.group(1)
logging.info("Thumbnail: %s", tbn)
fd = open(tbn, "wb")
fd.write(data)
fd.close()
def download_thumbnails(output, config, urls):
for show, url in urls:
data = Session().get(url).content