1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

Working thumbnail download. Used by svtplay and barnkanalen, downloads both episode and show thumbnails.

This commit is contained in:
Harald Gustafsson 2018-07-22 11:12:22 +02:00 committed by Johan Andersson
parent dbdf7dc851
commit bf0e38a6f9
2 changed files with 36 additions and 3 deletions

View File

@ -16,11 +16,12 @@ 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, OpenGraphThumbMixin):
class Svtplay(Service):
supported_domains = ['svtplay.se', 'svt.se', 'beta.svtplay.se', 'svtflow.se']
def get(self):
@ -297,4 +298,13 @@ class Svtplay(Service, OpenGraphThumbMixin):
try:
self.output["episodedescription"] = data["video"]["description"]
except:
pass
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

@ -5,7 +5,8 @@ from urllib.parse import urljoin
from requests import Session
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from svtplay_dl.utils.output import formatname
from svtplay_dl.utils.parser import Options
# Used for UA spoofing in get_http_data()
FIREFOX_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.3'
@ -60,6 +61,28 @@ def download_thumbnail(options, url):
fd.close()
def download_thumbnails(output, config, urls):
for show, url in urls:
data = Session().get(url).content
if show:
# Config for downloading show thumbnail
cconfig = Options()
cconfig.set("output", config.get("output"))
cconfig.set("path", config.get("path"))
cconfig.set("subfolder", config.get("subfolder"))
cconfig.set("filename", "{title}.tvshow.{ext}")
else:
cconfig = config
filename = formatname(output.copy(), cconfig, extension="tbn")
logging.info("Thumbnail: %s", filename)
fd = open(filename, "wb")
fd.write(data)
fd.close()
def get_full_url(url, srcurl):
if url[:4] == 'http':
return url