Example #1
0
def video_info(url):
    """Fetch info about a video using youtube-dl

    :param url: URL of the web page containing the video
    :rtype: :class:`weboob.capabilities.video.Video`
    """

    if not MediaPlayer._find_in_path(os.environ['PATH'], 'youtube-dl'):
        raise Exception('Please install youtube-dl')

    try:
        j = json.loads(subprocess.check_output(['youtube-dl', '-f', 'best', '-J', url]))
    except subprocess.CalledProcessError:
        return

    v = BaseVideo(id=url)
    v.title = j.get('title') or NotAvailable
    v.ext = j.get('ext') or NotAvailable
    v.description = j.get('description') or NotAvailable
    v.url = j['url']
    v.duration = j.get('duration') or NotAvailable
    v.author = j.get('uploader') or NotAvailable
    v.rating = j.get('average_rating') or NotAvailable

    if j.get('thumbnail'):
        v.thumbnail = Thumbnail(j['thumbnail'])

    d = j.get('upload_date', j.get('release_date'))
    if d:
        v.date = parse_date(d)

    return v
Example #2
0
    def parse_movie(self, movie):
        video = BaseVideo(u'%s#%s' % (movie['code'], 'movie'))
        video.title = unicode(movie['trailer']['name'])
        video._video_code = unicode(movie['trailer']['code'])
        video.ext = u'mp4'
        if 'poster' in movie:
            video.thumbnail = Thumbnail(movie['poster']['href'])
            video.thumbnail.url = unicode(movie['poster']['href'])
        tdate = movie['release']['releaseDate'].split('-')
        day = 1
        month = 1
        year = 1901
        if len(tdate) > 2:
            year = int(tdate[0])
            month = int(tdate[1])
            day = int(tdate[2])

        video.date = date(year, month, day)
        if 'userRating' in movie['statistics']:
            video.rating = movie['statistics']['userRating']
        elif 'pressRating' in movie['statistics']:
            video.rating = movie['statistics']['pressRating'] * 2
        video.rating_max = 5
        if 'synopsis' in movie:
            video.description = unicode(movie['synopsis'].replace(
                '<p>', '').replace('</p>', ''))
        elif 'synopsisShort' in movie:
            video.description = unicode(movie['synopsisShort'].replace(
                '<p>', '').replace('</p>', ''))
        if 'castingShort' in movie:
            if 'directors' in movie['castingShort']:
                video.author = unicode(movie['castingShort']['directors'])
        if 'runtime' in movie:
            video.duration = timedelta(seconds=int(movie['runtime']))
        return video
Example #3
0
    def create_video_from_json(self, _video):
        video = BaseVideo()
        video.id = u'%s' % _video['id']
        video.backend = u'%s' % _video['id'].split('@')[-1]

        if 'url' in _video.keys():
            video.url = u'%s' % _video['url']

        if 'thumbnail' in _video.keys() and _video['thumbnail'] and 'url' in _video['thumbnail'].keys():
            video.thumbnail = BaseImage()
            video.thumbnail.url = u'%s' % _video['thumbnail']['url']
        else:
            video.thumbnail.url = u''
        video.title = u'%s' % _video['title']

        if _video['date']:
            _date = re.search('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*', _video['date'])

            try:
                datetime.strptime(_date.group(1), '%Y-%m-%d %H:%M:%S')
            except TypeError:
                datetime(*(time.strptime(_date.group(1), '%Y-%m-%d %H:%M:%S')[0:6]))

        video.description = u'%s' % _video['description']
        video.author = u'%s' % _video['author']

        if _video['duration']:
            _duration = _video['duration'].split(':')
            video.duration = timedelta(hours=int(_duration[0]), minutes=int(_duration[1]), seconds=int(_duration[2]))

        return video
Example #4
0
    def parse_movie(self, movie):
        video = BaseVideo(u'%s#%s' % (movie['code'], 'movie'))
        video.title = unicode(movie['trailer']['name'])
        video._video_code = unicode(movie['trailer']['code'])
        video.ext = u'mp4'
        if 'poster' in movie:
            video.thumbnail = Thumbnail(movie['poster']['href'])
            video.thumbnail.url = unicode(movie['poster']['href'])
        tdate = movie['release']['releaseDate'].split('-')
        day = 1
        month = 1
        year = 1901
        if len(tdate) > 2:
            year = int(tdate[0])
            month = int(tdate[1])
            day = int(tdate[2])

        video.date = date(year, month, day)
        if 'userRating' in movie['statistics']:
            video.rating = movie['statistics']['userRating']
        elif 'pressRating' in movie['statistics']:
            video.rating = movie['statistics']['pressRating'] * 2
        video.rating_max = 5
        if 'synopsis' in movie:
            video.description = unicode(movie['synopsis'].replace('<p>', '').replace('</p>', ''))
        elif 'synopsisShort' in movie:
            video.description = unicode(movie['synopsisShort'].replace('<p>', '').replace('</p>', ''))
        if 'castingShort' in movie:
            if 'directors' in movie['castingShort']:
                video.author = unicode(movie['castingShort']['directors'])
        if 'runtime' in movie:
            video.duration = timedelta(seconds=int(movie['runtime']))
        return video
Example #5
0
    def parse_movie(self, movie):
        video = BaseVideo(u"%s#%s" % (movie["code"], "movie"))
        video.title = unicode(movie["trailer"]["name"])
        video._video_code = unicode(movie["trailer"]["code"])
        video.ext = u"mp4"
        if "poster" in movie:
            video.thumbnail = BaseImage(movie["poster"]["href"])
            video.thumbnail.url = unicode(movie["poster"]["href"])
        tdate = movie["release"]["releaseDate"].split("-")
        day = 1
        month = 1
        year = 1901
        if len(tdate) > 2:
            year = int(tdate[0])
            month = int(tdate[1])
            day = int(tdate[2])

        video.date = date(year, month, day)
        if "userRating" in movie["statistics"]:
            video.rating = movie["statistics"]["userRating"]
        elif "pressRating" in movie["statistics"]:
            video.rating = movie["statistics"]["pressRating"] * 2
        video.rating_max = 5
        if "synopsis" in movie:
            video.description = unicode(movie["synopsis"].replace("<p>", "").replace("</p>", ""))
        elif "synopsisShort" in movie:
            video.description = unicode(movie["synopsisShort"].replace("<p>", "").replace("</p>", ""))
        if "castingShort" in movie:
            if "directors" in movie["castingShort"]:
                video.author = unicode(movie["castingShort"]["directors"])
        if "runtime" in movie:
            video.duration = timedelta(seconds=int(movie["runtime"]))
        return video
Example #6
0
def video_info(url):
    """Fetch info about a video using youtube-dl

    :param url: URL of the web page containing the video
    :rtype: :class:`weboob.capabilities.video.Video`
    """

    if not MediaPlayer._find_in_path(os.environ['PATH'], 'youtube-dl'):
        raise Exception('Please install youtube-dl')

    try:
        j = json.loads(
            subprocess.check_output(['youtube-dl', '-f', 'best', '-J', url]))
    except subprocess.CalledProcessError:
        return

    v = BaseVideo(id=url)
    v.title = j.get('title') or NotAvailable
    v.ext = j.get('ext') or NotAvailable
    v.description = j.get('description') or NotAvailable
    v.url = j['url']
    v.duration = j.get('duration') or NotAvailable
    v.author = j.get('uploader') or NotAvailable
    v.rating = j.get('average_rating') or NotAvailable

    if j.get('thumbnail'):
        v.thumbnail = Thumbnail(j['thumbnail'])

    d = j.get('upload_date', j.get('release_date'))
    if d:
        v.date = parse_date(d)

    return v