1 /*
2  *
3  *   Copyright (C) 2015-2018 by C.H. Huang
4  *   plushuang.tw@gmail.com
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2.1 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  *  ---
21  *
22  *  In addition, as a special exception, the copyright holders give
23  *  permission to link the code of portions of this program with the
24  *  OpenSSL library under certain conditions as described in each
25  *  individual source file, and distribute linked combinations
26  *  including the two.
27  *  You must obey the GNU Lesser General Public License in all respects
28  *  for all of the code used other than OpenSSL.  If you modify
29  *  file(s) with this exception, you may extend this exception to your
30  *  version of the file(s), but you are not obligated to do so.  If you
31  *  do not wish to do so, delete this exception statement from your
32  *  version.  If you delete this exception statement from all source
33  *  files in the program, then also delete it here.
34  *
35  */
36 
37 // YouTube support
38 #ifndef UGET_MEDIA_H
39 #define UGET_MEDIA_H
40 
41 #include <UgList.h>
42 #include <UgetData.h>
43 #include <UgetSite.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 typedef struct UgetMedia         UgetMedia;
50 typedef struct UgetMediaItem     UgetMediaItem;
51 
52 typedef enum UgetMediaMatchMode
53 {
54 	UGET_MEDIA_MATCH_0 = 0,
55 	UGET_MEDIA_MATCH_1 = 1,
56 	UGET_MEDIA_MATCH_2,
57 	UGET_MEDIA_MATCH_NEAR,   // near quality
58 
59 	UGET_MEDIA_N_MATCH_MODE,
60 } UgetMediaMatchMode;
61 
62 typedef enum UgetMediaQuality
63 {
64 	UGET_MEDIA_QUALITY_UNKNOWN = -1,
65 
66 	UGET_MEDIA_QUALITY_240P,    // YouTube small
67 	UGET_MEDIA_QUALITY_360P,    // YouTube medium
68 	UGET_MEDIA_QUALITY_480P,    // YouTube large
69 	UGET_MEDIA_QUALITY_720P,    // YouTube hd720
70 	UGET_MEDIA_QUALITY_1080P,   // YouTube hd1080
71 
72 	UGET_MEDIA_N_QUALITY,
73 } UgetMediaQuality;
74 
75 typedef enum UgetMediaType
76 {
77 	UGET_MEDIA_TYPE_UNKNOWN = -1,
78 
79 	UGET_MEDIA_TYPE_MP4,
80 	UGET_MEDIA_TYPE_WEBM,
81 	UGET_MEDIA_TYPE_3GPP,
82 	UGET_MEDIA_TYPE_FLV,
83 
84 	// YouTube MIME type:
85 	// audio/mp4;+codecs="mp4a.40.2"
86 	// audio/webm;+codecs="vorbis"
87 	// audio/webm;+codecs="opus"
88 	UGET_MEDIA_AUDIO_MP4,
89 	UGET_MEDIA_AUDIO_WEBM,
90 //	UGET_MEDIA_AUDIO_WEBM_VORBIS,  // YouTube - audio/webm;+codecs="vorbis"
91 //	UGET_MEDIA_AUDIO_WEBM_OPUS,    // YouTube - audio/webm;+codecs="opus"
92 
93 	UGET_MEDIA_N_TYPE,
94 } UgetMediaType;
95 
96 
97 struct UgetMedia
98 {
99 	UG_LIST_MEMBERS(UgetMediaItem);
100 //	uintptr_t        size;
101 //	UgetMediaItem*   head;
102 //	UgetMediaItem*   tail;
103 
104 	UgUri       uuri;
105 	UgUriQuery  uquery;
106 
107 	int    site_id;
108 	char*  url;
109 	char*  title;
110 
111 	// error message
112 	UgetEvent*  event;
113 
114 	// for internal use only
115 	void*  data;
116 	void*  data1;
117 	void*  data2;
118 	void*  data3;
119 	void*  data4;
120 };
121 
122 UgetMedia*  uget_media_new(const char* url, UgetSiteId site_id);
123 void        uget_media_free(UgetMedia* umedia);
124 void        uget_media_clear(UgetMedia* umedia, int free_items);
125 
126 int         uget_media_grab_items(UgetMedia* umedia, UgetProxy* proxy);
127 
128 // return begin of matched items. Don't free it
129 UgetMediaItem*  uget_media_match(UgetMedia*          umedia,
130                                  UgetMediaMatchMode  mode,
131                                  UgetMediaQuality    quality,
132                                  UgetMediaType       type);
133 
134 // ----------------------------------------------------------------------------
135 // UgetMediaItem
136 
137 struct UgetMediaItem
138 {
139 	UG_LINK_MEMBERS(UgetMediaItem, UgetMediaItem, self);
140 //	UgetMediaItem* self;
141 //	UgetMediaItem* next;
142 //	UgetMediaItem* prev;
143 
144 	char* url;
145 	int   quality;    // video - 480p, 720p
146 	int   bitrate;    // audio
147 	int   type;       // UgetMediaType
148 
149 	// for internal use only
150 	int   order;
151 	union {
152 		int   integer;
153 		char* string;
154 		void* pointer;
155 	} data;
156 
157 	union {
158 		int   integer;
159 		char* string;
160 		void* pointer;
161 	} data1;
162 };
163 
164 UgetMediaItem*  uget_media_item_new(UgetMedia* umedia);
165 void            uget_media_item_free(UgetMediaItem* umitem);
166 
167 #ifdef __cplusplus
168 }
169 #endif  // __cplusplus
170 
171 #endif  // End of UGET_MEDIA_H
172 
173