mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-03 20:23:13 +08:00
[tistory] Add support for daum
This commit is contained in:
parent
7829a5c2db
commit
dd6bda841f
@ -18,11 +18,10 @@ from ..compat import (
|
|||||||
import os.path
|
import os.path
|
||||||
import cgi
|
import cgi
|
||||||
import re
|
import re
|
||||||
import xml.etree.ElementTree as ET
|
|
||||||
|
|
||||||
|
|
||||||
class TistoryBaseIE(InfoExtractor):
|
class TistoryBaseIE(InfoExtractor):
|
||||||
_TI_MEDIA_URL = r'https?://cfile[0-9]*.uf.tistory.com/(?:media|attach|attachment|original)/(?P<id>[A-Za-z0-9]*)'
|
_TI_MEDIA_URL = r'https?://cfile[0-9]*.uf.(tistory.com|daum.net)/(?:media|attach|attachment|original)/(?P<id>[A-Za-z0-9]*)'
|
||||||
|
|
||||||
def _ti_unquote(self, url):
|
def _ti_unquote(self, url):
|
||||||
return compat_urlparse.unquote(url)
|
return compat_urlparse.unquote(url)
|
||||||
@ -48,18 +47,19 @@ class TistoryBaseIE(InfoExtractor):
|
|||||||
return ext
|
return ext
|
||||||
|
|
||||||
def _ti_get_real_from_check(self, check):
|
def _ti_get_real_from_check(self, check):
|
||||||
checkmatch = re.search("(cfile[0-9]*.uf)@([A-Z0-9]*)(?:\.([A-Za-z0-9]*))?", check)
|
checkmatch = re.search("(?P<host>(tistory.com|daum.net)).*(?P<server>cfile[0-9]*.uf)@(?P<id>[A-Z0-9]*)(?:\.(?P<ext>[A-Za-z0-9]*))?", check)
|
||||||
if not checkmatch:
|
if not checkmatch:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
cfile = checkmatch.group(1)
|
host = checkmatch.group("host")
|
||||||
url = checkmatch.group(2)
|
cfile = checkmatch.group("server")
|
||||||
|
url = checkmatch.group("id")
|
||||||
ext = None
|
ext = None
|
||||||
|
|
||||||
if len(checkmatch.groups()) > 2:
|
if len(checkmatch.groups()) > 3:
|
||||||
ext = checkmatch.group(3)
|
ext = checkmatch.group("ext")
|
||||||
|
|
||||||
return ("http://" + cfile + ".tistory.com/attach/" + url, ext)
|
return ("http://" + cfile + "." + host + "/attach/" + url, ext)
|
||||||
|
|
||||||
def _ti_get_video_id(self, url):
|
def _ti_get_video_id(self, url):
|
||||||
if '_TI_MEDIA_URL_RE' not in self.__dict__:
|
if '_TI_MEDIA_URL_RE' not in self.__dict__:
|
||||||
@ -83,6 +83,14 @@ class TistoryBaseIE(InfoExtractor):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _ti_detect_xml(self, head):
|
||||||
|
content_type = head.info().get("content-type")
|
||||||
|
|
||||||
|
if "xml" in content_type or content_type == "text/html":
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def _ti_get_media(self, url, video_id, head, ext=None, title=None):
|
def _ti_get_media(self, url, video_id, head, ext=None, title=None):
|
||||||
if head:
|
if head:
|
||||||
content_type = head.info().get("content-type")
|
content_type = head.info().get("content-type")
|
||||||
@ -141,8 +149,29 @@ class TistoryBaseIE(InfoExtractor):
|
|||||||
|
|
||||||
return (real_url, ext)
|
return (real_url, ext)
|
||||||
|
|
||||||
def _ti_dl(self, url, ext=None, title=None):
|
def _ti_read_xml(self, url, video_id):
|
||||||
video_id = self._ti_get_video_id(url)
|
xml = self._download_xml(url, video_id)
|
||||||
|
entries = []
|
||||||
|
|
||||||
|
for tracklist in xml:
|
||||||
|
for track in tracklist:
|
||||||
|
for tag in track:
|
||||||
|
if "location" not in tag.tag:
|
||||||
|
continue
|
||||||
|
|
||||||
|
loc = tag.text
|
||||||
|
|
||||||
|
newloc, ext = self._ti_get_real_from_check(loc)
|
||||||
|
if newloc:
|
||||||
|
loc = newloc
|
||||||
|
|
||||||
|
entries.append(self._ti_dl(loc, ext))
|
||||||
|
|
||||||
|
return self.playlist_result(entries)
|
||||||
|
|
||||||
|
def _ti_dl(self, url, ext=None, title=None, video_id=None):
|
||||||
|
if not video_id:
|
||||||
|
video_id = self._ti_get_video_id(url)
|
||||||
|
|
||||||
head = None
|
head = None
|
||||||
|
|
||||||
@ -155,6 +184,8 @@ class TistoryBaseIE(InfoExtractor):
|
|||||||
|
|
||||||
if head and self._ti_detect_swf(head):
|
if head and self._ti_detect_swf(head):
|
||||||
return self._ti_dl(*self._ti_read_swf(url, video_id, head))
|
return self._ti_dl(*self._ti_read_swf(url, video_id, head))
|
||||||
|
elif head and self._ti_detect_xml(head):
|
||||||
|
return self._ti_read_xml(url, video_id)
|
||||||
else:
|
else:
|
||||||
return self._ti_get_media(url, video_id, head, ext, title)
|
return self._ti_get_media(url, video_id, head, ext, title)
|
||||||
|
|
||||||
@ -188,29 +219,10 @@ class TistoryIE(TistoryBaseIE):
|
|||||||
|
|
||||||
|
|
||||||
class TistoryPlaylistIE(TistoryBaseIE):
|
class TistoryPlaylistIE(TistoryBaseIE):
|
||||||
_VALID_URL = r'(?:https?://cfs.tistory.com/custom/blog/.*/skin/images/po.swf?.*file=)?(?P<rurl>https?://cfs.tistory.com/custom/blog/.*/skin/images/(?P<id>.*)\.xml).*'
|
_VALID_URL = r'.*(?P<rurl>https?://cfs.tistory.com/custom/blog/.*/skin/images/(?P<id>.*)\.xml).*'
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
rurl = self._VALID_URL_RE.match(url).group("rurl")
|
rurl = self._VALID_URL_RE.match(url).group("rurl")
|
||||||
|
|
||||||
xml = self._download_xml(rurl, video_id)
|
return self._ti_dl(rurl, video_id=video_id)
|
||||||
entries = []
|
|
||||||
|
|
||||||
for tracklist in xml:
|
|
||||||
for track in tracklist:
|
|
||||||
for tag in track:
|
|
||||||
print(ET.tostring(tag))
|
|
||||||
if "location" not in tag.tag:
|
|
||||||
continue
|
|
||||||
|
|
||||||
loc = tag.text
|
|
||||||
|
|
||||||
newloc, ext = self._ti_get_real_from_check(loc)
|
|
||||||
if newloc:
|
|
||||||
loc = newloc
|
|
||||||
|
|
||||||
entries.append(self._ti_dl(loc, ext))
|
|
||||||
|
|
||||||
|
|
||||||
return self.playlist_result(entries)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user