From a7a16c95f350fb8682b31976aeaf49c394a14acf Mon Sep 17 00:00:00 2001 From: Gouranga Das <38029649+GourangaDas@users.noreply.github.com> Date: Thu, 13 Dec 2018 21:05:14 +0530 Subject: [PATCH 1/2] Support to Gaana.com added --- youtube_dl/extractor/gaana.py | 124 ++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 youtube_dl/extractor/gaana.py diff --git a/youtube_dl/extractor/gaana.py b/youtube_dl/extractor/gaana.py new file mode 100644 index 000000000..fd09a8e6d --- /dev/null +++ b/youtube_dl/extractor/gaana.py @@ -0,0 +1,124 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import re +from ..aes import aes_cbc_decrypt +from ..compat import ( + compat_b64decode, +) + +from .common import InfoExtractor +from ..utils import ( + bytes_to_intlist, + intlist_to_bytes, + int_or_none, +) + + +class GaanaBaseIE(InfoExtractor): + bs = 32 + + def _Decrypt(self, data): + + key = 'Z0AxbiEoZjEjci4wJCkmJQ==' + iv = 'YXNkIUAjIUAjQCExMjMxMg==' + + stream_url = intlist_to_bytes(aes_cbc_decrypt( + bytes_to_intlist(compat_b64decode(data)), + bytes_to_intlist(compat_b64decode(key)), + bytes_to_intlist(compat_b64decode(iv)))).decode() + + s = stream_url[:-ord(stream_url[len(stream_url) - 1:])] + return s + + def _create_entry(self, data, video_id): + + raw_data = self._parse_json(data, video_id) + + video_data = raw_data.get('path') + title = raw_data.get('title') + thumbnail = raw_data.get('atw', '') or raw_data.get('albumartwork', '') + duration = raw_data.get('duration') + + formats = [] + for value in video_data.keys(): + # need to skip auto + if not value == 'auto': + content = video_data.get(value) + for k in content: + format_url = self._Decrypt(k.get('message')) + format_id = value + + formats.append({ + 'url': format_url, + 'format_id': format_id, + 'ext': 'mp4' + }) + + return { + 'id': video_id, + 'title': title, + 'description': raw_data.get('description'), + 'duration': int_or_none(duration), + 'formats': formats, + 'album': raw_data.get('albumtitle'), + 'thumbnail': thumbnail, + 'artist': raw_data.get('artist'), + 'release_date': raw_data.get('release_date'), + 'language': raw_data.get('language') + } + + +class GaanaIE(GaanaBaseIE): + IE_NAME = 'gaana' + _VALID_URL = r'https?://(?:www\.)?gaana\.com/song/(?P[^/#?]+)' + _TESTS = [{ + # contentData + 'url': 'https://gaana.com/song/jeeye-to-jeeye-kaise', + 'info_dict': { + 'id': 'jeeye-to-jeeye-kaise', + 'ext': 'mp4', + 'title': 'Jeeye To Jeeye Kaise', + 'duration': 325, + }, + 'params': { + # m3u8 download + 'skip_download': True, + } + }] + _GEO_BYPASS = False + + def _real_extract(self, url): + video_id = self._match_id(url) + + webpage = self._download_webpage(url, video_id) + raw_data = self._search_regex( + r'class="parentnode sourcelist_\d+"> (.*?) ', + webpage, 'raw data') + + return self._create_entry(raw_data, video_id) + + +class GaanaAlbumIE(GaanaBaseIE): + IE_NAME = 'gaana:album' + _VALID_URL = r'https?://(?:www\.)?gaana\.com/album/(?P[^/#?]+)' + _TESTS = [{ + 'url': 'https://gaana.com/album/saajan-hindi', + 'info_dict': { + 'id': 'saajan-hindi', + }, + 'playlist_mincount': 20, + }, { + 'url': 'https://gaana.com/artist/kumar-sanu', + 'only_matching': True, + }] + + def _real_extract(self, url): + playlist_id = self._match_id(url) + webpage = self._download_webpage(url, playlist_id) + matchobj = re.findall(r'class="parentnode sourcelist_\d+"> (.*?) ', webpage) + entries = [] + for g in matchobj: + entries.append(self._create_entry(g, playlist_id)) + + return self.playlist_result(entries, playlist_id) From a1283cc60ab541e55617410ff99f72ff717522d2 Mon Sep 17 00:00:00 2001 From: Gouranga Das <38029649+GourangaDas@users.noreply.github.com> Date: Thu, 13 Dec 2018 21:38:33 +0530 Subject: [PATCH 2/2] Update extractors.py --- youtube_dl/extractor/extractors.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 6a5d12ab1..c0e66bc59 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -418,6 +418,10 @@ from .gameone import ( ) from .gamespot import GameSpotIE from .gamestar import GameStarIE +from .gaana import ( + GaanaIE, + GaanaAlbumIE, +) from .gaskrank import GaskrankIE from .gazeta import GazetaIE from .gdcvault import GDCVaultIE