Ejemplo n.º 1
0
    def getVideoInfo(self, url):
        # General configuration
        tf = tempfile.NamedTemporaryFile(delete=False)
        tf.close()
        self.cookies = tf.name
        jar = compat_cookiejar.MozillaCookieJar(self.cookies)
        cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
        proxies = compat_urllib_request.getproxies()
        proxy_handler = compat_urllib_request.ProxyHandler(proxies)
        https_handler = make_HTTPS_handler(None)
        opener = compat_urllib_request.build_opener(https_handler,
                                                    proxy_handler,
                                                    cookie_processor,
                                                    YoutubeDLHandler)
        compat_urllib_request.install_opener(opener)

        y = youtube_dl.YoutubeDL({
            'outtmpl': u'',
            'skip_download': True
        })  # empty outtmpl needed due to weird issue in youtube-dl
        y.add_info_extractor(WatchCartoonOnlineIE())
        y.add_default_info_extractors()

        try:
            info = y.extract_info(url, download=False)
        except Exception:
            raise
            self.status = 'invalid'
            self.queue.removeMeAsync(self.uid)  # Remove if possible
            self.ready.release()
            return False

        jar.save()

        if 'entries' in info:
            vinfo = info['entries'][0]
        else:
            vinfo = info

        if 'title' in vinfo:
            self.title = vinfo['title']
        if 'duration' in vinfo:
            self.duration = vinfo['duration']
        if 'extractor' in vinfo:
            self.site = vinfo['extractor']
        if 'url' in vinfo:
            self.media = vinfo['url']
        if 'thumbnail' in vinfo:
            self.thumbnail = vinfo['thumbnail']
        if 'description' in vinfo:
            self.description = vinfo['description']
        if 'id' in vinfo:
            self.vid = vinfo['id']

        if self.status == 'added':
            self.status = 'ready'

        self.ready.release()
        return True
Ejemplo n.º 2
0
	def getVideoInfo(self,url):
		# General configuration
		tf=tempfile.NamedTemporaryFile(delete=False)
		tf.close()
		self.cookies=tf.name
		jar = compat_cookiejar.MozillaCookieJar(self.cookies)
		cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
		proxies = compat_urllib_request.getproxies()
		proxy_handler = compat_urllib_request.ProxyHandler(proxies)
		https_handler = make_HTTPS_handler(None)
		opener = compat_urllib_request.build_opener(https_handler, proxy_handler, cookie_processor, YoutubeDLHandler)
		compat_urllib_request.install_opener(opener)

		y=youtube_dl.YoutubeDL({'outtmpl':u'','skip_download':True}) # empty outtmpl needed due to weird issue in youtube-dl
		y.add_info_extractor(WatchCartoonOnlineIE())
		y.add_default_info_extractors()

		try:
			info=y.extract_info(url,download=False)
		except Exception:
			raise
			self.status='invalid'
			self.queue.removeMeAsync(self.uid) # Remove if possible
			self.ready.release()
			return False

		jar.save()

		if 'entries' in info:
			vinfo=info['entries'][0]
		else:
			vinfo=info

		if 'title' in vinfo:
			self.title=vinfo['title']
		if 'duration' in vinfo:
			self.duration=vinfo['duration']
		if 'extractor' in vinfo:
			self.site=vinfo['extractor']
		if 'url' in vinfo:
			self.media=vinfo['url']
		if 'thumbnail' in vinfo:
			self.thumbnail=vinfo['thumbnail']
		if 'description' in vinfo:
			self.description=vinfo['description']
		if 'id' in vinfo:
			self.vid=vinfo['id']

		if self.status=='added':
			self.status='ready'

		self.ready.release()
		return True
Ejemplo n.º 3
0
import os.path
import re
import types

import youtube_dl.extractor
from youtube_dl import YoutubeDL, YoutubeDLHandler
from youtube_dl.utils import (
    compat_cookiejar,
    compat_urllib_request,
)

# General configuration (from __init__, not very elegant...)
jar = compat_cookiejar.CookieJar()
cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
proxy_handler = compat_urllib_request.ProxyHandler()
opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
compat_urllib_request.install_opener(opener)

PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
    parameters = json.load(pf)


def try_rm(filename):
    """ Remove a file if it exists """
    try:
        os.remove(filename)
    except OSError as ose:
        if ose.errno != errno.ENOENT:
            raise
Ejemplo n.º 4
0
def setup_url_handlers():
    opener = compat_urllib_request.build_opener( YoutubeDLHandler())
    opener.addheaders =[]
    compat_urllib_request.install_opener(opener)