mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-16 06:15:46 +00:00
[namava] Add new extractor
This commit is contained in:
parent
955894e72f
commit
49a68705dc
2 changed files with 98 additions and 0 deletions
|
@ -712,6 +712,7 @@ from .myvi import (
|
|||
MyviEmbedIE,
|
||||
)
|
||||
from .myvidster import MyVidsterIE
|
||||
from .namava import NamavaIE
|
||||
from .nationalgeographic import (
|
||||
NationalGeographicVideoIE,
|
||||
NationalGeographicTVIE,
|
||||
|
|
97
youtube_dl/extractor/namava.py
Normal file
97
youtube_dl/extractor/namava.py
Normal file
|
@ -0,0 +1,97 @@
|
|||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
urlencode_postdata,
|
||||
url_or_none,
|
||||
str_or_none,
|
||||
)
|
||||
|
||||
|
||||
class NamavaIE(InfoExtractor):
|
||||
IE_NAME = 'namava'
|
||||
_NETRC_MACHINE = IE_NAME
|
||||
_VALID_URL = r'https?://(?:www\.)?play\.namava\.ir/.*\bm=(?P<id>[0-9]+)'
|
||||
_TEST = {
|
||||
'url': 'https://play.namava.ir/?m=52396&p=desktop',
|
||||
'md5': '15639792543cc8e830a3451db1f44c72',
|
||||
'info_dict': {
|
||||
'id': '52396',
|
||||
'ext': 'mp4',
|
||||
'title': 'پلنگ صورتی - فصل ۴ قسمت ۱',
|
||||
'description': 'ماجراهای سرگرمکننده و طنز پلنگ صورتی و اتفاقات غیرمنتظرهای که همیشه برای او رخ میدهد و او با زیرکی خاص خودش، راهحلی را پیدا میکند و...'
|
||||
},
|
||||
}
|
||||
|
||||
_LOGIN_URL = 'https://www.namava.ir/api/v1.0/accounts/by-phone/login'
|
||||
HOST = 'www.namava.ir'
|
||||
|
||||
def _real_initialize(self):
|
||||
self._login()
|
||||
|
||||
def _login(self):
|
||||
username, password = self._get_login_info()
|
||||
|
||||
if not username:
|
||||
raise ExtractorError(
|
||||
'Unable to login: you have to pass username and password to logging in.',
|
||||
expected=True)
|
||||
|
||||
login_data = {
|
||||
'UserName': username,
|
||||
'Password': password,
|
||||
}
|
||||
response = self._download_json(
|
||||
self._LOGIN_URL, None,
|
||||
'Logging in', data=urlencode_postdata(login_data))
|
||||
|
||||
if response.get('succeeded') is True:
|
||||
self._set_cookie(self.HOST, 'auth_v2', response.get('result'))
|
||||
return True
|
||||
|
||||
error = response.get('error', {})
|
||||
error_message = error.get('message', '')
|
||||
raise ExtractorError(
|
||||
'Unable to login: %s said: %s' % (self.IE_NAME, error_message),
|
||||
expected=True)
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
|
||||
info = self._download_json(
|
||||
'https://www.namava.ir/api2/movie/' + video_id,
|
||||
video_id, 'Fetching video info', headers={
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
})
|
||||
|
||||
title = info.get('Name')
|
||||
if title is None:
|
||||
raise ExtractorError(
|
||||
'Unable to fetch video info',
|
||||
expected=True)
|
||||
|
||||
media_info = info.get('MediaInfoModel', {})
|
||||
domain = media_info.get('Domain') or ''
|
||||
m3u8_file = media_info.get('File') or ''
|
||||
m3u8_url = url_or_none(domain + m3u8_file)
|
||||
|
||||
formats = self._extract_m3u8_formats(
|
||||
m3u8_url, video_id, ext='mp4', fatal=False)
|
||||
self._sort_formats(formats)
|
||||
|
||||
url = formats[-1]['url']
|
||||
if len(formats) > 1:
|
||||
url = formats[-2]['url']
|
||||
|
||||
result = {
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'ext': 'mp4',
|
||||
'description': str_or_none(info.get('ShortDescription')),
|
||||
'formats': formats,
|
||||
'thumbnail': url_or_none(info.get('ImageAbsoluteUrl')),
|
||||
'url': url
|
||||
}
|
||||
return result
|
Loading…
Reference in a new issue