Пример #1
0
def get_embed_code(url, maxwidth=None, maxheight=None):
    embed = {}
    header = cache.get_headers(url)
    if header.get('content-type', '').startswith('text/html'):
        html = cache.read_url(url)
        json_oembed = filter(lambda l: 'json+oembed' in l, re.compile('<link.*?>').findall(html))
        xml_oembed = filter(lambda l: 'xml+oembed' in l, re.compile('<link.*?>').findall(html))
        if json_oembed:
            oembed_url = find_re(json_oembed[0], 'href="(.*?)"')
            if maxwidth:
                oembed_url += '&maxwidth=%d' % maxwidth
            if maxheight:
                oembed_url += '&maxheight=%d' % maxheight
            embed = json.loads(cache.read_url(oembed_url))
        elif xml_oembed:
            oembed_url = find_re(json_oembed[0], 'href="(.*?)"')
            if maxwidth:
                oembed_url += '&maxwidth=%d' % maxwidth
            if maxheight:
                oembed_url += '&maxheight=%d' % maxheight
            data = cache.read_url(oembed_url)
            for e in ET.fromstring(data):
                embed[e.tag] = e.text
    return embed
Пример #2
0
def parse_movie_path(path):
    """
        "A/Abrams, J.J.; Lieber, Jeffrey; Lindelof, Damon/Lost (2004)/Lost.Season 3.Episode 21.Greatest Hits.avi"
        "B/Balada, Ivan/Metrum (1967)/Metrum.Part 1.en.srt"
        "N/Nakata, Hideo/L - Change the World (2008)/L - Change the World.Part 2.srt"
        "R/Reitz, Edgar/Heimat (1984-2006)/Heimat.Season 2.Episode 8.The Wedding.Part 2.avi"
        "F/Feuillade, Louis/Les vampires (1915)/Les vampires.Episode 10.Part 2.avi"
            title: 'Les vampires', year: '1915', episode: 10, part: 2

        "G/Godard, Jean-Luc/Histoire(s) du cinema_ Toutes les histoires (1988)/Histoire(s) du cinema_ Toutes les histoires.avi"
        "G/Godard, Jean-Luc/Six fois deux (1976)/Six fois deux.Part 1A.Y a personne.avi"
        "G/Godard, Jean-Luc; Miéville, Anne-Marie/France_tour_detour_deux_enfants (1977)/France_tour_detour_deux_enfants.Part 5.Impression_Dictée.avi"

        "L/Labarthe, André S_/Cinéastes de notre temps (1964-)/Cinéastes de notre temps.Episode.Jean Renoir le patron, première partie_ La Recherche du relatif.avi"
        "S/Scott, Ridley/Blade Runner (1982)/Blade Runner.Directors's Cut.avi"

        or
        
        T/Title (Year)/Title.avi
    """
    episodeTitle = episodeYear = seriesTitle = None
    episodeDirector = []
    parts = path.split('/')

    #title/year
    if len(parts) == 4:
        title = parts[2]
    elif len(parts) > 1:
        title = parts[1]
    else:
        title = parts[0]
    title = title.replace('_ ', ': ')
    if title.endswith('_'):
        title = title[:-1] + '.'
    if title.startswith('_'):
        title = '.' + title[1:]

    year = find_re(title, '(\(\d{4}\))')
    if not year:
        year = find_re(title, '(\(\d{4}-\d*\))')
    if year and title.endswith(year):
        title = title[:-len(year)].strip()
        year = year[1:-1]
        if '-' in year:
            year = find_re(year, '\d{4}')

    #director
    if len(parts) == 4:
        director = parts[1]
        if director.endswith('_'):
            director = "%s." % director[:-1]
        director = director.split('; ')
        director = [normalize_name(d).strip() for d in director]
        director = filter(lambda d: d not in ('Unknown Director', 'Various Directors'), director)
    else:
        director = []

    #extension/language
    fileparts = [x.replace('||', '. ') for x in parts[-1].replace('. ', '||').split('.')]
    extension = len(fileparts) > 1 and fileparts[-1] or ''

    if len(fileparts) > 1 and len(fileparts[-2]) == 2:
        language = fileparts[-2]
    else:
        language = ''
    
    #season/episode/episodeTitle
    match = re.compile('(.+?) \((S(\d+))?(E(\d+))?\)( (.+?))?\.').match(parts[-1])
    if match:
        seriesTitle = match.group(1)
        season = match.group(3)
        episode = match.group(5)
        episodeTitle = (match.group(6) or '').strip()
        if episode != None:
            episode = int(episode)
        if season != None:
            season = int(season)
        if episode and not season:
            season = 1
    else:
        season = find_re(parts[-1], '\.Season (\d+)\.')
        if season:
            season = int(season)
        else:
            season = None

        episode = find_re(parts[-1], '\.Episode[s]* ([\d+]+)\.')
        if episode:
            episode = episode.split('+')[0]
            episode = int(episode)
        else:
            episode = None

        if episode and 'Episode %d'%episode in fileparts:
            episodeTitle = fileparts.index('Episode %d' % episode) + 1
            episodeTitle = fileparts[episodeTitle]
            if episodeTitle == extension or episodeTitle.startswith('Part'):
                episodeTitle = None

        if not season and 'Episode' in fileparts:
            episodeTitle = fileparts.index('Episode') + 1
            episodeTitle = fileparts[episodeTitle]
            if episodeTitle == extension or episodeTitle.startswith('Part'):
                episodeTitle = None
            else:
                season = 1

    if season:
        seriesTitle = title
        title = u'%s (S%02d)' % (seriesTitle, season)
        if isinstance(episode, int):
            title = u'%s (S%02dE%02d)' % (seriesTitle, season, episode)
        if episodeTitle:
            title = u'%s %s' % (title, episodeTitle)

    #part
    part = find_re(parts[-1], '\.Part (\d+)\.')
    if part:
        part = int(part)
    else:
        part = 0

    return {
        'director': director,
        'episodeDirector': episodeDirector,
        'episode': episode,
        'episodeTitle': episodeTitle,
        'episodeYear': episodeYear,
        'extension': extension,
        'language': language,
        'part': part,
        'season': season,
        'seriesTitle': seriesTitle,
        'title': title,
        'year': year,
    }