Browse Source

add sorting options to movie_listing

master
cinnaboot 7 years ago
parent
commit
0e54a68e08
  1. 35
      video_metadata/schema.sql
  2. 17
      video_metadata/static/style.css
  3. 10
      video_metadata/templates/tmdb/list_movie_test.html
  4. 30
      video_metadata/views/tmdb.py

35
video_metadata/schema.sql

@ -1,21 +1,4 @@
DROP TABLE IF EXISTS movie_queries;
CREATE TABLE movie_queries(
query_id integer primary key autoincrement,
query text,
year integer
);
DROP TABLE IF EXISTS movie_details;
CREATE TABLE movie_details(
movie_id primary key not null,
title text,
overview text,
release_date date,
original_language text,
poster_path text
);
DROP TABLE IF EXISTS movie_query_mapping; DROP TABLE IF EXISTS movie_query_mapping;
CREATE TABLE movie_query_mapping( CREATE TABLE movie_query_mapping(
query_id int, query_id int,
@ -28,6 +11,7 @@ DROP TABLE IF EXISTS movie_paths;
CREATE TABLE movie_paths( CREATE TABLE movie_paths(
movie_id int not null, movie_id int not null,
movie_path text unique not null, movie_path text unique not null,
add_date date, -- NOTE: date the path was mapped
foreign key(movie_id) references movie_details(movie_id) foreign key(movie_id) references movie_details(movie_id)
); );
@ -45,6 +29,23 @@ CREATE TABLE movie_genre_mapping(
foreign key(movie_id) references movie_details(movie_id) foreign key(movie_id) references movie_details(movie_id)
); );
DROP TABLE IF EXISTS movie_queries;
CREATE TABLE movie_queries(
query_id integer primary key autoincrement,
query text,
year integer
);
DROP TABLE IF EXISTS movie_details;
CREATE TABLE movie_details(
movie_id primary key not null,
title text,
overview text,
release_date date,
original_language text,
poster_path text
);
DROP TABLE IF EXISTS actor_details; DROP TABLE IF EXISTS actor_details;
CREATE TABLE actor_details( CREATE TABLE actor_details(
actor_id integer primary key not null, actor_id integer primary key not null,

17
video_metadata/static/style.css

@ -18,10 +18,6 @@ nav ul li a, nav ul li span, header .action { display: block; padding: 0.5rem; }
input { color: #333; background-color: #eee; } input { color: #333; background-color: #eee; }
input.danger { color: #cc2f2e; } input.danger { color: #cc2f2e; }
.debug { background: lightgrey; padding: 1em; overflow: auto; border: 1px solid darkgrey } .debug { background: lightgrey; padding: 1em; overflow: auto; border: 1px solid darkgrey }
.search_result { overflow: auto; max-height: 100px; max-width: 300px; margin-bottom: 1em; padding: 0.5em 1em; background: lightblue; border: 1px solid blue }
.search_result h3, .search_result ul { border: 0; padding: 0; margin: 0 }
.search_result ul { font-size: 0.75em }
.arrow_submit { width: 3em; font-weight: bold; }
.content li { list-style: ' - '; } .content li { list-style: ' - '; }
.folder { background: lightblue; } .folder { background: lightblue; }
.file { background: orange; } .file { background: orange; }
@ -39,3 +35,16 @@ input.danger { color: #cc2f2e; }
.query_description { border: 0; padding: 0; margin: 0; } .query_description { border: 0; padding: 0; margin: 0; }
#query_close { float: right; } #query_close { float: right; }
.search_result {
overflow: auto;
max-height: 100px; max-width: 300px;
border: 1px solid blue;
margin-bottom: 1em; padding: 0.5em 1em;
background: lightblue;
}
.search_result h3, .search_result ul { border: 0; padding: 0; margin: 0 }
.search_result ul { font-size: 0.75em }
.play_link { float: right; }
.test li { list-style: none; display: inline; padding-left: 0.5em; }

10
video_metadata/templates/tmdb/list_movie_test.html

@ -2,15 +2,23 @@
{% block header %} {% block header %}
<h1>{% block title %}movie list test{% endblock %}</h1> <h1>{% block title %}movie list test{% endblock %}</h1>
<ul class="test">
<li>Order By: </li>
<li><a href="{{ url_for('tmdb.list_movie_test') }}/title">title</a></li>
<li><a href="{{ url_for('tmdb.list_movie_test') }}/add-date">add-date</a></li>
<li><a href="{{ url_for('tmdb.list_movie_test') }}/add-date-desc">add-date-desc</a></li>
<li><a href="{{ url_for('tmdb.list_movie_test') }}/release-date">release-date</a></li>
<li><a href="{{ url_for('tmdb.list_movie_test') }}/release-date-desc">release-date-desc</a></li>
</ul>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div id="search_results"> <div id="search_results">
{% for r in view_results %} {% for r in view_results %}
<div class="search_result"> <div class="search_result">
<a class="play_link" href="{{ url_prefix }}{{ r.rel_path|urlencode }}">play</a>
<h3><a href="{{ r.tmdb_link }}">{{ r.title }}</a></h3> <h3><a href="{{ r.tmdb_link }}">{{ r.title }}</a></h3>
<ul> <ul>
<li><a href="{{ url_prefix }}{{ r.rel_path|urlencode }}">test link</a></li>
<li>Release Date: {{ r.release_date }}</li> <li>Release Date: {{ r.release_date }}</li>
<li>Description: <li>Description:
<p>{{ r.overview }}</p> <p>{{ r.overview }}</p>

30
video_metadata/views/tmdb.py

@ -98,17 +98,30 @@ class result_encoder(json.JSONEncoder):
# flask routes # flask routes
@bp.route('/list_movie_test') @bp.route('/list_movie_test')
def list_movie_test(): @bp.route('/list_movie_test/<string:sorting>')
def list_movie_test(sorting = 'title'):
if sorting == 'add-date':
orderby = 'mp.add_date'
elif sorting == 'add-date-desc':
orderby = 'mp.add_date DESC'
elif sorting == 'release-date':
orderby = 'md.release_date'
elif sorting == 'release-date-desc':
orderby = 'md.release_date DESC'
else:
orderby = 'md.title'
# TODO: order by genres, unwatched folder...
conn = db.get_db() conn = db.get_db()
cur = conn.cursor() cur = conn.cursor()
view_results = [] view_results = []
query = '''SELECT query = f'''SELECT
movie_details.*, movie_paths.movie_path md.*, mp.movie_path
FROM FROM
movie_details movie_details md
JOIN movie_paths ON movie_paths.movie_id=movie_details.movie_id JOIN movie_paths mp ON mp.movie_id=md.movie_id
ORDER BY ORDER BY
movie_details.title''' {orderby}'''
# TODO: should probably loop on movie_id, and add a list of movie_paths because # TODO: should probably loop on movie_id, and add a list of movie_paths because
# there can be multiple paths associated with a movie_id # there can be multiple paths associated with a movie_id
@ -190,7 +203,7 @@ def create_mapping():
cur = conn.cursor() cur = conn.cursor()
current_app.logger.debug(f'{util.getFunctionName()}, mapping path "{rel_path}" for id: {movie_id}') current_app.logger.debug(f'{util.getFunctionName()}, mapping path "{rel_path}" for id: {movie_id}')
try: try:
cur.execute('INSERT INTO movie_paths(movie_id, movie_path) VALUES(?, ?)', cur.execute('INSERT INTO movie_paths(movie_id, movie_path, add_date) VALUES(?, ?, datetime())',
(movie_id, rel_path )) (movie_id, rel_path ))
except DatabaseError as e: except DatabaseError as e:
errors.append(str(e)) errors.append(str(e))
@ -209,7 +222,7 @@ def create_mapping():
################### ###################
# helpers # helpers
def doQueryAlgorithm(query:query_data) -> list: def doQueryAlgorithm(query:query_data) -> dict:
errors, view_results = [], [] errors, view_results = [], []
response = response_data() response = response_data()
@ -400,7 +413,6 @@ def storeTMDBQueryResults(query_obj, result_list):
current_app.logger.debug(f'{util.getFunctionName()}, adding query string ' current_app.logger.debug(f'{util.getFunctionName()}, adding query string '
f'"{query_obj.parsed_query_str}" into local cache') f'"{query_obj.parsed_query_str}" into local cache')
#current_app.logger.debug(f'{util.getFunctionName()}, result_list:\n{result_list} ')
try: try:
cur.execute('BEGIN TRANSACTION') cur.execute('BEGIN TRANSACTION')

Loading…
Cancel
Save