00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00032
00033 #if defined(YOUTUBE) // make sure to add more ifdefs when we get more services
00034
00035 #ifndef __YOUTUBE_SERVICE_H__
00036 #define __YOUTUBE_SERVICE_H__
00037
00038 #include "zmm/zmm.h"
00039 #include "mxml/mxml.h"
00040 #include "online_service.h"
00041 #include "url.h"
00042 #include "dictionary.h"
00043 #include "youtube_content_handler.h"
00044 #include <curl/curl.h>
00045
00046 typedef enum
00047 {
00048 YT_request_none = 0,
00049 YT_request_video_search,
00050 YT_request_stdfeed,
00051 YT_request_user_favorites,
00052 YT_request_user_playlists,
00053 YT_request_user_subscriptions,
00054 YT_request_user_uploads,
00055 YT_subrequest_playlists,
00056 YT_subrequest_subscriptions,
00057 } yt_requests_t;
00058
00059 typedef enum
00060 {
00061 YT_region_au = 0,
00062 YT_region_br,
00063 YT_region_ca,
00064 YT_region_fr,
00065 YT_region_de,
00066 YT_region_gb,
00067 YT_region_nl,
00068 YT_region_hk,
00069 YT_region_ie,
00070 YT_region_it,
00071 YT_region_jp,
00072 YT_region_mx,
00073 YT_region_nz,
00074 YT_region_pl,
00075 YT_region_ru,
00076 YT_region_kr,
00077 YT_region_es,
00078 YT_region_tw,
00079 YT_region_us,
00080 YT_region_none,
00081 } yt_regions_t;
00082
00085 class YouTubeService : public OnlineService
00086 {
00087 public:
00088 YouTubeService();
00089 ~YouTubeService();
00092 virtual bool refreshServiceData(zmm::Ref<Layout> layout);
00093
00095 virtual service_type_t getServiceType();
00096
00098 virtual zmm::String getServiceName();
00099
00102 virtual zmm::Ref<zmm::Object> defineServiceTask(zmm::Ref<mxml::Element> xmlopt, zmm::Ref<zmm::Object> params);
00103
00106 static zmm::String getRequestName(yt_requests_t request);
00107
00109 static zmm::String getRegionName(yt_regions_t region_code);
00110
00111 protected:
00112
00113 CURL *curl_handle;
00114
00115 pthread_t pid;
00116
00117
00118 zmm::Ref<URL> url;
00119
00121 zmm::Ref<mxml::Element> getData(zmm::String url_part, zmm::Ref<Dictionary> params, bool construct_url = true);
00122
00127 class YouTubeTask : public zmm::Object
00128 {
00129 public:
00130 YouTubeTask();
00131
00133 yt_requests_t request;
00134
00136 yt_regions_t region;
00137
00140 zmm::String url_part;
00141
00144 zmm::Ref<Dictionary> parameters;
00145
00147 int amount;
00148
00150 int amount_fetched;
00151
00153 int start_index;
00154
00156 int cfg_start_index;
00157
00159 zmm::String sub_request_name;
00160
00162 zmm::Ref<YouTubeSubFeed> subfeed;
00163 int subfeed_index;
00164
00167 bool kill;
00168 };
00169
00172 int current_task;
00173
00174
00175
00176
00177
00178 void getPagingParams(zmm::Ref<mxml::Element> xml,
00179 zmm::Ref<YouTubeTask> task);
00180 void addTimeParams(zmm::Ref<mxml::Element> xml, zmm::Ref<YouTubeTask> task);
00181 yt_regions_t getRegion(zmm::Ref<mxml::Element> xml);
00182 zmm::String getFeed(zmm::Ref<mxml::Element> xml);
00183
00184
00185
00186 void killOneTimeTasks(zmm::Ref<zmm::Array<zmm::Object> > tasklist);
00187 };
00188
00189 #endif//__ONLINE_SERVICE_H__
00190
00191 #endif//YOUTUBE