Skip to content

Commit

Permalink
[aparat] Fix extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
remitamine authored and ThirumalaiK committed Jan 28, 2021
1 parent 8e7ae4f commit 1121f85
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions youtube_dl/extractor/aparat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .common import InfoExtractor
from ..utils import (
get_element_by_id,
int_or_none,
merge_dicts,
mimetype2ext,
Expand Down Expand Up @@ -39,23 +40,15 @@ def _real_extract(self, url):
webpage = self._download_webpage(url, video_id, fatal=False)

if not webpage:
# Note: There is an easier-to-parse configuration at
# http://www.aparat.com/video/video/config/videohash/%video_id
# but the URL in there does not work
webpage = self._download_webpage(
'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id,
video_id)

options = self._parse_json(
self._search_regex(
r'options\s*=\s*JSON\.parse\(\s*(["\'])(?P<value>(?:(?!\1).)+)\1\s*\)',
webpage, 'options', group='value'),
video_id)

player = options['plugins']['sabaPlayerPlugin']
options = self._parse_json(self._search_regex(
r'options\s*=\s*({.+?})\s*;', webpage, 'options'), video_id)

formats = []
for sources in player['multiSRC']:
for sources in (options.get('multiSRC') or []):
for item in sources:
if not isinstance(item, dict):
continue
Expand Down Expand Up @@ -85,11 +78,12 @@ def _real_extract(self, url):
info = self._search_json_ld(webpage, video_id, default={})

if not info.get('title'):
info['title'] = player['title']
info['title'] = get_element_by_id('videoTitle', webpage) or \
self._html_search_meta(['og:title', 'twitter:title', 'DC.Title', 'title'], webpage, fatal=True)

return merge_dicts(info, {
'id': video_id,
'thumbnail': url_or_none(options.get('poster')),
'duration': int_or_none(player.get('duration')),
'duration': int_or_none(options.get('duration')),
'formats': formats,
})

0 comments on commit 1121f85

Please sign in to comment.