Merge lp:~dreamdevel/eradio/asxdecoder into lp:eradio/luna

Proposed by Fotini Skoti
Status: Merged
Merged at revision: 61
Proposed branch: lp:~dreamdevel/eradio/asxdecoder
Merge into: lp:eradio/luna
Diff against target: 165 lines (+112/-2)
4 files modified
CMakeLists.txt (+2/-0)
debian/control (+2/-1)
src/asx_decoder.vala (+95/-0)
src/stream_player.vala (+13/-1)
To merge this branch: bzr merge lp:~dreamdevel/eradio/asxdecoder
Reviewer Review Type Date Requested Status
George Sofianos Approve
Review via email: mp+225216@code.launchpad.net

Description of the change

Added asx type support

To post a comment you must log in.
lp:~dreamdevel/eradio/asxdecoder updated
62. By George Sofianos

Fixed indentation in asx decoder filen

Revision history for this message
George Sofianos (georgesofianosgr) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-06-30 16:17:26 +0000
3+++ CMakeLists.txt 2014-07-02 06:32:57 +0000
4@@ -35,6 +35,7 @@
5 libnotify
6 json-glib-1.0
7 libsoup-2.4
8+ libxml-2.0
9 )
10
11 pkg_check_modules(DEPS REQUIRED ${PROJECT_DEPS})
12@@ -70,6 +71,7 @@
13 src/m3u_decoder.vala
14 src/progress_dialog.vala
15 src/pls_decoder.vala
16+ src/asx_decoder.vala
17 PACKAGES
18 ${PROJECT_DEPS}
19 )
20
21=== modified file 'debian/control'
22--- debian/control 2014-07-01 07:05:22 +0000
23+++ debian/control 2014-07-02 06:32:57 +0000
24@@ -12,7 +12,8 @@
25 libgee-dev,
26 libnotify-dev,
27 libjson-glib-dev,
28- libsoup2.4-dev
29+ libsoup2.4-dev,
30+ libxml2-dev
31 Standards-Version: 3.9.3
32
33 Package: eradio
34
35=== added file 'src/asx_decoder.vala'
36--- src/asx_decoder.vala 1970-01-01 00:00:00 +0000
37+++ src/asx_decoder.vala 2014-07-02 06:32:57 +0000
38@@ -0,0 +1,95 @@
39+/*-
40+ * Copyright (c) 2014 Dream Dev Developers (https://launchpad.net/~dreamdev)
41+ *
42+ * This program is free software: you can redistribute it and/or modify
43+ * it under the terms of the GNU General Public License as published by
44+ * the Free Software Foundation, either version 3 of the License, or
45+ * (at your option) any later version.
46+ *
47+ * This program is distributed in the hope that it will be useful,
48+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
49+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50+ * GNU General Public License for more details.
51+ *
52+ * You should have received a copy of the GNU General Public License
53+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
54+ *
55+ * Authored by: Fotini Skoti <fotini.skoti@gmail.com>
56+ *
57+ */
58+
59+ public class ASXDecoder {
60+
61+ public static Gee.ArrayList<string>? parse (string url) {
62+
63+ //download file to string
64+ string file = get_file (url);
65+ if (file == null) {
66+ stderr.printf ("Failed to download file");
67+ return null;
68+ }
69+
70+ //lower case string
71+ file = file.down();
72+
73+ unowned Xml.Doc doc = Xml.Parser.parse_doc (file);
74+ if (doc == null) {
75+ stderr.printf ("Unable to open file\n");
76+ return null;
77+ }
78+
79+ unowned Xml.Node root = doc.get_root_element ();
80+ if (root == null) {
81+ stdout.printf ("Wanted root\n");
82+ return null;
83+ }
84+
85+ var hrefs_list = new Gee.ArrayList<string> ();
86+
87+ if (root.name == "asx") {
88+ for (unowned Xml.Node iter = root.children; iter != null; iter = iter.next) {
89+ if (iter.type == Xml.ElementType.ELEMENT_NODE && iter.name == "entry") {
90+ var parsed_hrefs = get_hrefs (iter);
91+ foreach (string href in parsed_hrefs)
92+ hrefs_list.add(href);
93+ }
94+ }
95+ }
96+
97+ if (hrefs_list.size == 0)
98+ return null;
99+
100+ return hrefs_list;
101+ }
102+
103+ private static Gee.ArrayList<string>? get_hrefs (Xml.Node node) {
104+
105+ var hrefs = new Gee.ArrayList<string> ();
106+
107+ for (unowned Xml.Node iter = node.children; iter != null; iter = iter.next) {
108+ if (iter.type == Xml.ElementType.ELEMENT_NODE && iter.name == "ref") {
109+ hrefs.add (iter.get_prop ("href"));
110+ }
111+ }
112+
113+ if (hrefs == null)
114+ return null;
115+
116+ return hrefs;
117+ }
118+
119+ private static string? get_file (string url) {
120+
121+ Soup.SessionSync session = new Soup.SessionSync ();
122+ Soup.Message msg = new Soup.Message ("GET", url);
123+
124+ session.send_message (msg);
125+
126+ var data = (string) msg.response_body.data;
127+
128+ if (msg.status_code == 200)
129+ return data;
130+ else
131+ return null;
132+ }
133+}
134\ No newline at end of file
135
136=== modified file 'src/stream_player.vala'
137--- src/stream_player.vala 2014-06-30 14:32:25 +0000
138+++ src/stream_player.vala 2014-07-02 06:32:57 +0000
139@@ -66,7 +66,11 @@
140 public void add (string uri) throws Radio.Error{
141
142 string final_uri = uri;
143- var content_type = this.get_content_type (uri);
144+ string content_type = "";
145+
146+ if (final_uri.index_of("http") == 0){
147+ content_type = this.get_content_type (uri);
148+ }
149
150 // Check content type to decode
151 if ( content_type == "audio/x-mpegurl" || content_type == "audio/mpegurl" ) {
152@@ -86,6 +90,14 @@
153 throw new Radio.Error.GENERAL ("Could not decode pls file, wrong url or corrupted file");
154
155 }
156+ else if ( content_type == "video/x-ms-wmv" || content_type == "video/x-ms-wvx" || content_type == "video/x-ms-asf" || content_type == "video/x-ms-asx" || content_type == "audio/x-ms-wax" || uri.last_index_of (".asx",uri.length - 4) != -1) {
157+ var list = ASXDecoder.parse (uri);
158+ // Temporary ignoring all links beside the first
159+ if ( list != null )
160+ final_uri = list[0];
161+ else
162+ throw new Radio.Error.GENERAL ("Could not decode asx file, wrong url or corrupted file");
163+ }
164
165 this.has_url = true;
166

Subscribers

People subscribed via source and target branches