Skip to content

Commit

Permalink
Merge pull request #728 from Difegue/dev
Browse files Browse the repository at this point in the history
Fix OPDS (for good this time)
  • Loading branch information
Difegue committed Dec 23, 2022
2 parents 322fed4 + 4ab60eb commit 21fa4f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
18 changes: 11 additions & 7 deletions lib/LANraragi/Model/Opds.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use utf8;

use Redis;
use POSIX qw(strftime);
use Mojo::Util qw(xml_escape);

use LANraragi::Utils::Generic qw(get_tag_with_namespace);
Expand Down Expand Up @@ -57,7 +58,7 @@ sub generate_opds_catalog {
motd => $mojo->LRR_CONF->get_motd,
version => $mojo->LRR_VERSION,
api_key_query => $api_key ? "?key=" . $api_key : "",
api_key_and => $api_key ? "&key=" . $api_key : ""
api_key_and => $api_key ? "&key=" . $api_key : ""
);
}

Expand All @@ -78,7 +79,7 @@ sub generate_opds_item {
motd => $mojo->LRR_CONF->get_motd,
version => $mojo->LRR_VERSION,
api_key_query => $api_key ? "?key=" . $api_key : "",
api_key_and => $api_key ? "&key=" . $api_key : ""
api_key_and => $api_key ? "&key=" . $api_key : ""
);
}

Expand All @@ -95,12 +96,15 @@ sub get_opds_data {

my $tags = $arcdata->{tags};

# Parse date from the date_added tag, and convert from unix time to ISO 8601.
my $date = get_tag_with_namespace( "date_added", $tags, "0" );
$arcdata->{dateadded} = strftime( "%Y-%m-%dT%H:%M:%SZ", gmtime($date) );

# Infer a few OPDS-related fields from the tags
$arcdata->{dateadded} = get_tag_with_namespace( "date_added", $tags, "2010-01-10T10:01:11Z" );
$arcdata->{author} = get_tag_with_namespace( "artist", $tags, "" );
$arcdata->{language} = get_tag_with_namespace( "language", $tags, "" );
$arcdata->{circle} = get_tag_with_namespace( "group", $tags, "" );
$arcdata->{event} = get_tag_with_namespace( "event", $tags, "" );
$arcdata->{author} = get_tag_with_namespace( "artist", $tags, "" );
$arcdata->{language} = get_tag_with_namespace( "language", $tags, "" );
$arcdata->{circle} = get_tag_with_namespace( "group", $tags, "" );
$arcdata->{event} = get_tag_with_namespace( "event", $tags, "" );

# Application/zip is universally hated by all readers so it's better to use x-cbz and x-cbr here.
if ( $file =~ /^(.*\/)*.+\.(pdf)$/ ) {
Expand Down
24 changes: 12 additions & 12 deletions tests/samples/opds/opds_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
<entry>
<title>Fate GO MEMO</title>
<id>urn:lrr:28697b96f0ac5858be2614ed10ca47742c9522fd</id>
<updated>2010-01-10T10:01:11Z</updated>
<published>2010-01-10T10:01:11Z</published>
<updated>1970-01-01T00:00:00Z</updated>
<published>1970-01-01T00:00:00Z</published>
<author>
<name>wada rco</name>
</author>
Expand Down Expand Up @@ -73,8 +73,8 @@
<entry>
<title>Fate GO MEMO 2</title>
<id>urn:lrr:2810d5e0a8d027ecefebca6237031a0fa7b91eb3</id>
<updated>2010-01-10T10:01:11Z</updated>
<published>2010-01-10T10:01:11Z</published>
<updated>1970-01-01T00:00:00Z</updated>
<published>1970-01-01T00:00:00Z</published>
<author>
<name>wada rco</name>
</author>
Expand Down Expand Up @@ -103,8 +103,8 @@
<entry>
<title>Ghost in the Shell 1.5 - Human-Error Processor vol01ch01</title>
<id>urn:lrr:4857fd2e7c00db8b0af0337b94055d8445118630</id>
<updated>2010-01-10T10:01:11Z</updated>
<published>2010-01-10T10:01:11Z</published>
<updated>1970-01-01T00:00:00Z</updated>
<published>1970-01-01T00:00:00Z</published>
<author>
<name>shirow masamune</name>
</author>
Expand Down Expand Up @@ -133,8 +133,8 @@
<entry>
<title>Rohan Kishibe goes to Gucci</title>
<id>urn:lrr:e4c422fd10943dc169e3489a38cdbf57101a5f7e</id>
<updated>2010-01-10T10:01:11Z</updated>
<published>2010-01-10T10:01:11Z</published>
<updated>1970-01-01T00:00:00Z</updated>
<published>1970-01-01T00:00:00Z</published>
<author>
<name></name>
</author>
Expand Down Expand Up @@ -163,8 +163,8 @@
<entry>
<title>Saturn Backup Cartridge - American Manual</title>
<id>urn:lrr:e69e43e1355267f7d32a4f9b7f2fe108d2401ebg</id>
<updated>2010-01-10T10:01:11Z</updated>
<published>2010-01-10T10:01:11Z</published>
<updated>1970-01-01T00:00:00Z</updated>
<published>1970-01-01T00:00:00Z</published>
<author>
<name></name>
</author>
Expand Down Expand Up @@ -193,8 +193,8 @@
<entry>
<title>Saturn Backup Cartridge - Japanese Manual</title>
<id>urn:lrr:e69e43e1355267f7d32a4f9b7f2fe108d2401ebf</id>
<updated>2010-01-10T10:01:11Z</updated>
<published>2010-01-10T10:01:11Z</published>
<updated>1970-01-01T00:00:00Z</updated>
<published>1970-01-01T00:00:00Z</published>
<author>
<name></name>
</author>
Expand Down

0 comments on commit 21fa4f4

Please sign in to comment.