mirror of
				https://github.com/janeczku/calibre-web
				synced 2025-10-31 15:23:02 +00:00 
			
		
		
		
	Update opds feed with letters for all titles, authors, categories and series
This commit is contained in:
		
							
								
								
									
										98
									
								
								cps/opds.py
									
									
									
									
									
								
							
							
						
						
									
										98
									
								
								cps/opds.py
									
									
									
									
									
								
							| @@ -99,10 +99,35 @@ def feed_normal_search(): | |||||||
|  |  | ||||||
| @opds.route("/opds/books") | @opds.route("/opds/books") | ||||||
| @requires_basic_auth_if_no_ano | @requires_basic_auth_if_no_ano | ||||||
| def feed_books(): | def feed_booksindex(): | ||||||
|     off = request.args.get("offset") or 0 |     off = request.args.get("offset") or 0 | ||||||
|  |     entries = calibre_db.session.query(func.upper(func.substr(db.Books.sort, 1, 1)).label('id'))\ | ||||||
|  |         .filter(calibre_db.common_filters()).group_by(func.upper(func.substr(db.Books.sort, 1, 1))).all() | ||||||
|  |  | ||||||
|  |     elements = [] | ||||||
|  |     if off == 0: | ||||||
|  |         elements.append({'id': "00", 'name':_("All")}) | ||||||
|  |     for entry in entries: | ||||||
|  |         elements.append({'id': entry.id, 'name': entry.id}) | ||||||
|  |  | ||||||
|  |     pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, | ||||||
|  |                             len(elements)) | ||||||
|  |     return render_xml_template('feed.xml', | ||||||
|  |                                letterelements=elements, | ||||||
|  |                                folder='opds.feed_letter_books', | ||||||
|  |                                pagination=pagination) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @opds.route("/opds/books/letter/<book_id>") | ||||||
|  | @requires_basic_auth_if_no_ano | ||||||
|  | def feed_letter_books(book_id): | ||||||
|  |     off = request.args.get("offset") or 0 | ||||||
|  |     letter = true() if book_id == "00" else func.upper(db.Books.sort).startswith(book_id) | ||||||
|     entries, __, pagination = calibre_db.fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1), 0, |     entries, __, pagination = calibre_db.fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1), 0, | ||||||
|                                                         db.Books, True, [db.Books.sort]) |                                                         db.Books, | ||||||
|  |                                                         letter, | ||||||
|  |                                                         [db.Books.sort]) | ||||||
|  |  | ||||||
|     return render_xml_template('feed.xml', entries=entries, pagination=pagination) |     return render_xml_template('feed.xml', entries=entries, pagination=pagination) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -160,22 +185,29 @@ def feed_hot(): | |||||||
| @requires_basic_auth_if_no_ano | @requires_basic_auth_if_no_ano | ||||||
| def feed_authorindex(): | def feed_authorindex(): | ||||||
|     off = request.args.get("offset") or 0 |     off = request.args.get("offset") or 0 | ||||||
|     entries = calibre_db.session.query(func.upper(func.substr(db.Authors.sort, 1, 1)).label('id'), |     entries = calibre_db.session.query(func.upper(func.substr(db.Authors.sort, 1, 1)).label('id'))\ | ||||||
|                                        func.upper(func.substr(db.Authors.sort, 1, 1)).label('name')) \ |         .join(db.books_authors_link).join(db.Books).filter(calibre_db.common_filters())\ | ||||||
|         .join(db.books_authors_link).join(db.Books).filter(calibre_db.common_filters()) \ |  | ||||||
|         .group_by(func.upper(func.substr(db.Authors.sort, 1, 1))).all() |         .group_by(func.upper(func.substr(db.Authors.sort, 1, 1))).all() | ||||||
|  |  | ||||||
|     # ToDo: Add All to list -> All: id = 0 |     elements = [] | ||||||
|  |     if off == 0: | ||||||
|  |         elements.append({'id': "00", 'name':_("All")}) | ||||||
|  |     for entry in entries: | ||||||
|  |         elements.append({'id': entry.id, 'name': entry.id}) | ||||||
|  |  | ||||||
|     pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, |     pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, | ||||||
|                             len(entries)) |                             len(elements)) | ||||||
|     return render_xml_template('feed.xml', listelements=entries, folder='opds.feed_letter_author', pagination=pagination) |     return render_xml_template('feed.xml', | ||||||
|  |                                letterelements=elements, | ||||||
|  |                                folder='opds.feed_letter_author', | ||||||
|  |                                pagination=pagination) | ||||||
|  |  | ||||||
|  |  | ||||||
| @opds.route("/opds/author/letter/<book_id>") | @opds.route("/opds/author/letter/<book_id>") | ||||||
| @requires_basic_auth_if_no_ano | @requires_basic_auth_if_no_ano | ||||||
| def feed_letter_author(book_id): | def feed_letter_author(book_id): | ||||||
|     off = request.args.get("offset") or 0 |     off = request.args.get("offset") or 0 | ||||||
|     letter = true() if book_id == "0" else func.upper(db.Authors.sort).startswith(book_id) |     letter = true() if book_id == "00" else func.upper(db.Authors.sort).startswith(book_id) | ||||||
|     entries = calibre_db.session.query(db.Authors).join(db.books_authors_link).join(db.Books)\ |     entries = calibre_db.session.query(db.Authors).join(db.books_authors_link).join(db.Books)\ | ||||||
|         .filter(calibre_db.common_filters()).filter(letter)\ |         .filter(calibre_db.common_filters()).filter(letter)\ | ||||||
|         .group_by(text('books_authors_link.author'))\ |         .group_by(text('books_authors_link.author'))\ | ||||||
| @@ -227,10 +259,31 @@ def feed_publisher(book_id): | |||||||
| @requires_basic_auth_if_no_ano | @requires_basic_auth_if_no_ano | ||||||
| def feed_categoryindex(): | def feed_categoryindex(): | ||||||
|     off = request.args.get("offset") or 0 |     off = request.args.get("offset") or 0 | ||||||
|  |     entries = calibre_db.session.query(func.upper(func.substr(db.Tags.name, 1, 1)).label('id'))\ | ||||||
|  |         .join(db.books_tags_link).join(db.Books).filter(calibre_db.common_filters())\ | ||||||
|  |         .group_by(func.upper(func.substr(db.Tags.name, 1, 1))).all() | ||||||
|  |     elements = [] | ||||||
|  |     if off == 0: | ||||||
|  |         elements.append({'id': "00", 'name':_("All")}) | ||||||
|  |     for entry in entries: | ||||||
|  |         elements.append({'id': entry.id, 'name': entry.id}) | ||||||
|  |  | ||||||
|  |     pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, | ||||||
|  |                             len(elements)) | ||||||
|  |     return render_xml_template('feed.xml', | ||||||
|  |                                letterelements=elements, | ||||||
|  |                                folder='opds.feed_letter_category', | ||||||
|  |                                pagination=pagination) | ||||||
|  |  | ||||||
|  | @opds.route("/opds/category/letter/<book_id>") | ||||||
|  | @requires_basic_auth_if_no_ano | ||||||
|  | def feed_letter_category(book_id): | ||||||
|  |     off = request.args.get("offset") or 0 | ||||||
|  |     letter = true() if book_id == "00" else func.upper(db.Tags.name).startswith(book_id) | ||||||
|     entries = calibre_db.session.query(db.Tags)\ |     entries = calibre_db.session.query(db.Tags)\ | ||||||
|         .join(db.books_tags_link)\ |         .join(db.books_tags_link)\ | ||||||
|         .join(db.Books)\ |         .join(db.Books)\ | ||||||
|         .filter(calibre_db.common_filters())\ |         .filter(calibre_db.common_filters()).filter(letter)\ | ||||||
|         .group_by(text('books_tags_link.tag'))\ |         .group_by(text('books_tags_link.tag'))\ | ||||||
|         .order_by(db.Tags.name)\ |         .order_by(db.Tags.name)\ | ||||||
|         .offset(off)\ |         .offset(off)\ | ||||||
| @@ -255,10 +308,31 @@ def feed_category(book_id): | |||||||
| @requires_basic_auth_if_no_ano | @requires_basic_auth_if_no_ano | ||||||
| def feed_seriesindex(): | def feed_seriesindex(): | ||||||
|     off = request.args.get("offset") or 0 |     off = request.args.get("offset") or 0 | ||||||
|  |     entries = calibre_db.session.query(func.upper(func.substr(db.Series.sort, 1, 1)).label('id'))\ | ||||||
|  |         .join(db.books_series_link).join(db.Books).filter(calibre_db.common_filters())\ | ||||||
|  |         .group_by(func.upper(func.substr(db.Series.sort, 1, 1))).all() | ||||||
|  |     elements = [] | ||||||
|  |     if off == 0: | ||||||
|  |         elements.append({'id': "00", 'name':_("All")}) | ||||||
|  |     for entry in entries: | ||||||
|  |         elements.append({'id': entry.id, 'name': entry.id}) | ||||||
|  |  | ||||||
|  |     pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, | ||||||
|  |                             len(elements)) | ||||||
|  |     return render_xml_template('feed.xml', | ||||||
|  |                                letterelements=elements, | ||||||
|  |                                folder='opds.feed_letter_series', | ||||||
|  |                                pagination=pagination) | ||||||
|  |  | ||||||
|  | @opds.route("/opds/series/letter/<book_id>") | ||||||
|  | @requires_basic_auth_if_no_ano | ||||||
|  | def feed_letter_series(book_id): | ||||||
|  |     off = request.args.get("offset") or 0 | ||||||
|  |     letter = true() if book_id == "00" else func.upper(db.Series.sort).startswith(book_id) | ||||||
|     entries = calibre_db.session.query(db.Series)\ |     entries = calibre_db.session.query(db.Series)\ | ||||||
|         .join(db.books_series_link)\ |         .join(db.books_series_link)\ | ||||||
|         .join(db.Books)\ |         .join(db.Books)\ | ||||||
|         .filter(calibre_db.common_filters())\ |         .filter(calibre_db.common_filters()).filter(letter)\ | ||||||
|         .group_by(text('books_series_link.series'))\ |         .group_by(text('books_series_link.series'))\ | ||||||
|         .order_by(db.Series.sort)\ |         .order_by(db.Series.sort)\ | ||||||
|         .offset(off).all() |         .offset(off).all() | ||||||
| @@ -294,7 +368,7 @@ def feed_ratingindex(): | |||||||
|                             len(entries)) |                             len(entries)) | ||||||
|     element = list() |     element = list() | ||||||
|     for entry in entries: |     for entry in entries: | ||||||
|         element.append(FeedObject(entry[0].id, "{} Stars".format(entry.name))) |         element.append(FeedObject(entry[0].id, _("{} Stars").format(entry.name))) | ||||||
|     return render_xml_template('feed.xml', listelements=element, folder='opds.feed_ratings', pagination=pagination) |     return render_xml_template('feed.xml', listelements=element, folder='opds.feed_ratings', pagination=pagination) | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -84,4 +84,11 @@ | |||||||
|     <link rel="subsection" type="application/atom+xml;profile=opds-catalog" href="{{url_for(folder, book_id=entry.id)}}"/> |     <link rel="subsection" type="application/atom+xml;profile=opds-catalog" href="{{url_for(folder, book_id=entry.id)}}"/> | ||||||
|   </entry> |   </entry> | ||||||
|   {% endfor %} |   {% endfor %} | ||||||
|  |   {% for entry in letterelements %} | ||||||
|  |   <entry> | ||||||
|  |     <title>{{entry['name']}}</title> | ||||||
|  |     <id>{{ url_for(folder, book_id=entry['id']) }}</id> | ||||||
|  |     <link rel="subsection" type="application/atom+xml;profile=opds-catalog" href="{{url_for(folder, book_id=entry['id'])}}"/> | ||||||
|  |   </entry> | ||||||
|  |   {% endfor %} | ||||||
| </feed> | </feed> | ||||||
|   | |||||||
| @@ -16,8 +16,8 @@ | |||||||
|   </author> |   </author> | ||||||
|   <entry> |   <entry> | ||||||
|     <title>{{_('Alphabetical Books')}}</title> |     <title>{{_('Alphabetical Books')}}</title> | ||||||
|     <link href="{{url_for('opds.feed_books')}}" type="application/atom+xml;profile=opds-catalog"/> |     <link href="{{url_for('opds.feed_booksindex')}}" type="application/atom+xml;profile=opds-catalog"/> | ||||||
|     <id>{{url_for('opds.feed_books')}}</id> |     <id>{{url_for('opds.feed_booksindex')}}</id> | ||||||
|     <updated>{{ current_time }}</updated> |     <updated>{{ current_time }}</updated> | ||||||
|     <content type="text">{{_('Books sorted alphabetically')}}</content> |     <content type="text">{{_('Books sorted alphabetically')}}</content> | ||||||
|   </entry> |   </entry> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ozzie Isaacs
					Ozzie Isaacs