示例#1
0
class EdXBrowser(object):
    def __init__(self, config):
        self._br = mechanize.Browser()
        self._cj = mechanize.LWPCookieJar()
        csrftoken = makeCsrf()
        self._cj.set_cookie(csrfCookie(csrftoken))
        self._br.set_handle_robots(False)
        self._br.set_cookiejar(self._cj)
        self._br.addheaders.append(('X-CSRFToken',csrftoken))
        self._br.addheaders.append(('Referer',base_url))
        self._logged_in = False
        self._fd = YoutubeDL(config.YDL_PARAMS)
        self._fd.add_info_extractor(YoutubeIE())
        self._config = config

    def login(self):
        try:
            login_resp = self._br.open(base_url + login_url, urlencode({'email':self._config.EMAIL, 'password':self._config.PASSWORD}))
            login_state = json.loads(login_resp.read())
            self._logged_in = login_state.get('success')
            if not self._logged_in:
                print login_state.get('value')
            return self._logged_in
        except mechanize.HTTPError, e:
            sys.exit('Can\'t sign in')
示例#2
0
class EdXBrowser(object):
    def __init__(self, config):
        self._br = mechanize.Browser()
        self._cj = mechanize.LWPCookieJar()
        csrftoken = makeCsrf()
        self._cj.set_cookie(csrfCookie(csrftoken))
        self._br.set_handle_robots(False)
        self._br.set_cookiejar(self._cj)
        self._br.addheaders.append(('X-CSRFToken', csrftoken))
        self._br.addheaders.append(('Referer', base_url))
        self._logged_in = False
        self._fd = YoutubeDL(config.YDL_PARAMS)
        self._fd.add_info_extractor(YoutubeIE())
        self._config = config

    def login(self):
        try:
            login_resp = self._br.open(
                base_url + login_url,
                urlencode({
                    'email': self._config.EMAIL,
                    'password': self._config.PASSWORD
                }))
            login_state = json.loads(login_resp.read())
            self._logged_in = login_state.get('success')
            if not self._logged_in:
                print login_state.get('value')
            return self._logged_in
        except mechanize.HTTPError, e:
            sys.exit('Can\'t sign in')
 def extractYoutubeDL(self, url, video):
     links = {}
     try:
         from youtube_dl.YoutubeDL import YoutubeDL, ExtractorError
     except ImportError:
         util.error("no youtube-dl installed!")
         return links
     ydl = YoutubeDL({'youtube_include_dash_manifest':False}, auto_init=False)
     ydl.add_info_extractor(ydl.get_info_extractor("Youtube"))
     try:
         res = ydl.extract_info(url, False, ie_key="Youtube")
     except ExtractorError as e:
         util.error(str(e))
         return links
     for e in res['formats']:
         links[int(e['format_id'])] = e['url']
     return links
 def extractYoutubeDL(self, url, video):
     links = {}
     try:
         from youtube_dl.YoutubeDL import YoutubeDL, ExtractorError
     except ImportError:
         util.error("no youtube-dl installed!")
         return links
     ydl = YoutubeDL({'youtube_include_dash_manifest': False},
                     auto_init=False)
     ydl.add_info_extractor(ydl.get_info_extractor("Youtube"))
     try:
         res = ydl.extract_info(url, False, ie_key="Youtube")
     except ExtractorError as e:
         util.error(str(e))
         return links
     for e in res['formats']:
         links[int(e['format_id'])] = e['url']
     return links
def main():
    ns = parse_args()

    ydl = YoutubeDL({
        'quiet': True,
        'outtmpl': '%(title).%(ext)s',
        'simulate': ns.simulate,
    })

    ydl.add_info_extractor(YoutubeSearchIE())
    ydl.add_info_extractor(YoutubeIE())

    ydl.add_post_processor(FFmpegExtractAudioPP())

    artist = Artist(ns.artista)

    if not artist.found:
        print('ERROR: %s no existe' % artist.name)
        return 1

    print('Obteniendo información de %s...' % artist.name)
    artist.parse()

    if not ns.simulate and not os.path.exists(artist.name):
        os.mkdir(artist.name)

    if ns.disco is None:
        albums = artist.albums
    else:
        album = artist.get_album(ns.disco)

        if album is None or not album.found:
            print('ERROR: %s no tiene un disco %s' % (artist.name, ns.disco))
            return 1

        albums = [album]

    for album in albums:
        if not album.found:
            print('Ignorando %s' % album.name)
            continue

        fpath = os.path.join(artist.name, '%s - %s' % (album.year, album.name))

        if not ns.simulate and not os.path.exists(fpath):
            os.mkdir(fpath)

        if ns.disco is None:
            print('%s:' % album.name)
        else:
            print('Obteniendo lista de temas...')

        album.parse()

        for song in album.songs:
            fname = FILE_FORMAT % (album.songs.index(song) + 1, song)

            print(' %s' % fname)

            ydl.params['outtmpl'] = os.path.join(fpath, fname + '.%(ext)s')
            ydl.download(['ytsearch:%s %s' % (artist.name, song)])

    return 0