From 5adc36f2aed75566576fb644ef84ca206d0d0ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Wed, 27 Jan 2021 12:12:39 -0500 Subject: [PATCH 1/7] [ninjastream] Adding new extractor --- youtube_dl/extractor/extractors.py | 1 + youtube_dl/extractor/ninjastream.py | 69 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 youtube_dl/extractor/ninjastream.py diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index ab8d6a5a5..7b360c00c 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -777,6 +777,7 @@ from .niconico import NiconicoIE, NiconicoPlaylistIE from .ninecninemedia import NineCNineMediaIE from .ninegag import NineGagIE from .ninenow import NineNowIE +from .ninjastream import NinjaStreamIE from .nintendo import NintendoIE from .njpwworld import NJPWWorldIE from .nobelprize import NobelPrizeIE diff --git a/youtube_dl/extractor/ninjastream.py b/youtube_dl/extractor/ninjastream.py new file mode 100644 index 000000000..ef172f73a --- /dev/null +++ b/youtube_dl/extractor/ninjastream.py @@ -0,0 +1,69 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import os + +from .common import InfoExtractor +from ..utils import ExtractorError + + +class NinjaStreamIE(InfoExtractor): + """ + Handles downloading video from ninjastream.to + """ + _VALID_URL = r'https?://(?:\w+\.)?ninjastream\.to/watch/[0-9a-zA-Z]+' + _TESTS = [ + { + 'url': 'https://ninjastream.to/watch/74GA02Nw6ZYBk', + 'info_dict': { + 'id': '74GA02Nw6ZYBk', + 'ext': 'mp4', + 'title': 'Damon_Andros_and_Stephen_Harte' + }, + } + ] + + def _real_extract(self, url): + """ + Parses the URL into the video's URL. + """ + # Parse the video id + video_id = self._search_regex(r'https?://(?:\w+\.)?ninjastream\.to/watch/([0-9a-zA-Z]+)', + url, 'video_id', fatal=False) or '' + + # Get the hosted webpage + webpage = self._download_webpage(url, video_id) + + # The links to the m3u8 file will be buried and html encoded in the tag + jwplayer_link = self._html_search_regex(r' Date: Wed, 27 Jan 2021 14:14:16 -0500 Subject: [PATCH 2/7] [ninjastream] Addressing coding convention issues --- youtube_dl/extractor/ninjastream.py | 43 ++++++++++++++++++----------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/youtube_dl/extractor/ninjastream.py b/youtube_dl/extractor/ninjastream.py index ef172f73a..b5929b645 100644 --- a/youtube_dl/extractor/ninjastream.py +++ b/youtube_dl/extractor/ninjastream.py @@ -28,39 +28,50 @@ class NinjaStreamIE(InfoExtractor): Parses the URL into the video's URL. """ # Parse the video id - video_id = self._search_regex(r'https?://(?:\w+\.)?ninjastream\.to/watch/([0-9a-zA-Z]+)', - url, 'video_id', fatal=False) or '' + video_id = self._search_regex( + r'https?://(?:\w+\.)?ninjastream\.to/watch/([0-9a-zA-Z]+)', + url, 'video_id', fatal=False, default='') # Get the hosted webpage webpage = self._download_webpage(url, video_id) - # The links to the m3u8 file will be buried and html encoded in the tag - jwplayer_link = self._html_search_regex(r' tag + jwplayer_link = self._html_search_regex( + r' Date: Fri, 30 Apr 2021 17:36:47 +0200 Subject: [PATCH 3/7] [ninjastream] fix line endings --- youtube_dl/extractor/ninjastream.py | 160 ++++++++++++++-------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/youtube_dl/extractor/ninjastream.py b/youtube_dl/extractor/ninjastream.py index b5929b645..70995f3ed 100644 --- a/youtube_dl/extractor/ninjastream.py +++ b/youtube_dl/extractor/ninjastream.py @@ -1,80 +1,80 @@ -# coding: utf-8 -from __future__ import unicode_literals - -import os - -from .common import InfoExtractor -from ..utils import ExtractorError - - -class NinjaStreamIE(InfoExtractor): - """ - Handles downloading video from ninjastream.to - """ - _VALID_URL = r'https?://(?:\w+\.)?ninjastream\.to/watch/[0-9a-zA-Z]+' - _TESTS = [ - { - 'url': 'https://ninjastream.to/watch/74GA02Nw6ZYBk', - 'info_dict': { - 'id': '74GA02Nw6ZYBk', - 'ext': 'mp4', - 'title': 'Damon_Andros_and_Stephen_Harte' - }, - } - ] - - def _real_extract(self, url): - """ - Parses the URL into the video's URL. - """ - # Parse the video id - video_id = self._search_regex( - r'https?://(?:\w+\.)?ninjastream\.to/watch/([0-9a-zA-Z]+)', - url, 'video_id', fatal=False, default='') - - # Get the hosted webpage - webpage = self._download_webpage(url, video_id) - - # The links to the m3u8 file will be buried and html encoded in - # the tag - jwplayer_link = self._html_search_regex( - r' tag + jwplayer_link = self._html_search_regex( + r' Date: Fri, 30 Apr 2021 18:13:10 +0200 Subject: [PATCH 4/7] [ninjastream] replace test --- youtube_dl/extractor/ninjastream.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/ninjastream.py b/youtube_dl/extractor/ninjastream.py index 70995f3ed..92b918181 100644 --- a/youtube_dl/extractor/ninjastream.py +++ b/youtube_dl/extractor/ninjastream.py @@ -14,11 +14,11 @@ class NinjaStreamIE(InfoExtractor): _VALID_URL = r'https?://(?:\w+\.)?ninjastream\.to/watch/[0-9a-zA-Z]+' _TESTS = [ { - 'url': 'https://ninjastream.to/watch/74GA02Nw6ZYBk', + 'url': 'https://ninjastream.to/watch/GbJQP8rawQ7rw', 'info_dict': { - 'id': '74GA02Nw6ZYBk', + 'id': 'GbJQP8rawQ7rw', 'ext': 'mp4', - 'title': 'Damon_Andros_and_Stephen_Harte' + 'title': 'Big Buck Bunny 360 10s 5MB' }, } ] From 0ad70a76f0a16505683849690dda947323400444 Mon Sep 17 00:00:00 2001 From: schnusch Date: Fri, 30 Apr 2021 17:40:27 +0200 Subject: [PATCH 5/7] [ninjastream] fix video ID --- youtube_dl/extractor/ninjastream.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/youtube_dl/extractor/ninjastream.py b/youtube_dl/extractor/ninjastream.py index 92b918181..d91e0c853 100644 --- a/youtube_dl/extractor/ninjastream.py +++ b/youtube_dl/extractor/ninjastream.py @@ -11,7 +11,7 @@ class NinjaStreamIE(InfoExtractor): """ Handles downloading video from ninjastream.to """ - _VALID_URL = r'https?://(?:\w+\.)?ninjastream\.to/watch/[0-9a-zA-Z]+' + _VALID_URL = r'https?://(?:www\.)?ninjastream\.to/(?:download|watch)/(?P[^/?#]+)' _TESTS = [ { 'url': 'https://ninjastream.to/watch/GbJQP8rawQ7rw', @@ -24,13 +24,7 @@ class NinjaStreamIE(InfoExtractor): ] def _real_extract(self, url): - """ - Parses the URL into the video's URL. - """ - # Parse the video id - video_id = self._search_regex( - r'https?://(?:\w+\.)?ninjastream\.to/watch/([0-9a-zA-Z]+)', - url, 'video_id', fatal=False, default='') + video_id = self._match_id(url) # Get the hosted webpage webpage = self._download_webpage(url, video_id) From 01924f678a3ee18dce53ddb5178600afd89fb44a Mon Sep 17 00:00:00 2001 From: schnusch Date: Fri, 30 Apr 2021 18:00:29 +0200 Subject: [PATCH 6/7] [ninjastream] request API to obtain playlist URL --- youtube_dl/extractor/ninjastream.py | 54 +++++++++++------------------ 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/youtube_dl/extractor/ninjastream.py b/youtube_dl/extractor/ninjastream.py index d91e0c853..df7ad30de 100644 --- a/youtube_dl/extractor/ninjastream.py +++ b/youtube_dl/extractor/ninjastream.py @@ -1,10 +1,10 @@ # coding: utf-8 from __future__ import unicode_literals -import os +import json +import posixpath from .common import InfoExtractor -from ..utils import ExtractorError class NinjaStreamIE(InfoExtractor): @@ -29,43 +29,31 @@ class NinjaStreamIE(InfoExtractor): # Get the hosted webpage webpage = self._download_webpage(url, video_id) - # The links to the m3u8 file will be buried and html encoded in - # the tag - jwplayer_link = self._html_search_regex( - r' Date: Fri, 30 Apr 2021 18:07:44 +0200 Subject: [PATCH 7/7] [ninjastream] add thumbnail --- youtube_dl/extractor/ninjastream.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/ninjastream.py b/youtube_dl/extractor/ninjastream.py index df7ad30de..9a8b4378a 100644 --- a/youtube_dl/extractor/ninjastream.py +++ b/youtube_dl/extractor/ninjastream.py @@ -5,6 +5,7 @@ import json import posixpath from .common import InfoExtractor +from ..utils import urljoin class NinjaStreamIE(InfoExtractor): @@ -40,6 +41,10 @@ class NinjaStreamIE(InfoExtractor): except KeyError: filename = 'ninjastream.to' + thumbnail = file_meta.get('poster_id') + if thumbnail: + thumbnail = urljoin('https://cdn.ninjastream.to/', thumbnail) + data = {'id': video_id} headers = { 'X-Requested-With': 'XMLHttpRequest', @@ -51,12 +56,14 @@ class NinjaStreamIE(InfoExtractor): video_id, data=data, headers=headers) # Get and parse the m3u8 information + stream_url = stream_meta['result']['playlist'] formats = self._extract_m3u8_formats( - url, video_id, 'mp4', entry_protocol='m3u8_native', + stream_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls') return { 'formats': formats, 'id': video_id, + 'thumbnail': thumbnail, 'title': filename, }