2014-08-11 20:41:09 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import re
|
2014-08-11 21:25:10 +02:00
|
|
|
import os
|
2014-08-11 20:41:09 +02:00
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2015-07-05 21:51:58 +02:00
|
|
|
from svtplay_dl.utils import get_http_data, is_py2_old, check_redirect, urlparse
|
2014-08-11 20:41:09 +02:00
|
|
|
from svtplay_dl.log import log
|
|
|
|
from svtplay_dl.fetcher.rtmp import RTMP
|
|
|
|
|
|
|
|
# This is _very_ similar to mtvservices..
|
|
|
|
class Mtvnn(Service, OpenGraphThumbMixin):
|
|
|
|
supported_domains = ['nickelodeon.se', "nickelodeon.nl", "nickelodeon.no"]
|
|
|
|
|
|
|
|
def get(self, options):
|
2014-12-08 23:07:02 +01:00
|
|
|
error, data = self.get_urldata()
|
|
|
|
if error:
|
2014-11-26 15:59:16 +01:00
|
|
|
log.error("Can't get the page")
|
|
|
|
return
|
2015-07-05 21:51:58 +02:00
|
|
|
match = re.search(r'"(http://api.mtvnn.com/v2/mrss.xml[^"]+)"', data)
|
2014-08-11 20:41:09 +02:00
|
|
|
if not match:
|
|
|
|
log.error("Can't find id for the video")
|
2014-10-06 23:21:43 +02:00
|
|
|
return
|
2015-07-05 21:51:58 +02:00
|
|
|
|
2014-12-08 23:07:02 +01:00
|
|
|
error, data = get_http_data(match.group(1))
|
|
|
|
if error:
|
|
|
|
log.error("Cant get video info")
|
|
|
|
return
|
2014-08-11 20:41:09 +02:00
|
|
|
xml = ET.XML(data)
|
|
|
|
mediagen = xml.find("channel").find("item").find("{http://search.yahoo.com/mrss/}group")
|
2014-08-11 21:25:10 +02:00
|
|
|
title = xml.find("channel").find("item").find("title").text
|
|
|
|
if options.output_auto:
|
|
|
|
directory = os.path.dirname(options.output)
|
|
|
|
if len(directory):
|
2015-08-24 23:02:18 +02:00
|
|
|
options.output = os.path.join(directory, title)
|
2014-08-11 21:25:10 +02:00
|
|
|
else:
|
|
|
|
options.output = title
|
2014-12-22 17:41:40 +01:00
|
|
|
|
|
|
|
if self.exclude(options):
|
|
|
|
return
|
|
|
|
|
2015-07-05 21:51:58 +02:00
|
|
|
swfurl = mediagen.find("{http://search.yahoo.com/mrss/}player").attrib["url"]
|
|
|
|
parse = urlparse(swfurl)
|
|
|
|
options.other = "-W %s://%s%s" % (parse.scheme, parse.hostname, check_redirect(swfurl))
|
|
|
|
|
2014-08-11 20:41:09 +02:00
|
|
|
contenturl = mediagen.find("{http://search.yahoo.com/mrss/}content").attrib["url"]
|
2014-12-08 23:07:02 +01:00
|
|
|
error, content = get_http_data(contenturl)
|
|
|
|
if error:
|
|
|
|
log.error("Cant download stream info")
|
|
|
|
return
|
2014-08-11 20:41:09 +02:00
|
|
|
xml = ET.XML(content)
|
|
|
|
ss = xml.find("video").find("item")
|
|
|
|
if is_py2_old:
|
|
|
|
sa = list(ss.getiterator("rendition"))
|
|
|
|
else:
|
|
|
|
sa = list(ss.iter("rendition"))
|
|
|
|
|
|
|
|
for i in sa:
|
2014-08-11 22:45:59 +02:00
|
|
|
yield RTMP(options, i.find("src").text, i.attrib["bitrate"])
|
|
|
|
|
|
|
|
def find_all_episodes(self, options):
|
2014-12-08 23:07:02 +01:00
|
|
|
match = re.search(r"data-franchise='([^']+)'", self.get_urldata()[1])
|
2014-08-11 22:45:59 +02:00
|
|
|
if match is None:
|
|
|
|
log.error("Couldn't program id")
|
2014-10-06 23:21:43 +02:00
|
|
|
return
|
2014-08-11 22:45:59 +02:00
|
|
|
programid = match.group(1)
|
2014-12-08 23:07:02 +01:00
|
|
|
match = re.findall(r"<li class='(divider playlist-item|playlist-item)'( data-item-id='([^']+)')?", self.get_urldata()[1])
|
2014-08-11 22:45:59 +02:00
|
|
|
if not match:
|
|
|
|
log.error("Couldn't retrieve episode list")
|
2014-10-06 23:21:43 +02:00
|
|
|
return
|
2014-09-27 22:53:41 +02:00
|
|
|
episodNr = []
|
|
|
|
for i in match:
|
|
|
|
if i[0] == "playlist-item":
|
|
|
|
episodNr.append(i[2])
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2014-08-11 22:45:59 +02:00
|
|
|
episodes = []
|
2014-12-21 13:16:05 +01:00
|
|
|
n = 0
|
2014-09-27 22:53:41 +02:00
|
|
|
for i in sorted(episodNr):
|
2014-12-21 13:16:05 +01:00
|
|
|
if n == options.all_last:
|
|
|
|
break
|
2014-08-11 22:45:59 +02:00
|
|
|
episodes.append("http://www.nickelodeon.se/serier/%s-something/videos/%s-something" % (programid, i))
|
2014-12-21 13:16:05 +01:00
|
|
|
n += 1
|
2014-08-11 22:45:59 +02:00
|
|
|
return episodes
|