-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSORGFetcher.py
42 lines (29 loc) · 1.43 KB
/
SORGFetcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#-*- coding: utf-8 -*-
__author__ = 'kovtash'
from serviceFetcher import serviceFetcher
import cookielib, downloader, json, logging
class SORGFetcher(serviceFetcher):
SHORT_NAME = 'SORG'
def downloadWorker(self,episodeUrl,tmpFilePath):
showURL = episodeUrl.split('|')[0]
episodeID = episodeUrl.split('|')[1]
showCookie = cookielib.CookieJar()
showPage=downloader.HTMLDocGet(showURL,None,showCookie)
#Если не удалось получить страницу, перейти к слеующей
if showPage.data==None:
logging.error("Can\'t fetch show page")
return False
playlistRaw="".join(showPage.data.xpath('//div[@class="content"]/script/descendant::text()')).replace('\\/','/')
playlistDataStart=playlistRaw.find('p.setPlaylist( ')+15
playlistData=playlistRaw[playlistDataStart:playlistRaw.find(']',playlistDataStart)+1]
playlist=json.loads(playlistData)
episodeURL=None
for playlistEntry in playlist:
if str(playlistEntry[u"episodeId"])==episodeID:
episodeURL=playlistEntry[u"file"]
if episodeURL==None:
logging.error("Can\'t find clip url")
return False
logging.error(episodeURL)
#return True #TODO: разблокировать загрузку файлов
return downloader.fetchfile(episodeURL,tmpFilePath,cookie=showCookie)