Files
bin
images
plugins
archiver
disk_usage
favorites
file_properties
movie_tv_info
searcher
template
trasher
vod_thumbnailer
youtube_download
yt_dlp
downloader
extractor
anvato_token_generator
__init__.py
abc.py
abcnews.py
abcotvs.py
academicearth.py
acast.py
adn.py
adobeconnect.py
adobepass.py
adobetv.py
adultswim.py
aenetworks.py
afreecatv.py
airmozilla.py
aliexpress.py
aljazeera.py
allocine.py
alphaporno.py
alura.py
amara.py
amazon.py
amcnetworks.py
americastestkitchen.py
amp.py
animelab.py
animeondemand.py
anvato.py
aol.py
apa.py
aparat.py
appleconnect.py
applepodcasts.py
appletrailers.py
archiveorg.py
arcpublishing.py
ard.py
arkena.py
arnes.py
arte.py
asiancrush.py
atresplayer.py
atttechchannel.py
atvat.py
audimedia.py
audioboom.py
audiomack.py
audius.py
awaan.py
aws.py
azmedien.py
baidu.py
bandaichannel.py
bandcamp.py
bannedvideo.py
bbc.py
beatport.py
beeg.py
behindkink.py
bellmedia.py
bet.py
bfi.py
bfmtv.py
bibeltv.py
bigflix.py
bild.py
bilibili.py
biobiochiletv.py
biqle.py
bitchute.py
bitwave.py
blackboardcollaborate.py
bleacherreport.py
blinkx.py
blogger.py
bloomberg.py
bokecc.py
bongacams.py
bostonglobe.py
box.py
bpb.py
br.py
bravotv.py
breakcom.py
breitbart.py
brightcove.py
businessinsider.py
buzzfeed.py
byutv.py
c56.py
cableav.py
callin.py
cam4.py
camdemy.py
cammodels.py
camwithher.py
canalalpha.py
canalc2.py
canalplus.py
canvas.py
carambatv.py
cartoonnetwork.py
cbc.py
cbs.py
cbsinteractive.py
cbslocal.py
cbsnews.py
cbssports.py
ccc.py
ccma.py
cctv.py
cda.py
ceskatelevize.py
cgtn.py
channel9.py
charlierose.py
chaturbate.py
chilloutzone.py
chingari.py
chirbit.py
cinchcast.py
cinemax.py
ciscolive.py
ciscowebex.py
cjsw.py
cliphunter.py
clippit.py
cliprs.py
clipsyndicate.py
closertotruth.py
cloudflarestream.py
cloudy.py
clubic.py
clyp.py
cmt.py
cnbc.py
cnn.py
comedycentral.py
common.py
commonmistakes.py
commonprotocols.py
condenast.py
contv.py
corus.py
coub.py
cozytv.py
cracked.py
crackle.py
crooksandliars.py
crowdbunker.py
crunchyroll.py
cspan.py
ctsnews.py
ctv.py
ctvnews.py
cultureunplugged.py
curiositystream.py
cwtv.py
daftsex.py
dailymail.py
dailymotion.py
damtomo.py
daum.py
dbtv.py
dctp.py
deezer.py
defense.py
democracynow.py
dfb.py
dhm.py
digg.py
digitalconcerthall.py
digiteka.py
discovery.py
discoverygo.py
discoveryvr.py
disney.py
dispeak.py
dlive.py
doodstream.py
dotsub.py
douyutv.py
dplay.py
drbonanza.py
dreisat.py
drooble.py
dropbox.py
dropout.py
drtuber.py
drtv.py
dtube.py
duboku.py
dumpert.py
dvtv.py
dw.py
eagleplatform.py
ebaumsworld.py
echomsk.py
egghead.py
ehow.py
eighttracks.py
einthusan.py
eitb.py
ellentube.py
elonet.py
elpais.py
embedly.py
engadget.py
epicon.py
eporner.py
eroprofile.py
ertgr.py
escapist.py
espn.py
esri.py
europa.py
europeantour.py
euscreen.py
everyonesmixtape.py
expotv.py
expressen.py
extractors.py
extremetube.py
eyedotv.py
facebook.py
fancode.py
faz.py
fc2.py
fczenit.py
filmmodu.py
filmon.py
filmweb.py
firsttv.py
fivemin.py
fivetv.py
flickr.py
folketinget.py
footyroom.py
formula1.py
fourtube.py
fox.py
fox9.py
foxgay.py
foxnews.py
foxsports.py
franceculture.py
franceinter.py
francetv.py
freesound.py
freespeech.py
freshlive.py
frontendmasters.py
fujitv.py
funimation.py
funk.py
fusion.py
fxnetworks.py
gab.py
gaia.py
gameinformer.py
gamejolt.py
gamespot.py
gamestar.py
gaskrank.py
gazeta.py
gdcvault.py
gedidigital.py
generic.py
gettr.py
gfycat.py
giantbomb.py
giga.py
gigya.py
glide.py
globo.py
glomex.py
go.py
godtube.py
gofile.py
golem.py
googledrive.py
googlepodcasts.py
googlesearch.py
gopro.py
goshgay.py
gotostage.py
gputechconf.py
gronkh.py
groupon.py
hbo.py
hearthisat.py
heise.py
hellporno.py
helsinki.py
hentaistigma.py
hgtv.py
hidive.py
historicfilms.py
hitbox.py
hitrecord.py
hketv.py
hornbunny.py
hotnewhiphop.py
hotstar.py
howcast.py
howstuffworks.py
hrfensehen.py
hrti.py
hse.py
huajiao.py
huffpost.py
hungama.py
hypem.py
ichinanalive.py
ign.py
iheart.py
imdb.py
imggaming.py
imgur.py
ina.py
inc.py
indavideo.py
infoq.py
instagram.py
internazionale.py
internetvideoarchive.py
iprima.py
iqiyi.py
ir90tv.py
itv.py
ivi.py
ivideon.py
iwara.py
izlesene.py
jamendo.py
jeuxvideo.py
joj.py
jove.py
jwplatform.py
kakao.py
kaltura.py
kanalplay.py
kankan.py
karaoketv.py
karrierevideos.py
keezmovies.py
kelbyone.py
ketnet.py
khanacademy.py
kickstarter.py
kinja.py
kinopoisk.py
konserthusetplay.py
koo.py
krasview.py
ku6.py
kusi.py
kuwo.py
la7.py
laola1tv.py
lazy_extractors.py
lbry.py
lci.py
lcp.py
lecture2go.py
lecturio.py
leeco.py
lego.py
lemonde.py
lenta.py
libraryofcongress.py
libsyn.py
lifenews.py
limelight.py
line.py
linkedin.py
linuxacademy.py
litv.py
livejournal.py
livestream.py
lnkgo.py
localnews8.py
lovehomeporn.py
lrt.py
lynda.py
m6.py
magentamusik360.py
mailru.py
mainstreaming.py
malltv.py
mangomolo.py
manoto.py
manyvids.py
maoritv.py
markiza.py
massengeschmacktv.py
matchtv.py
mdr.py
medaltv.py
mediaite.py
mediaklikk.py
medialaan.py
mediaset.py
mediasite.py
medici.py
megaphone.py
megatvcom.py
meipai.py
melonvod.py
meta.py
metacafe.py
metacritic.py
mgoon.py
mgtv.py
miaopai.py
microsoftstream.py
microsoftvirtualacademy.py
mildom.py
minds.py
ministrygrid.py
minoto.py
miomio.py
mirrativ.py
mit.py
mitele.py
mixch.py
mixcloud.py
mlb.py
mlssoccer.py
mnet.py
moevideo.py
mofosex.py
mojvideo.py
morningstar.py
motherless.py
motorsport.py
movieclips.py
moviezine.py
movingimage.py
msn.py
mtv.py
muenchentv.py
musescore.py
musicdex.py
mwave.py
mxplayer.py
mychannels.py
myspace.py
myspass.py
myvi.py
myvideoge.py
myvidster.py
n1.py
nate.py
nationalgeographic.py
naver.py
nba.py
nbc.py
ndr.py
ndtv.py
nebula.py
nerdcubed.py
neteasemusic.py
netzkino.py
newgrounds.py
newstube.py
newsy.py
nextmedia.py
nexx.py
nfhsnetwork.py
nfl.py
nhk.py
nhl.py
nick.py
niconico.py
ninecninemedia.py
ninegag.py
ninenow.py
nintendo.py
nitter.py
njpwworld.py
nobelprize.py
noco.py
nonktube.py
noodlemagazine.py
noovo.py
normalboots.py
nosvideo.py
nova.py
novaplay.py
nowness.py
noz.py
npo.py
npr.py
nrk.py
nrl.py
ntvcojp.py
ntvde.py
ntvru.py
nuevo.py
nuvid.py
nytimes.py
nzherald.py
nzz.py
odatv.py
odnoklassniki.py
oktoberfesttv.py
olympics.py
on24.py
once.py
ondemandkorea.py
onefootball.py
onet.py
onionstudios.py
ooyala.py
opencast.py
openload.py
openrec.py
ora.py
orf.py
outsidetv.py
packtpub.py
palcomp3.py
pandoratv.py
paramountplus.py
parliamentliveuk.py
parlview.py
patreon.py
pbs.py
pearvideo.py
peertube.py
peertv.py
peloton.py
people.py
performgroup.py
periscope.py
philharmoniedeparis.py
phoenix.py
photobucket.py
picarto.py
piksel.py
pinkbike.py
pinterest.py
pixivsketch.py
pladform.py
planetmarathi.py
platzi.py
playfm.py
playplustv.py
plays.py
playstuff.py
playtvak.py
playvid.py
playwire.py
pluralsight.py
plutotv.py
podomatic.py
pokemon.py
pokergo.py
polsatgo.py
polskieradio.py
popcorntimes.py
popcorntv.py
porn91.py
porncom.py
pornez.py
pornflip.py
pornhd.py
pornhub.py
pornotube.py
pornovoisines.py
pornoxo.py
presstv.py
projectveritas.py
prosiebensat1.py
prx.py
puhutv.py
puls4.py
pyvideo.py
qqmusic.py
r7.py
radiko.py
radiobremen.py
radiocanada.py
radiode.py
radiofrance.py
radiojavan.py
radiokapital.py
radiozet.py
radlive.py
rai.py
raywenderlich.py
rbmaradio.py
rcs.py
rcti.py
rds.py
redbulltv.py
reddit.py
redgifs.py
redtube.py
regiotv.py
rentv.py
restudy.py
reuters.py
reverbnation.py
rice.py
rmcdecouverte.py
ro220.py
rockstargames.py
roosterteeth.py
rottentomatoes.py
roxwel.py
rozhlas.py
rtbf.py
rte.py
rtl2.py
rtlnl.py
rtnews.py
rtp.py
rtrfm.py
rts.py
rtve.py
rtvnh.py
rtvs.py
ruhd.py
rule34video.py
rumble.py
rutube.py
rutv.py
ruutu.py
ruv.py
safari.py
saitosan.py
samplefocus.py
sapo.py
savefrom.py
sbs.py
screencast.py
screencastomatic.py
scrippsnetworks.py
scte.py
seeker.py
senategov.py
sendtonews.py
servus.py
sevenplus.py
sexu.py
seznamzpravy.py
shahid.py
shared.py
shemaroome.py
showroomlive.py
simplecast.py
sina.py
sixplay.py
skeb.py
sky.py
skyit.py
skylinewebcams.py
skynewsarabia.py
skynewsau.py
slideshare.py
slideslive.py
slutload.py
snotr.py
sohu.py
sonyliv.py
soundcloud.py
soundgasm.py
southpark.py
sovietscloset.py
spankbang.py
spankwire.py
spiegel.py
spiegeltv.py
spike.py
sport5.py
sportbox.py
sportdeutschland.py
spotify.py
spreaker.py
springboardplatform.py
sprout.py
srgssr.py
srmediathek.py
stanfordoc.py
startv.py
steam.py
stitcher.py
storyfire.py
streamable.py
streamanity.py
streamcloud.py
streamcz.py
streamff.py
streetvoice.py
stretchinternet.py
stripchat.py
stv.py
sunporno.py
sverigesradio.py
svt.py
swrmediathek.py
syfy.py
sztvhu.py
tagesschau.py
tass.py
tastytrade.py
tbs.py
tdslifeway.py
teachable.py
teachertube.py
teachingchannel.py
teamcoco.py
teamtreehouse.py
techtalks.py
ted.py
tele13.py
tele5.py
telebruxelles.py
telecinco.py
telegraaf.py
telemb.py
telemundo.py
telequebec.py
teletask.py
telewebion.py
tennistv.py
tenplay.py
testurl.py
tf1.py
tfo.py
theintercept.py
theplatform.py
thescene.py
thestar.py
thesun.py
theta.py
theweatherchannel.py
thisamericanlife.py
thisav.py
thisoldhouse.py
threeqsdn.py
threespeak.py
tiktok.py
tinypic.py
tmz.py
tnaflix.py
toggle.py
toggo.py
tokentube.py
tonline.py
toongoggles.py
toutv.py
toypics.py
traileraddict.py
trilulilu.py
trovo.py
trueid.py
trunews.py
trutv.py
tube8.py
tubitv.py
tudou.py
tumblr.py
tunein.py
tunepk.py
turbo.py
turner.py
tv2.py
tv2dk.py
tv2hu.py
tv4.py
tv5mondeplus.py
tv5unis.py
tva.py
tvanouvelles.py
tvc.py
tver.py
tvigle.py
tvland.py
tvn24.py
tvnet.py
tvnoe.py
tvnow.py
tvopengr.py
tvp.py
tvplay.py
tvplayer.py
tweakers.py
twentyfourvideo.py
twentymin.py
twentythreevideo.py
twitcasting.py
twitch.py
twitter.py
udemy.py
udn.py
ufctv.py
ukcolumn.py
uktvplay.py
umg.py
unistra.py
unity.py
uol.py
uplynk.py
urort.py
urplay.py
usanetwork.py
usatoday.py
ustream.py
ustudio.py
utreon.py
varzesh3.py
vbox7.py
veehd.py
veo.py
veoh.py
vesti.py
vevo.py
vgtv.py
vh1.py
vice.py
vidbit.py
viddler.py
videa.py
videodetective.py
videofyme.py
videomore.py
videopress.py
vidio.py
vidlii.py
vidzi.py
vier.py
viewlift.py
viidea.py
viki.py
vimeo.py
vimm.py
vimple.py
vine.py
viqeo.py
viu.py
vk.py
vlive.py
vodlocker.py
vodpl.py
vodplatform.py
voicerepublic.py
voicy.py
voot.py
voxmedia.py
vrak.py
vrt.py
vrv.py
vshare.py
vtm.py
vube.py
vuclip.py
vupload.py
vvvvid.py
vyborymos.py
vzaar.py
wakanim.py
walla.py
washingtonpost.py
wat.py
watchbox.py
watchindianporn.py
wdr.py
webcaster.py
webofstories.py
weibo.py
weiqitv.py
whowatch.py
willow.py
wimtv.py
wistia.py
worldstarhiphop.py
wppilot.py
wsj.py
wwe.py
xbef.py
xboxclips.py
xfileshare.py
xhamster.py
xiami.py
ximalaya.py
xminus.py
xnxx.py
xstream.py
xtube.py
xuite.py
xvideos.py
xxxymovies.py
yahoo.py
yandexdisk.py
yandexmusic.py
yandexvideo.py
yapfiles.py
yesjapan.py
yinyuetai.py
ynet.py
youjizz.py
youku.py
younow.py
youporn.py
yourporn.py
yourupload.py
youtube.py
zapiks.py
zaq1.py
zattoo.py
zdf.py
zee5.py
zhihu.py
zingmp3.py
zoom.py
zype.py
postprocessor
YoutubeDL.py
__init__.py
__main__.py
aes.py
cache.py
compat.py
cookies.py
jsinterp.py
minicurses.py
options.py
socks.py
update.py
utils.py
version.py
webvtt.py
yt_dlp-2022.2.4.dist-info
__init__.py
__main__.py
download.sh
manifest.json
plugin.py
README.md
src
user_config
.gitignore
LICENSE
README.md
SolarFM/plugins/youtube_download/yt_dlp/extractor/yandexdisk.py

147 lines
5.0 KiB
Python
Raw Normal View History

# coding: utf-8
from __future__ import unicode_literals
import json
from .common import InfoExtractor
from ..utils import (
determine_ext,
float_or_none,
int_or_none,
mimetype2ext,
try_get,
urljoin,
)
class YandexDiskIE(InfoExtractor):
_VALID_URL = r'''(?x)https?://
(?P<domain>
yadi\.sk|
disk\.yandex\.
(?:
az|
by|
co(?:m(?:\.(?:am|ge|tr))?|\.il)|
ee|
fr|
k[gz]|
l[tv]|
md|
t[jm]|
u[az]|
ru
)
)/(?:[di]/|public.*?\bhash=)(?P<id>[^/?#&]+)'''
_TESTS = [{
'url': 'https://yadi.sk/i/VdOeDou8eZs6Y',
'md5': 'a4a8d52958c8fddcf9845935070402ae',
'info_dict': {
'id': 'VdOeDou8eZs6Y',
'ext': 'mp4',
'title': '4.mp4',
'duration': 168.6,
'uploader': 'y.botova',
'uploader_id': '300043621',
'view_count': int,
},
'expected_warnings': ['Unable to download JSON metadata'],
}, {
'url': 'https://yadi.sk/d/h3WAXvDS3Li3Ce',
'only_matching': True,
}, {
'url': 'https://yadi.sk/public?hash=5DZ296JK9GWCLp02f6jrObjnctjRxMs8L6%2B%2FuhNqk38%3D',
'only_matching': True,
}]
def _real_extract(self, url):
domain, video_id = self._match_valid_url(url).groups()
webpage = self._download_webpage(url, video_id)
store = self._parse_json(self._search_regex(
r'<script[^>]+id="store-prefetch"[^>]*>\s*({.+?})\s*</script>',
webpage, 'store'), video_id)
resource = store['resources'][store['rootResourceId']]
title = resource['name']
meta = resource.get('meta') or {}
public_url = meta.get('short_url')
if public_url:
video_id = self._match_id(public_url)
source_url = (self._download_json(
'https://cloud-api.yandex.net/v1/disk/public/resources/download',
video_id, query={'public_key': url}, fatal=False) or {}).get('href')
video_streams = resource.get('videoStreams') or {}
video_hash = resource.get('hash') or url
environment = store.get('environment') or {}
sk = environment.get('sk')
yandexuid = environment.get('yandexuid')
if sk and yandexuid and not (source_url and video_streams):
self._set_cookie(domain, 'yandexuid', yandexuid)
def call_api(action):
return (self._download_json(
urljoin(url, '/public/api/') + action, video_id, data=json.dumps({
'hash': video_hash,
'sk': sk,
}).encode(), headers={
'Content-Type': 'text/plain',
}, fatal=False) or {}).get('data') or {}
if not source_url:
# TODO: figure out how to detect if download limit has
# been reached and then avoid unnecessary source format
# extraction requests
source_url = call_api('download-url').get('url')
if not video_streams:
video_streams = call_api('get-video-streams')
formats = []
if source_url:
formats.append({
'url': source_url,
'format_id': 'source',
'ext': determine_ext(title, meta.get('ext') or mimetype2ext(meta.get('mime_type')) or 'mp4'),
'quality': 1,
'filesize': int_or_none(meta.get('size'))
})
for video in (video_streams.get('videos') or []):
format_url = video.get('url')
if not format_url:
continue
if video.get('dimension') == 'adaptive':
formats.extend(self._extract_m3u8_formats(
format_url, video_id, 'mp4', 'm3u8_native',
m3u8_id='hls', fatal=False))
else:
size = video.get('size') or {}
height = int_or_none(size.get('height'))
format_id = 'hls'
if height:
format_id += '-%dp' % height
formats.append({
'ext': 'mp4',
'format_id': format_id,
'height': height,
'protocol': 'm3u8_native',
'url': format_url,
'width': int_or_none(size.get('width')),
})
self._sort_formats(formats)
uid = resource.get('uid')
display_name = try_get(store, lambda x: x['users'][uid]['displayName'])
return {
'id': video_id,
'title': title,
'duration': float_or_none(video_streams.get('duration'), 1000),
'uploader': display_name,
'uploader_id': uid,
'view_count': int_or_none(meta.get('views_counter')),
'formats': formats,
}