Пример #1
0
def mark_watched(media_id):
    user = auth.get_logged_in_user()
    media = Media.get(Media.id == media_id)
    info = WatchInfo().get(WatchInfo.user == user and WatchInfo.media == media)
    info.watched = True
    info.save()
    return redirect(url_for('homepage'))
Пример #2
0
def mark_hidden(media_id):
    user = auth.get_logged_in_user()
    media = Media.get(Media.id == media_id)
    info = WatchInfo().get(WatchInfo.user == user and WatchInfo.media == media)
    info.visible = False
    info.save()
    return redirect(url_for('homepage'))
Пример #3
0
def available_series():
    user = auth.get_logged_in_user()
    user_series = list(SeriesWatchInfo.select().where(
        (SeriesWatchInfo.user == user) & (SeriesWatchInfo.visible == True)
        & (SeriesWatchInfo.following == False)
        & (SeriesWatchInfo.permissions == True)))
    return render_template('available_series.html', series=user_series)
Пример #4
0
def homepage():
    user = auth.get_logged_in_user()
    query = WatchInfo.select().join(Media).where(
        (WatchInfo.user == user) & (WatchInfo.visible == True)
        & (WatchInfo.watched == False)).order_by(Media.season, Media.episode)
    watch_next = list(query)

    movies = []
    series = []
    episodes = []
    for watchable in watch_next:
        if watchable.media.type == 'movie':
            movies.append(watchable)
        elif watchable.media.type == 'tvepisode':
            if watchable.media.series.name not in series:
                episodes.append(watchable)
                series.append(watchable.media.series.name)

    episodes = sorted(episodes, key=lambda x: x.media.series.id)
    movies = sorted(
        movies,
        key=lambda x: "{0:03d}-{1}".format(100 - x.progress, x.media.name))
    context = {
        'nothing_to_watch': len(watch_next) == 0,
        'movies': movies,
        'episodes': episodes
    }
    return render_template('home.html', **context)
Пример #5
0
def play_media(media_id, transcode_id):
    user = auth.get_logged_in_user()
    media = Media.get(Media.id == media_id)
    watchinfo = WatchInfo.get(WatchInfo.user == user, WatchInfo.media == media)
    transcodes = TranscodedMedia.select().where(TranscodedMedia.media == media)
    src = '/stream/{}'.format(media.path)
    if transcode_id:
        src = '/stream/transcoded/{}/{}.mkv'.format(transcode_id, media.id)
    return render_template('play.html', media=media, watchinfo=watchinfo, transcodes=transcodes,
                           transcode_id=transcode_id, src=src)
Пример #6
0
def mark_season_watched(season_id):
    """ This function does horrible things to your mysql. (n*2)+3 queries"""
    user = auth.get_logged_in_user()
    season = Season.get(Season.id == season_id)
    episodes = list(Media.select().where((Media.series == season.series) & (Media.season == season.number)))
    for episode in episodes:
        info = WatchInfo().get((WatchInfo.user == user) & (WatchInfo.media == episode))
        info.watched = True
        info.save()

    return redirect(url_for('homepage'))
Пример #7
0
def progress(media_id, progress):
    user = auth.get_logged_in_user()
    media = Media.get(Media.id == media_id)
    info = WatchInfo().get((WatchInfo.user == user) & (WatchInfo.media == media))
    info.progress = progress

    if progress > media.length * 0.9:
        info.watched = True

    info.save()
    return '{}'
Пример #8
0
def progress(media_id, progress):
    user = auth.get_logged_in_user()
    media = Media.get(Media.id == media_id)
    info = WatchInfo().get((WatchInfo.user == user)
                           & (WatchInfo.media == media))
    info.progress = progress

    if progress > media.length * 0.9:
        info.watched = True

    info.save()
    return '{}'
Пример #9
0
def mark_season_watched(season_id):
    """ This function does horrible things to your mysql. (n*2)+3 queries"""
    user = auth.get_logged_in_user()
    season = Season.get(Season.id == season_id)
    episodes = list(Media.select().where((Media.series == season.series)
                                         & (Media.season == season.number)))
    for episode in episodes:
        info = WatchInfo().get((WatchInfo.user == user)
                               & (WatchInfo.media == episode))
        info.watched = True
        info.save()

    return redirect(url_for('homepage'))
Пример #10
0
def series_details(series_id):
    user = auth.get_logged_in_user()
    series = Series.get(Series.id == series_id)
    seasons = Season.select().where(Season.series == series)
    episodes = list(Media.select().where(Media.series == series).order_by(-Media.season, -Media.episode))
    season_episodes = {}
    for episode in episodes:
        if episode.season not in season_episodes.keys():
            season_episodes[episode.season] = {}
        season_episodes[episode.season][episode.episode] = episode
    actors = SeriesActor.select().join(Actor).where(SeriesActor.series == series)
    return render_template('series-details.html', series=series, season_episodes=season_episodes, actors=actors,
                           seasons=seasons)
Пример #11
0
def play_media(media_id, transcode_id):
    user = auth.get_logged_in_user()
    media = Media.get(Media.id == media_id)
    watchinfo = WatchInfo.get(WatchInfo.user == user, WatchInfo.media == media)
    transcodes = TranscodedMedia.select().where(TranscodedMedia.media == media)
    src = '/stream/{}'.format(media.path)
    if transcode_id:
        src = '/stream/transcoded/{}/{}.mkv'.format(transcode_id, media.id)
    return render_template('play.html',
                           media=media,
                           watchinfo=watchinfo,
                           transcodes=transcodes,
                           transcode_id=transcode_id,
                           src=src)
Пример #12
0
def series_details(series_id):
    user = auth.get_logged_in_user()
    series = Series.get(Series.id == series_id)
    seasons = Season.select().where(Season.series == series)
    episodes = list(Media.select().where(Media.series == series).order_by(
        -Media.season, -Media.episode))
    season_episodes = {}
    for episode in episodes:
        if episode.season not in season_episodes.keys():
            season_episodes[episode.season] = {}
        season_episodes[episode.season][episode.episode] = episode
    actors = SeriesActor.select().join(Actor).where(
        SeriesActor.series == series)
    return render_template('series-details.html',
                           series=series,
                           season_episodes=season_episodes,
                           actors=actors,
                           seasons=seasons)
Пример #13
0
def start_series(series_id):
    user = auth.get_logged_in_user()
    series = Series.get(Series.id == series_id)
    series_media = Media.select().where(Media.series == series)
    for episode in series_media:
        WatchInfo.create(user=user, media=episode)

    try:
        watchinfo = SeriesWatchInfo.get(SeriesWatchInfo.series == series,
                                        SeriesWatchInfo.user == user)
    except:
        watchinfo = SeriesWatchInfo.create(series=series,
                                           user=user,
                                           visible=True,
                                           permissions=False,
                                           following=False)
    watchinfo.following = True
    watchinfo.save()

    return redirect(url_for('homepage'))