File: mx-info

package info (click to toggle)
rygel 45.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,732 kB
  • sloc: xml: 1,756; ansic: 1,081; python: 226; sh: 64; makefile: 24
file content (148 lines) | stat: -rwxr-xr-x 5,514 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3

# This file is part of Rygel.
# Copyright (C) 2015 Jens Georg <mail@jensge.org>

# Rygel is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# Rygel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import sqlite3
import os.path
import time
from xdg import BaseDirectory
import sys
from urllib.request import pathname2url
import argparse

FILE_QUERY = """
SELECT o.upnp_id, o.type_fk, o.timestamp, null,
       m.size, m.mime_type, m.dlna_profile, m.duration, m.width, m.height,
       m.class, m.author, m.album, m.genre, m.date, m.bitrate, m.sample_freq,
       m.bits_per_sample, m.channels, m.track, m.color_depth, m.disc, o.title
FROM Object o JOIN Meta_Data m on o.upnp_id = m.object_fk
WHERE o.uri = :uri
"""

INFO_TEMPLATE = """Information about %(uri)s:
    Id: %(id)s
    Last Modified: %(mtime)u
    Size: %(size)d
    Content-Type: %(mime)s
    DLNA Profile: %(dlna_profile)s
    UPnP Class: %(class)s

Media information:
    Title: %(title)s
    Duration: %(duration)d
    Author: %(author)s
    Album: %(album)s
    Genre: %(genre)s
    Created: %(date)s
    Track: %(track)d
    Disc: %(disc)d

Technical information:
    Width: %(width)d
    Height: %(height)d
    Bitrate: %(bitrate)d
    Sample Freq: %(sample_freq)d
    Bits/Sample: %(bits)d
    Channels: %(channels)d
    Color depths: %(depth)d
"""
IGNORELIST_QUERY = """
SELECT b.timestamp FROM ignorelist b WHERE b.uri = :uri
"""

IGNORELIST_TEMPLATE = 'File %(uri)s was ignored on %(date)s'
SHOW_IGNORELIST_QUERY = 'SELECT timestamp, uri FROM ignorelist'
UNIGNORELIST_QUERY = 'DELETE FROM ignorelist where uri = :uri'

def ensure_uri(string):
    if not string.startswith ('file://'):
        return 'file://' + pathname2url (string)
    return string

parser = argparse.ArgumentParser (description = "MediaExport database tool")
parser.add_argument ('uris', metavar='URI', nargs = '+', type = ensure_uri,
                     help = 'URIs to dump infos for')
parser.add_argument ('-u, --unignore', action = 'store_true',
                     dest = 'unignore',
                     help = 'Remove uris from database\'s ignorelist')
parser.add_argument ('--show-ignorelist', action = 'store_true',
                     dest = 'show_ignorelist',
                     help = 'Show contents of the ignorelist')
args = parser.parse_args ()

rygel_db = os.path.join (BaseDirectory.xdg_cache_home, "rygel", "media-export.db")
conn = sqlite3.connect (rygel_db)

c = conn.cursor ()
c.execute ("SELECT version FROM schema_info")
info = c.fetchone()
if int(info[0]) < 16:
    print("Unsupported schema version or not a Rygel cache")
    sys.exit (1)

has_ignorelist = int(info[0]) >= 18

if not has_ignorelist and (args.unignore or args.show_ignorelist):
    print ('Database version is too old for ignorelists, cannot unignorelist')
    sys.exit (1)

if has_ignorelist and args.show_ignorelist:
    c.execute (SHOW_IGNORELIST_QUERY)
    for row in c:
        t = time.gmtime(row[0])
        print (IGNORELIST_TEMPLATE % { "uri" : row[1],
                                      "date" : time.strftime("%a, %d %b %Y %H:%M:%S +0000", t)})
    sys.exit(0)

if has_ignorelist and args.unignore:
    for uri in args.uris:
        c.execute (UNIGNORELIST_QUERY, { 'uri' : uri })
    conn.commit()
else:
    for uri in args.uris:
        c.execute (FILE_QUERY, {"uri": uri})
        for row in c:
            print (INFO_TEMPLATE % { "uri": uri,
                                     "id" : row[0],
                                     "mtime" : row[2],
                                     "size" : row[4],
                                     "mime" : row[5],
                                     "dlna_profile" : row[6],
                                     "class" : row[10],
                                     "duration" : row[7],
                                     "author" : row[11],
                                     "album" : row[12],
                                     "genre" : row[13],
                                     "date" : row[14],
                                     "track" : row[19],
                                     "width" : row[8],
                                     "height" : row[9],
                                     "bitrate" : row[15],
                                     "sample_freq" : row[16],
                                     "bits" : row[17],
                                     "channels" : row[18],
                                     "depth" : row[20],
                                     "disc" : row[21],
                                     "title": row[22]})

        if has_ignorelist:
            c.execute (IGNORELIST_QUERY, {"uri": uri})
            for row in c:
                t = time.gmtime(row[0])
                print (IGNORELIST_TEMPLATE % { "uri" : uri,
                                          "date" : time.strftime("%a, %d %b %Y %H:%M:%S +0000", t)})